shared_array_property_map.hpp 1.4 KB

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