21 #ifndef VECTORGRAPHPROPERTY_H
22 #define VECTORGRAPHPROPERTY_H
31 class ValArrayInterface {
32 friend class VectorGraph;
34 virtual void addElement(
const unsigned int id) = 0;
35 virtual void reserve(
const size_t size) = 0;
36 virtual ~ValArrayInterface() {}
43 template <
typename TYPE>
44 class ValArray :
public ValArrayInterface {
45 friend class VectorGraph;
47 ValArray(
const unsigned int size = 0,
const unsigned int capacity = 0) {
48 _data.reserve(capacity);
51 virtual ~ValArray() {}
52 void addElement(
const unsigned int id) {
53 if (
id >= _data.size()) {
55 _data.push_back(TYPE());
58 void reserve(
const size_t size) {
63 std::vector<TYPE> _data;
72 template <
typename TYPE>
73 class VectorGraphProperty {
74 friend class VectorGraph;
81 typename std::vector<TYPE>::reference operator[](
const size_t id) {
83 assert(
id < (*_array)._data.size());
84 return (*_array)._data[
id];
91 typename std::vector<TYPE>::const_reference operator[](
const size_t id)
const {
93 assert(
id < (*_array)._data.size());
94 return (*_array)._data[
id];
107 void setAll(
const TYPE &obj) {
108 fill(_array->_data.begin(), _array->_data.end(), obj);
115 void set(
const size_t id,
const TYPE &obj) {
123 typename std::vector<TYPE>::const_reference
get(
const size_t id)
const {
127 virtual bool isValid()
const = 0;
131 VectorGraphProperty():_array(0), _graph(0) {
133 VectorGraphProperty(
const VectorGraphProperty &obj): _array(obj._array), _graph(obj._graph) {
135 VectorGraphProperty(ValArray<TYPE> *array, VectorGraph *graph):_array(array), _graph(graph) {
138 ValArray<TYPE> *_array;
177 template <
typename TYPE>
178 class EdgeProperty :
public VectorGraphProperty<TYPE> {
179 friend class VectorGraph;
181 EdgeProperty():VectorGraphProperty<TYPE>() {}
182 EdgeProperty(
const EdgeProperty &obj): VectorGraphProperty<TYPE>(obj) {}
184 bool isValid()
const;
188 EdgeProperty(ValArray<TYPE> *array, VectorGraph *graph):VectorGraphProperty<TYPE>(array, graph) {}
225 template <
typename TYPE>
226 class NodeProperty :
public VectorGraphProperty<TYPE> {
227 friend class VectorGraph;
229 NodeProperty():VectorGraphProperty<TYPE>() {}
230 NodeProperty(
const NodeProperty &obj): VectorGraphProperty<TYPE>(obj) {}
232 bool isValid()
const;
236 NodeProperty(ValArray<TYPE> *array, VectorGraph *graph):VectorGraphProperty<TYPE>(array, graph) {}
240 #endif // VECTORGRAPHPROPERTY_H