Chris@16: // Copyright (C) 2004-2006 The Trustees of Indiana University. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // Authors: Douglas Gregor Chris@16: // Andrew Lumsdaine Chris@16: Chris@16: // The placement of this #include probably looks very odd relative to Chris@16: // the #ifndef/#define pair below. However, this placement is Chris@16: // extremely important to allow the various property map headers to be Chris@16: // included in any order. Chris@16: #include Chris@16: Chris@16: #ifndef BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP Chris@16: #define BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: /** Property map that accesses an underlying, local property map Chris@16: * using a subset of the global keys. Chris@16: */ Chris@16: template Chris@16: class local_property_map Chris@16: { Chris@16: typedef typename property_traits::value_type owner_local_pair; Chris@16: Chris@16: public: Chris@16: typedef ProcessGroup process_group_type; Chris@16: typedef typename property_traits::value_type value_type; Chris@16: typedef typename property_traits::key_type key_type; Chris@16: typedef typename property_traits::reference reference; Chris@16: typedef typename property_traits::category category; Chris@16: Chris@16: local_property_map() { } Chris@16: Chris@101: local_property_map(const ProcessGroup& process_group, Chris@16: const GlobalMap& global, const StorageMap& storage) Chris@16: : process_group_(process_group), global_(global), storage(storage) { } Chris@16: Chris@101: reference operator[](const key_type& key) Chris@101: { Chris@16: owner_local_pair p = get(global_, key); Chris@16: BOOST_ASSERT(p.first == process_id(process_group_)); Chris@101: return storage[p.second]; Chris@16: } Chris@16: Chris@16: GlobalMap& global() const { return global_; } Chris@16: StorageMap& base() const { return storage; } Chris@16: Chris@16: ProcessGroup& process_group() { return process_group_; } Chris@16: const ProcessGroup& process_group() const { return process_group_; } Chris@16: Chris@16: private: Chris@16: ProcessGroup process_group_; Chris@16: mutable GlobalMap global_; Chris@16: mutable StorageMap storage; Chris@16: }; Chris@16: Chris@16: template Chris@16: inline Chris@16: typename local_property_map::reference Chris@101: get(const local_property_map& pm, Chris@16: typename local_property_map::key_type Chris@16: const & key) Chris@16: Chris@16: { Chris@16: typename property_traits::value_type p = get(pm.global(), key); Chris@16: return get(pm.base(), p.second); Chris@16: } Chris@16: Chris@16: template Chris@16: inline void Chris@101: put(const local_property_map& pm, Chris@16: typename local_property_map Chris@16: ::key_type const & key, Chris@16: typename local_property_map Chris@16: ::value_type const& v) Chris@16: { Chris@16: typename property_traits::value_type p = get(pm.global(), key); Chris@16: BOOST_ASSERT(p.first == process_id(pm.process_group())); Chris@16: put(pm.base(), p.second, v); Chris@16: } Chris@16: } // end namespace boost Chris@16: #endif // BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP