21 #ifndef VECTORGRAPHPROPERTY_H 22 #define VECTORGRAPHPROPERTY_H 34 class VectorGraphValues {
35 friend class VectorGraph;
38 virtual void addElement(
const unsigned int id) = 0;
39 virtual void reserve(
const size_t size) = 0;
40 virtual ~VectorGraphValues() {}
51 template <
typename TYPE>
52 class VectorGraphProperty {
53 friend class VectorGraph;
61 struct ValuesImpl :
public VectorGraphValues,
public std::vector<TYPE> {
63 ValuesImpl(
const unsigned int size = 0,
const unsigned int capacity = 0) {
64 std::vector<TYPE>::reserve(capacity);
65 std::vector<TYPE>::resize(size);
67 ~ValuesImpl()
override {}
68 void addElement(
const unsigned int id)
override {
69 if (
id >= std::vector<TYPE>::size()) {
70 std::vector<TYPE>::resize(
id + 1);
73 void reserve(
const size_t size)
override {
74 std::vector<TYPE>::reserve(size);
79 virtual ~VectorGraphProperty() {}
85 typename std::vector<TYPE>::reference operator[](
const size_t id) {
87 assert(id < _values->size());
88 return (*_values)[id];
95 typename std::vector<TYPE>::const_reference operator[](
const size_t id)
const {
97 assert(id < _values->size());
98 return (*_values)[id];
111 void setAll(
const TYPE &obj) {
112 fill(_values->begin(), _values->end(), obj);
119 void set(
const size_t id,
const TYPE &obj) {
127 typename std::vector<TYPE>::const_reference
get(
const size_t id)
const {
131 virtual bool isValid()
const = 0;
134 void swap(VectorGraphProperty<TYPE> &v) {
135 assert(_values && (_graph == v._graph));
136 _values->swap(*(v._values));
140 VectorGraphProperty() : _values(nullptr), _graph(nullptr) {}
141 VectorGraphProperty(
const VectorGraphProperty &obj) : _values(obj._values), _graph(obj._graph) {}
142 VectorGraphProperty(ValuesImpl *values, VectorGraph *graph) : _values(values), _graph(graph) {}
183 template <
typename TYPE>
184 class EdgeProperty :
public VectorGraphProperty<TYPE> {
185 friend class VectorGraph;
188 EdgeProperty() : VectorGraphProperty<TYPE>() {}
189 EdgeProperty(
const EdgeProperty &obj) : VectorGraphProperty<TYPE>(obj) {}
191 bool isValid()
const;
195 EdgeProperty(
typename VectorGraphProperty<TYPE>::ValuesImpl *values, VectorGraph *graph)
196 : VectorGraphProperty<TYPE>(values, graph) {}
232 template <
typename TYPE>
233 class NodeProperty :
public VectorGraphProperty<TYPE> {
234 friend class VectorGraph;
237 NodeProperty() : VectorGraphProperty<TYPE>() {}
238 NodeProperty(
const NodeProperty &obj) : VectorGraphProperty<TYPE>(obj) {}
240 bool isValid()
const;
244 NodeProperty(
typename VectorGraphProperty<TYPE>::ValuesImpl *values, VectorGraph *graph)
245 : VectorGraphProperty<TYPE>(values, graph) {}
248 #endif // VECTORGRAPHPROPERTY_H