local_property_map.hpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (C) 2004-2006 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. // The placement of this #include probably looks very odd relative to
  8. // the #ifndef/#define pair below. However, this placement is
  9. // extremely important to allow the various property map headers to be
  10. // included in any order.
  11. #include <boost/property_map/property_map.hpp>
  12. #ifndef BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP
  13. #define BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP
  14. #ifndef BOOST_GRAPH_USE_MPI
  15. #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
  16. #endif
  17. #include <boost/assert.hpp>
  18. namespace boost {
  19. /** Property map that accesses an underlying, local property map
  20. * using a subset of the global keys.
  21. */
  22. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  23. class local_property_map
  24. {
  25. typedef typename property_traits<GlobalMap>::value_type owner_local_pair;
  26. public:
  27. typedef ProcessGroup process_group_type;
  28. typedef typename property_traits<StorageMap>::value_type value_type;
  29. typedef typename property_traits<GlobalMap>::key_type key_type;
  30. typedef typename property_traits<StorageMap>::reference reference;
  31. typedef typename property_traits<StorageMap>::category category;
  32. local_property_map() { }
  33. local_property_map(const ProcessGroup& process_group,
  34. const GlobalMap& global, const StorageMap& storage)
  35. : process_group_(process_group), global_(global), storage(storage) { }
  36. reference operator[](const key_type& key)
  37. {
  38. owner_local_pair p = get(global_, key);
  39. BOOST_ASSERT(p.first == process_id(process_group_));
  40. return storage[p.second];
  41. }
  42. GlobalMap& global() const { return global_; }
  43. StorageMap& base() const { return storage; }
  44. ProcessGroup& process_group() { return process_group_; }
  45. const ProcessGroup& process_group() const { return process_group_; }
  46. private:
  47. ProcessGroup process_group_;
  48. mutable GlobalMap global_;
  49. mutable StorageMap storage;
  50. };
  51. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  52. inline
  53. typename local_property_map<ProcessGroup, GlobalMap, StorageMap>::reference
  54. get(const local_property_map<ProcessGroup, GlobalMap, StorageMap>& pm,
  55. typename local_property_map<ProcessGroup, GlobalMap, StorageMap>::key_type
  56. const & key)
  57. {
  58. typename property_traits<GlobalMap>::value_type p = get(pm.global(), key);
  59. return get(pm.base(), p.second);
  60. }
  61. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  62. inline void
  63. put(const local_property_map<ProcessGroup, GlobalMap, StorageMap>& pm,
  64. typename local_property_map<ProcessGroup, GlobalMap, StorageMap>
  65. ::key_type const & key,
  66. typename local_property_map<ProcessGroup, GlobalMap, StorageMap>
  67. ::value_type const& v)
  68. {
  69. typename property_traits<GlobalMap>::value_type p = get(pm.global(), key);
  70. BOOST_ASSERT(p.first == process_id(pm.process_group()));
  71. put(pm.base(), p.second, v);
  72. }
  73. } // end namespace boost
  74. #endif // BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP