caching_property_map.hpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2004 The Trustees of Indiana University.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Authors: Douglas Gregor
  6. // Andrew Lumsdaine
  7. #ifndef BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
  8. #define BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
  9. #include <boost/property_map/property_map.hpp>
  10. namespace boost {
  11. // This probably doesn't belong here
  12. template<typename Key, typename Value>
  13. inline void local_put(dummy_property_map, const Key&, const Value&) {}
  14. namespace parallel {
  15. /** Property map that caches values placed in it but does not
  16. * broadcast values to remote processors. This class template is
  17. * meant as an adaptor for @ref distributed_property_map that
  18. * suppresses communication in the event of a remote @c put operation
  19. * by mapping it to a local @c put operation.
  20. *
  21. * @todo Find a better name for @ref caching_property_map
  22. */
  23. template<typename PropertyMap>
  24. class caching_property_map
  25. {
  26. public:
  27. typedef typename property_traits<PropertyMap>::key_type key_type;
  28. typedef typename property_traits<PropertyMap>::value_type value_type;
  29. typedef typename property_traits<PropertyMap>::reference reference;
  30. typedef typename property_traits<PropertyMap>::category category;
  31. explicit caching_property_map(const PropertyMap& property_map)
  32. : property_map(property_map) {}
  33. PropertyMap& base() { return property_map; }
  34. const PropertyMap& base() const { return property_map; }
  35. template<typename Reduce>
  36. void set_reduce(const Reduce& reduce)
  37. { property_map.set_reduce(reduce); }
  38. void reset() { property_map.reset(); }
  39. #if 0
  40. reference operator[](const key_type& key) const
  41. {
  42. return property_map[key];
  43. }
  44. #endif
  45. private:
  46. PropertyMap property_map;
  47. };
  48. template<typename PropertyMap, typename Key>
  49. inline typename caching_property_map<PropertyMap>::value_type
  50. get(const caching_property_map<PropertyMap>& pm, const Key& key)
  51. { return get(pm.base(), key); }
  52. template<typename PropertyMap, typename Key, typename Value>
  53. inline void
  54. local_put(const caching_property_map<PropertyMap>& pm, const Key& key,
  55. const Value& value)
  56. { local_put(pm.base(), key, value); }
  57. template<typename PropertyMap, typename Key, typename Value>
  58. inline void
  59. cache(const caching_property_map<PropertyMap>& pm, const Key& key,
  60. const Value& value)
  61. { cache(pm.base(), key, value); }
  62. template<typename PropertyMap, typename Key, typename Value>
  63. inline void
  64. put(const caching_property_map<PropertyMap>& pm, const Key& key,
  65. const Value& value)
  66. { local_put(pm.base(), key, value); }
  67. template<typename PropertyMap>
  68. inline caching_property_map<PropertyMap>
  69. make_caching_property_map(const PropertyMap& pm)
  70. { return caching_property_map<PropertyMap>(pm); }
  71. } } // end namespace boost::parallel
  72. #endif // BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP