File indexing completed on 2025-01-18 09:50:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <boost/property_map/property_map.hpp>
0015
0016 #ifndef BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP
0017 #define BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP
0018
0019 #include <boost/assert.hpp>
0020
0021 namespace boost {
0022
0023
0024
0025 template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
0026 class local_property_map
0027 {
0028 typedef typename property_traits<GlobalMap>::value_type owner_local_pair;
0029
0030 public:
0031 typedef ProcessGroup process_group_type;
0032 typedef typename property_traits<StorageMap>::value_type value_type;
0033 typedef typename property_traits<GlobalMap>::key_type key_type;
0034 typedef typename property_traits<StorageMap>::reference reference;
0035 typedef typename property_traits<StorageMap>::category category;
0036
0037 local_property_map() { }
0038
0039 local_property_map(const ProcessGroup& process_group,
0040 const GlobalMap& global, const StorageMap& storage)
0041 : process_group_(process_group), global_(global), storage(storage) { }
0042
0043 reference operator[](const key_type& key)
0044 {
0045 owner_local_pair p = get(global_, key);
0046 BOOST_ASSERT(p.first == process_id(process_group_));
0047 return storage[p.second];
0048 }
0049
0050 GlobalMap& global() const { return global_; }
0051 StorageMap& base() const { return storage; }
0052
0053 ProcessGroup& process_group() { return process_group_; }
0054 const ProcessGroup& process_group() const { return process_group_; }
0055
0056 private:
0057 ProcessGroup process_group_;
0058 mutable GlobalMap global_;
0059 mutable StorageMap storage;
0060 };
0061
0062 template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
0063 inline
0064 typename local_property_map<ProcessGroup, GlobalMap, StorageMap>::reference
0065 get(const local_property_map<ProcessGroup, GlobalMap, StorageMap>& pm,
0066 typename local_property_map<ProcessGroup, GlobalMap, StorageMap>::key_type
0067 const & key)
0068
0069 {
0070 typename property_traits<GlobalMap>::value_type p = get(pm.global(), key);
0071 return get(pm.base(), p.second);
0072 }
0073
0074 template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
0075 inline void
0076 put(const local_property_map<ProcessGroup, GlobalMap, StorageMap>& pm,
0077 typename local_property_map<ProcessGroup, GlobalMap, StorageMap>
0078 ::key_type const & key,
0079 typename local_property_map<ProcessGroup, GlobalMap, StorageMap>
0080 ::value_type const& v)
0081 {
0082 typename property_traits<GlobalMap>::value_type p = get(pm.global(), key);
0083 BOOST_ASSERT(p.first == process_id(pm.process_group()));
0084 put(pm.base(), p.second, v);
0085 }
0086 }
0087 #endif