File indexing completed on 2025-01-18 09:37:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_GRAPH_INDEXED_PROPERTIES_HPP
0014 #define BOOST_GRAPH_INDEXED_PROPERTIES_HPP
0015
0016 #include <vector>
0017 #include <utility>
0018 #include <algorithm>
0019 #include <climits>
0020 #include <iterator>
0021 #include <boost/graph/graph_traits.hpp>
0022 #include <boost/graph/properties.hpp>
0023 #include <boost/iterator/counting_iterator.hpp>
0024 #include <boost/integer.hpp>
0025 #include <boost/iterator/iterator_facade.hpp>
0026 #include <boost/property_map/property_map.hpp>
0027 #include <boost/mpl/if.hpp>
0028
0029 namespace boost
0030 {
0031 namespace detail
0032 {
0033
0034 template < typename Derived, typename Property, typename Descriptor,
0035 typename IndexMap >
0036 class indexed_vertex_properties
0037 {
0038 public:
0039 typedef no_property vertex_property_type;
0040 typedef Property vertex_bundled;
0041 typedef iterator_property_map<
0042 typename std::vector< Property >::iterator, IndexMap >
0043 vertex_map_type;
0044 typedef iterator_property_map<
0045 typename std::vector< Property >::const_iterator, IndexMap >
0046 const_vertex_map_type;
0047
0048
0049 Property& operator[](Descriptor v)
0050 {
0051 return m_vertex_properties[get(vertex_index, derived(), v)];
0052 }
0053
0054 const Property& operator[](Descriptor v) const
0055 {
0056 return m_vertex_properties[get(vertex_index, derived(), v)];
0057 }
0058
0059 vertex_map_type get_vertex_bundle(
0060 const IndexMap& index_map = IndexMap())
0061 {
0062 return vertex_map_type(m_vertex_properties.begin(), index_map);
0063 }
0064
0065 const_vertex_map_type get_vertex_bundle(
0066 const IndexMap& index_map = IndexMap()) const
0067 {
0068 return const_vertex_map_type(
0069 m_vertex_properties.begin(), index_map);
0070 }
0071
0072 protected:
0073
0074 indexed_vertex_properties() {}
0075
0076
0077 indexed_vertex_properties(std::size_t n) : m_vertex_properties(n) {}
0078
0079 public:
0080
0081 void clear() { m_vertex_properties.clear(); }
0082
0083
0084 void resize(std::size_t n) { m_vertex_properties.resize(n); }
0085
0086
0087 void reserve(std::size_t n) { m_vertex_properties.reserve(n); }
0088
0089
0090 void push_back(const Property& prop)
0091 {
0092 m_vertex_properties.push_back(prop);
0093 }
0094
0095
0096 void write_by_index(std::size_t idx, const Property& prop)
0097 {
0098 m_vertex_properties[idx] = prop;
0099 }
0100
0101
0102 Derived& derived() { return *static_cast< Derived* >(this); }
0103
0104 const Derived& derived() const
0105 {
0106 return *static_cast< const Derived* >(this);
0107 }
0108
0109 public:
0110 std::vector< Property > m_vertex_properties;
0111 };
0112
0113 template < typename Derived, typename Descriptor, typename IndexMap >
0114 class indexed_vertex_properties< Derived, void, Descriptor, IndexMap >
0115 {
0116 struct secret
0117 {
0118 };
0119
0120 public:
0121 typedef no_property vertex_property_type;
0122 typedef void vertex_bundled;
0123 typedef secret vertex_map_type;
0124 typedef secret const_vertex_map_type;
0125
0126 secret operator[](secret) { return secret(); }
0127
0128 vertex_map_type get_vertex_bundle() const { return vertex_map_type(); }
0129
0130 protected:
0131
0132 indexed_vertex_properties() {}
0133 indexed_vertex_properties(std::size_t) {}
0134
0135 public:
0136 void clear() {}
0137 void resize(std::size_t) {}
0138 void reserve(std::size_t) {}
0139 };
0140
0141 template < typename Derived, typename Property, typename Descriptor,
0142 typename IndexMap >
0143 class indexed_edge_properties
0144 {
0145 public:
0146 typedef no_property edge_property_type;
0147 typedef Property edge_bundled;
0148 typedef Property edge_push_back_type;
0149 typedef iterator_property_map<
0150 typename std::vector< Property >::iterator, IndexMap >
0151 edge_map_type;
0152 typedef iterator_property_map<
0153 typename std::vector< Property >::const_iterator, IndexMap >
0154 const_edge_map_type;
0155
0156
0157 Property& operator[](Descriptor v)
0158 {
0159 return m_edge_properties[get(edge_index, derived(), v)];
0160 }
0161
0162 const Property& operator[](Descriptor v) const
0163 {
0164 return m_edge_properties[get(edge_index, derived(), v)];
0165 }
0166
0167 edge_map_type get_edge_bundle(const IndexMap& index_map = IndexMap())
0168 {
0169 return edge_map_type(m_edge_properties.begin(), index_map);
0170 }
0171
0172 const_edge_map_type get_edge_bundle(
0173 const IndexMap& index_map = IndexMap()) const
0174 {
0175 return const_edge_map_type(m_edge_properties.begin(), index_map);
0176 }
0177
0178 protected:
0179
0180 indexed_edge_properties() {}
0181
0182
0183 indexed_edge_properties(std::size_t n) : m_edge_properties(n) {}
0184
0185
0186 std::size_t size() const { return m_edge_properties.size(); }
0187
0188
0189 void clear() { m_edge_properties.clear(); }
0190
0191
0192 void resize(std::size_t n) { m_edge_properties.resize(n); }
0193
0194
0195 void reserve(std::size_t n) { m_edge_properties.reserve(n); }
0196
0197
0198 void write_by_index(std::size_t idx, const Property& prop)
0199 {
0200 m_edge_properties[idx] = prop;
0201 }
0202
0203 public:
0204
0205 void push_back(const Property& prop)
0206 {
0207 m_edge_properties.push_back(prop);
0208 }
0209
0210
0211 void move_range(
0212 std::size_t src_begin, std::size_t src_end, std::size_t dest_begin)
0213 {
0214 std::copy_backward(m_edge_properties.begin() + src_begin,
0215 m_edge_properties.begin() + src_end,
0216 m_edge_properties.begin() + dest_begin + (src_end - src_begin));
0217 }
0218
0219 typedef typename std::vector< Property >::iterator iterator;
0220 iterator begin() { return m_edge_properties.begin(); }
0221 iterator end() { return m_edge_properties.end(); }
0222
0223 private:
0224
0225 Derived& derived() { return *static_cast< Derived* >(this); }
0226
0227 const Derived& derived() const
0228 {
0229 return *static_cast< const Derived* >(this);
0230 }
0231
0232 public:
0233 std::vector< Property > m_edge_properties;
0234 };
0235
0236 struct dummy_no_property_iterator
0237 : public boost::iterator_facade< dummy_no_property_iterator, no_property,
0238 std::random_access_iterator_tag >
0239 {
0240 mutable no_property prop;
0241 no_property& dereference() const { return prop; }
0242 bool equal(const dummy_no_property_iterator&) const { return true; }
0243 void increment() {}
0244 void decrement() {}
0245 void advance(std::ptrdiff_t) {}
0246 std::ptrdiff_t distance_to(const dummy_no_property_iterator) const
0247 {
0248 return 0;
0249 }
0250 };
0251
0252 template < typename Derived, typename Descriptor, typename IndexMap >
0253 class indexed_edge_properties< Derived, void, Descriptor, IndexMap >
0254 {
0255 struct secret
0256 {
0257 };
0258
0259 public:
0260 typedef no_property edge_property_type;
0261 typedef void edge_bundled;
0262 typedef void* edge_push_back_type;
0263 typedef secret edge_map_type;
0264 typedef secret const_edge_map_type;
0265
0266 secret operator[](secret) { return secret(); }
0267 void write_by_index(std::size_t , const no_property& ) {}
0268
0269 edge_map_type get_edge_bundle(const IndexMap& = IndexMap()) const
0270 {
0271 return edge_map_type();
0272 }
0273
0274 protected:
0275
0276 indexed_edge_properties() {}
0277 indexed_edge_properties(std::size_t) {}
0278 std::size_t size() const { return 0; }
0279 void clear() {}
0280 void resize(std::size_t) {}
0281 void reserve(std::size_t) {}
0282
0283 public:
0284 void push_back(const edge_push_back_type&) {}
0285 void move_range(std::size_t , std::size_t ,
0286 std::size_t )
0287 {
0288 }
0289
0290 typedef dummy_no_property_iterator iterator;
0291 iterator begin() { return dummy_no_property_iterator(); }
0292 iterator end() { return dummy_no_property_iterator(); }
0293 };
0294
0295 }
0296 }
0297
0298 #endif