annotate DEPENDENCIES/generic/include/boost/property_map/vector_property_map.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Copyright (C) Vladimir Prus 2003.
Chris@16 2 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 3 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 4 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5 //
Chris@16 6 // See http://www.boost.org/libs/graph/vector_property_map.html for
Chris@16 7 // documentation.
Chris@16 8 //
Chris@16 9
Chris@16 10 #ifndef VECTOR_PROPERTY_MAP_HPP_VP_2003_03_04
Chris@16 11 #define VECTOR_PROPERTY_MAP_HPP_VP_2003_03_04
Chris@16 12
Chris@16 13 #include <boost/property_map/property_map.hpp>
Chris@16 14 #include <boost/shared_ptr.hpp>
Chris@16 15 #include <vector>
Chris@16 16
Chris@16 17 namespace boost {
Chris@16 18 template<typename T, typename IndexMap = identity_property_map>
Chris@16 19 class vector_property_map
Chris@16 20 : public boost::put_get_helper<
Chris@16 21 typename std::iterator_traits<
Chris@16 22 typename std::vector<T>::iterator >::reference,
Chris@16 23 vector_property_map<T, IndexMap> >
Chris@16 24 {
Chris@16 25 public:
Chris@16 26 typedef typename property_traits<IndexMap>::key_type key_type;
Chris@16 27 typedef T value_type;
Chris@16 28 typedef typename std::iterator_traits<
Chris@16 29 typename std::vector<T>::iterator >::reference reference;
Chris@16 30 typedef boost::lvalue_property_map_tag category;
Chris@16 31
Chris@16 32 vector_property_map(const IndexMap& index = IndexMap())
Chris@16 33 : store(new std::vector<T>()), index(index)
Chris@16 34 {}
Chris@16 35
Chris@16 36 vector_property_map(unsigned initial_size,
Chris@16 37 const IndexMap& index = IndexMap())
Chris@16 38 : store(new std::vector<T>(initial_size)), index(index)
Chris@16 39 {}
Chris@16 40
Chris@16 41 typename std::vector<T>::iterator storage_begin()
Chris@16 42 {
Chris@16 43 return store->begin();
Chris@16 44 }
Chris@16 45
Chris@16 46 typename std::vector<T>::iterator storage_end()
Chris@16 47 {
Chris@16 48 return store->end();
Chris@16 49 }
Chris@16 50
Chris@16 51 typename std::vector<T>::const_iterator storage_begin() const
Chris@16 52 {
Chris@16 53 return store->begin();
Chris@16 54 }
Chris@16 55
Chris@16 56 typename std::vector<T>::const_iterator storage_end() const
Chris@16 57 {
Chris@16 58 return store->end();
Chris@16 59 }
Chris@16 60
Chris@16 61 IndexMap& get_index_map() { return index; }
Chris@16 62 const IndexMap& get_index_map() const { return index; }
Chris@16 63
Chris@16 64 public:
Chris@16 65 // Copy ctor absent, default semantics is OK.
Chris@16 66 // Assignment operator absent, default semantics is OK.
Chris@16 67 // CONSIDER: not sure that assignment to 'index' is correct.
Chris@16 68
Chris@16 69 reference operator[](const key_type& v) const {
Chris@16 70 typename property_traits<IndexMap>::value_type i = get(index, v);
Chris@16 71 if (static_cast<unsigned>(i) >= store->size()) {
Chris@16 72 store->resize(i + 1, T());
Chris@16 73 }
Chris@16 74 return (*store)[i];
Chris@16 75 }
Chris@16 76 private:
Chris@16 77 // Conceptually, we have a vector of infinite size. For practical
Chris@16 78 // purposes, we start with an empty vector and grow it as needed.
Chris@16 79 // Note that we cannot store pointer to vector here -- we cannot
Chris@16 80 // store pointer to data, because if copy of property map resizes
Chris@16 81 // the vector, the pointer to data will be invalidated.
Chris@16 82 // I wonder if class 'pmap_ref' is simply needed.
Chris@16 83 shared_ptr< std::vector<T> > store;
Chris@16 84 IndexMap index;
Chris@16 85 };
Chris@16 86
Chris@16 87 template<typename T, typename IndexMap>
Chris@16 88 vector_property_map<T, IndexMap>
Chris@16 89 make_vector_property_map(IndexMap index)
Chris@16 90 {
Chris@16 91 return vector_property_map<T, IndexMap>(index);
Chris@16 92 }
Chris@16 93 }
Chris@16 94
Chris@16 95 #ifdef BOOST_GRAPH_USE_MPI
Chris@101 96 #include <boost/property_map/parallel/vector_property_map.hpp>
Chris@101 97 #endif
Chris@16 98
Chris@16 99 #endif