1 // Copyright 2004 The Trustees of Indiana University.
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // Authors: Douglas Gregor
9 #ifndef BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
10 #define BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
12 #ifndef BOOST_GRAPH_USE_MPI
13 #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
16 #include <boost/property_map/property_map.hpp>
20 // This probably doesn't belong here
21 template<typename Key
, typename Value
>
22 inline void local_put(dummy_property_map
, const Key
&, const Value
&) {}
26 /** Property map that caches values placed in it but does not
27 * broadcast values to remote processors. This class template is
28 * meant as an adaptor for @ref distributed_property_map that
29 * suppresses communication in the event of a remote @c put operation
30 * by mapping it to a local @c put operation.
32 * @todo Find a better name for @ref caching_property_map
34 template<typename PropertyMap
>
35 class caching_property_map
38 typedef typename property_traits
<PropertyMap
>::key_type key_type
;
39 typedef typename property_traits
<PropertyMap
>::value_type value_type
;
40 typedef typename property_traits
<PropertyMap
>::reference reference
;
41 typedef typename property_traits
<PropertyMap
>::category category
;
43 explicit caching_property_map(const PropertyMap
& property_map
)
44 : property_map(property_map
) {}
46 PropertyMap
& base() { return property_map
; }
47 const PropertyMap
& base() const { return property_map
; }
49 template<typename Reduce
>
50 void set_reduce(const Reduce
& reduce
)
51 { property_map
.set_reduce(reduce
); }
53 void reset() { property_map
.reset(); }
56 reference
operator[](const key_type
& key
) const
58 return property_map
[key
];
63 PropertyMap property_map
;
66 template<typename PropertyMap
, typename Key
>
67 inline typename caching_property_map
<PropertyMap
>::value_type
68 get(const caching_property_map
<PropertyMap
>& pm
, const Key
& key
)
69 { return get(pm
.base(), key
); }
71 template<typename PropertyMap
, typename Key
, typename Value
>
73 local_put(const caching_property_map
<PropertyMap
>& pm
, const Key
& key
,
75 { local_put(pm
.base(), key
, value
); }
77 template<typename PropertyMap
, typename Key
, typename Value
>
79 cache(const caching_property_map
<PropertyMap
>& pm
, const Key
& key
,
81 { cache(pm
.base(), key
, value
); }
83 template<typename PropertyMap
, typename Key
, typename Value
>
85 put(const caching_property_map
<PropertyMap
>& pm
, const Key
& key
,
87 { local_put(pm
.base(), key
, value
); }
89 template<typename PropertyMap
>
90 inline caching_property_map
<PropertyMap
>
91 make_caching_property_map(const PropertyMap
& pm
)
92 { return caching_property_map
<PropertyMap
>(pm
); }
94 } } // end namespace boost::parallel
96 #endif // BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP