File indexing completed on 2025-01-18 09:50:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_PROPERTY_MAP_VECTOR_PROPERTY_MAP_HPP
0011 #define BOOST_PROPERTY_MAP_VECTOR_PROPERTY_MAP_HPP
0012
0013 #include <boost/property_map/property_map.hpp>
0014 #include <boost/smart_ptr/shared_ptr.hpp>
0015 #include <iterator>
0016 #include <vector>
0017
0018 namespace boost {
0019 template<typename T, typename IndexMap = identity_property_map>
0020 class vector_property_map
0021 : public boost::put_get_helper<
0022 typename std::iterator_traits<
0023 typename std::vector<T>::iterator >::reference,
0024 vector_property_map<T, IndexMap> >
0025 {
0026 public:
0027 typedef typename property_traits<IndexMap>::key_type key_type;
0028 typedef T value_type;
0029 typedef typename std::iterator_traits<
0030 typename std::vector<T>::iterator >::reference reference;
0031 typedef boost::lvalue_property_map_tag category;
0032
0033 vector_property_map(const IndexMap& index = IndexMap())
0034 : store(new std::vector<T>()), index(index)
0035 {}
0036
0037 vector_property_map(unsigned initial_size,
0038 const IndexMap& index = IndexMap())
0039 : store(new std::vector<T>(initial_size)), index(index)
0040 {}
0041
0042 typename std::vector<T>::iterator storage_begin()
0043 {
0044 return store->begin();
0045 }
0046
0047 typename std::vector<T>::iterator storage_end()
0048 {
0049 return store->end();
0050 }
0051
0052 typename std::vector<T>::const_iterator storage_begin() const
0053 {
0054 return store->begin();
0055 }
0056
0057 typename std::vector<T>::const_iterator storage_end() const
0058 {
0059 return store->end();
0060 }
0061
0062 IndexMap& get_index_map() { return index; }
0063 const IndexMap& get_index_map() const { return index; }
0064
0065 public:
0066
0067
0068
0069
0070 reference operator[](const key_type& v) const {
0071 typename property_traits<IndexMap>::value_type i = get(index, v);
0072 if (static_cast<unsigned>(i) >= store->size()) {
0073 store->resize(i + 1, T());
0074 }
0075 return (*store)[i];
0076 }
0077 private:
0078
0079
0080
0081
0082
0083
0084 shared_ptr< std::vector<T> > store;
0085 IndexMap index;
0086 };
0087
0088 template<typename T, typename IndexMap>
0089 vector_property_map<T, IndexMap>
0090 make_vector_property_map(IndexMap index)
0091 {
0092 return vector_property_map<T, IndexMap>(index);
0093 }
0094 }
0095
0096 #endif