21 #ifndef VECTORGRAPHPROPERTY_H 22 #define VECTORGRAPHPROPERTY_H 32 class ValArrayInterface {
33 friend class VectorGraph;
35 virtual void addElement(
const unsigned int id) = 0;
36 virtual void reserve(
const size_t size) = 0;
37 virtual ~ValArrayInterface() {}
44 template <
typename TYPE>
45 class ValArray :
public ValArrayInterface {
46 friend class VectorGraph;
48 ValArray(
const unsigned int size = 0,
const unsigned int capacity = 0) {
49 _data.reserve(capacity);
52 virtual ~ValArray() {}
53 void addElement(
const unsigned int id) {
54 if (
id >= _data.size()) {
56 _data.push_back(TYPE());
59 void reserve(
const size_t size) {
64 std::vector<TYPE> _data;
73 template <
typename TYPE>
74 class VectorGraphProperty {
75 friend class VectorGraph;
77 virtual ~VectorGraphProperty() {}
83 typename std::vector<TYPE>::reference operator[](
const size_t id) {
85 assert(
id < (*_array)._data.size());
86 return (*_array)._data[
id];
93 typename std::vector<TYPE>::const_reference operator[](
const size_t id)
const {
95 assert(
id < (*_array)._data.size());
96 return (*_array)._data[
id];
109 void setAll(
const TYPE &obj) {
110 fill(_array->_data.begin(), _array->_data.end(), obj);
117 void set(
const size_t id,
const TYPE &obj) {
125 typename std::vector<TYPE>::const_reference
get(
const size_t id)
const {
129 virtual bool isValid()
const = 0;
133 VectorGraphProperty():_array(0), _graph(0) {
135 VectorGraphProperty(
const VectorGraphProperty &obj): _array(obj._array), _graph(obj._graph) {
137 VectorGraphProperty(ValArray<TYPE> *array, VectorGraph *graph):_array(array), _graph(graph) {
140 ValArray<TYPE> *_array;
179 template <
typename TYPE>
180 class EdgeProperty :
public VectorGraphProperty<TYPE> {
181 friend class VectorGraph;
183 EdgeProperty():VectorGraphProperty<TYPE>() {}
184 EdgeProperty(
const EdgeProperty &obj): VectorGraphProperty<TYPE>(obj) {}
186 bool isValid()
const;
190 EdgeProperty(ValArray<TYPE> *array, VectorGraph *graph):VectorGraphProperty<TYPE>(array, graph) {}
227 template <
typename TYPE>
228 class NodeProperty :
public VectorGraphProperty<TYPE> {
229 friend class VectorGraph;
231 NodeProperty():VectorGraphProperty<TYPE>() {}
232 NodeProperty(
const NodeProperty &obj): VectorGraphProperty<TYPE>(obj) {}
234 bool isValid()
const;
238 NodeProperty(ValArray<TYPE> *array, VectorGraph *graph):VectorGraphProperty<TYPE>(array, graph) {}
242 #endif // VECTORGRAPHPROPERTY_H