• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright (C) 2009 Trustees of Indiana University
2 //  Authors: Jeremiah Willcock, Andrew Lumsdaine
3 
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
8 //  See http://www.boost.org/libs/property_map for documentation.
9 
10 #ifndef BOOST_SHARED_ARRAY_PROPERTY_MAP_HPP
11 #define BOOST_SHARED_ARRAY_PROPERTY_MAP_HPP
12 
13 #include <boost/smart_ptr/shared_array.hpp>
14 #include <boost/property_map/property_map.hpp>
15 
16 namespace boost {
17 
18 template <class T, class IndexMap>
19 class shared_array_property_map
20   : public boost::put_get_helper<T&, shared_array_property_map<T, IndexMap> >
21 {
22   public:
23   typedef typename property_traits<IndexMap>::key_type key_type;
24   typedef T value_type;
25   typedef T& reference;
26   typedef boost::lvalue_property_map_tag category;
27 
shared_array_property_map()28   inline shared_array_property_map(): data(), index() {}
29 
shared_array_property_map(size_t n,const IndexMap & _id=IndexMap ())30   explicit inline shared_array_property_map(
31     size_t n,
32     const IndexMap& _id = IndexMap())
33   : data(new T[n]), index(_id) {}
34 
operator [](key_type v) const35   inline T& operator[](key_type v) const {
36     return data[get(index, v)];
37   }
38 
39   private:
40   boost::shared_array<T> data;
41   IndexMap index;
42 };
43 
44 template <class T, class IndexMap>
45 shared_array_property_map<T, IndexMap>
make_shared_array_property_map(size_t n,const T &,const IndexMap & index)46 make_shared_array_property_map(size_t n, const T&, const IndexMap& index) {
47   return shared_array_property_map<T, IndexMap>(n, index);
48 }
49 
50 } // end namespace boost
51 
52 #endif // BOOST_SHARED_ARRAY_PROPERTY_MAP_HPP
53