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 #include <boost/property_map/property_map.hpp>
16 // This probably doesn't belong here
17 template<typename Key, typename Value>
18 inline void local_put(dummy_property_map, const Key&, const Value&) {}
22 /** Property map that caches values placed in it but does not
23 * broadcast values to remote processors. This class template is
24 * meant as an adaptor for @ref distributed_property_map that
25 * suppresses communication in the event of a remote @c put operation
26 * by mapping it to a local @c put operation.
28 * @todo Find a better name for @ref caching_property_map
30 template<typename PropertyMap>
31 class caching_property_map
34 typedef typename property_traits<PropertyMap>::key_type key_type;
35 typedef typename property_traits<PropertyMap>::value_type value_type;
36 typedef typename property_traits<PropertyMap>::reference reference;
37 typedef typename property_traits<PropertyMap>::category category;
39 explicit caching_property_map(const PropertyMap& property_map)
40 : property_map(property_map) {}
42 PropertyMap& base() { return property_map; }
43 const PropertyMap& base() const { return property_map; }
45 template<typename Reduce>
46 void set_reduce(const Reduce& reduce)
47 { property_map.set_reduce(reduce); }
49 void reset() { property_map.reset(); }
52 reference operator[](const key_type& key) const
54 return property_map[key];
59 PropertyMap property_map;
62 template<typename PropertyMap, typename Key>
63 inline typename caching_property_map<PropertyMap>::value_type
64 get(const caching_property_map<PropertyMap>& pm, const Key& key)
65 { return get(pm.base(), key); }
67 template<typename PropertyMap, typename Key, typename Value>
69 local_put(const caching_property_map<PropertyMap>& pm, const Key& key,
71 { local_put(pm.base(), key, value); }
73 template<typename PropertyMap, typename Key, typename Value>
75 cache(const caching_property_map<PropertyMap>& pm, const Key& key,
77 { cache(pm.base(), key, value); }
79 template<typename PropertyMap, typename Key, typename Value>
81 put(const caching_property_map<PropertyMap>& pm, const Key& key,
83 { local_put(pm.base(), key, value); }
85 template<typename PropertyMap>
86 inline caching_property_map<PropertyMap>
87 make_caching_property_map(const PropertyMap& pm)
88 { return caching_property_map<PropertyMap>(pm); }
90 } } // end namespace boost::parallel
92 #endif // BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP