Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
OGDFVector.h
Go to the documentation of this file.
1
31#pragma once
32
33#include <cstddef>
34#include <vector>
35
36namespace ogdf {
37namespace internal {
38namespace gcm {
39
40namespace datastructure {
41
42template<typename T, typename Graph>
43class NodeVector : public std::vector<T> {
44private:
45 using Node = typename Graph::Node;
46 using reference = typename std::vector<T>::reference;
47 using const_reference = typename std::vector<T>::const_reference;
48
49 const Graph* g;
51
52
53public:
54 NodeVector() : g(nullptr) { }
55
56 NodeVector(const Graph& _g) : std::vector<T>(_g.max_node_index() + 1), g(&_g) { }
57
58 NodeVector(const Graph& _g, T& v)
59 : std::vector<T>(_g.max_node_index() + 1, v), g(&_g), default_value(v) { }
60
61 NodeVector(const Graph& _g, T v)
62 : std::vector<T>(_g.max_node_index() + 1, v), g(&_g), default_value(v) { }
63
65 : std::vector<T>(x), g(x.g), default_value(x.default_value) { }
66
67 inline void adapt() {
68 if ((std::size_t)g->max_node_index() >= std::vector<T>::size()) {
69 std::vector<T>::resize(g->max_node_index() + 1, default_value);
70 }
71 }
72
74 adapt();
75 return std::vector<T>::operator[](v->index());
76 }
77
79 OGDF_ASSERT((std::size_t)v->index() < this->size());
80 return std::vector<T>::operator[](v->index());
81 }
82
84 std::vector<T>::operator=(x);
86 return *this;
87 }
88
90 std::vector<T>::operator=(std::move(x));
91 default_value = x.default_value;
92 return *this;
93 }
94};
95
96template<typename T, typename Graph>
97class EdgeVector : public std::vector<T> {
98private:
99 using Edge = typename Graph::Edge;
100 using reference = typename std::vector<T>::reference;
101 using const_reference = typename std::vector<T>::const_reference;
102 const Graph* g;
104
105public:
106 EdgeVector() : g(nullptr) { }
107
108 EdgeVector(const Graph& _g) : std::vector<T>(_g.max_edge_index() + 1), g(&_g) { }
109
110 EdgeVector(const Graph& _g, T& v)
111 : std::vector<T>(_g.max_edge_index() + 1, v), g(&_g), default_value(v) { }
112
113 EdgeVector(const Graph& _g, T v)
114 : std::vector<T>(_g.max_edge_index() + 1, v), g(&_g), default_value(v) { }
115
116 EdgeVector(const EdgeVector& x) : std::vector<T>(x), g(&x.g), default_value(x.default_value) { }
117
119 : std::vector<T>(x), g(std::move(x.g)), default_value(x.default_value) { }
120
121 inline void adapt() {
122 if (g && (std::size_t)g->max_edge_index() >= std::vector<T>::size()) {
123 std::vector<T>::resize(g->max_edge_index() + 1, default_value);
124 }
125 }
126
128 adapt();
129 return std::vector<T>::operator[](e->index());
130 }
131
133 OGDF_ASSERT((std::size_t)e->index() < this->size());
134 return std::vector<T>::operator[](e->index());
135 }
136
138 std::vector<T>::operator=(x);
140 return *this;
141 }
142
144 std::vector<T>::operator=(std::move(x));
145 default_value = x.default_value;
146 return *this;
147 }
148};
149
150}
151
152}
153}
154}
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
const_reference operator[](const Edge &e) const
Definition OGDFVector.h:132
typename std::vector< T >::reference reference
Definition OGDFVector.h:100
EdgeVector< T, Graph > & operator=(EdgeVector< T, Graph > &&x)
Definition OGDFVector.h:143
typename std::vector< T >::const_reference const_reference
Definition OGDFVector.h:101
EdgeVector< T, Graph > & operator=(const EdgeVector< T, Graph > &x)
Definition OGDFVector.h:137
NodeVector< T, Graph > & operator=(const NodeVector< T, Graph > &x)
Definition OGDFVector.h:83
const_reference operator[](const Node &v) const
Definition OGDFVector.h:78
NodeVector(const NodeVector< T, Graph > &x)
Definition OGDFVector.h:64
typename std::vector< T >::const_reference const_reference
Definition OGDFVector.h:47
typename std::vector< T >::reference reference
Definition OGDFVector.h:46
NodeVector< T, Graph > & operator=(NodeVector< T, Graph > &&x)
Definition OGDFVector.h:89
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.
Definition GML.h:111