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