19 #ifndef STATICPROPERTY_H
20 #define STATICPROPERTY_H
22 #include <tulip/Graph.h>
23 #include <tulip/GraphParallelTools.h>
24 #include <tulip/NumericProperty.h>
27 template <
typename TYPE>
28 class NodeStaticProperty :
public std::vector<TYPE> {
33 NodeStaticProperty(
const Graph *g) : std::vector<TYPE>(g->numberOfNodes()), graph(g) {}
35 NodeStaticProperty(
const Graph *g, TYPE val)
36 : std::vector<TYPE>(g->numberOfNodes(), val), graph(g) {}
38 inline typename std::vector<TYPE>::const_reference operator[](
unsigned int i)
const {
39 return std::vector<TYPE>::operator[](i);
42 inline typename std::vector<TYPE>::reference operator[](
unsigned int i) {
43 return std::vector<TYPE>::operator[](i);
46 inline typename std::vector<TYPE>::const_reference operator[](node n)
const {
47 return (*
this)[graph->nodePos(n)];
50 inline typename std::vector<TYPE>::reference operator[](node n) {
51 return (*
this)[graph->nodePos(n)];
55 inline typename std::vector<TYPE>::const_reference getNodeValue(node n)
const {
60 inline void setNodeValue(node n, TYPE val) {
65 void setAll(
const TYPE &val) {
66 TLP_PARALLEL_MAP_INDICES(graph->numberOfNodes(), [&](
unsigned int i) { (*this)[i] = val; });
70 void addNodeValue(node n, TYPE val) {
71 unsigned int nPos = graph->nodePos(n);
73 if (nPos + 1 > this->size())
74 this->resize(nPos + 1);
80 template <
typename PROP_PTR>
81 void copyFromProperty(PROP_PTR prop) {
83 graph, [&](
const node n,
unsigned int i) { (*this)[i] = prop->getNodeValue(n); });
87 void copyFromNumericProperty(
const NumericProperty *prop) {
89 graph, [&](
const node n,
unsigned int i) { (*this)[i] = prop->getNodeDoubleValue(n); });
93 template <
typename PROP_PTR>
94 void copyToProperty(PROP_PTR prop) {
95 const std::vector<node> &nodes = graph->nodes();
96 unsigned int nbNodes = nodes.size();
98 for (
unsigned int i = 0; i < nbNodes; ++i)
99 prop->setNodeValue(nodes[i], (*
this)[i]);
104 class NodeStaticProperty<bool> :
public std::vector<unsigned char> {
109 NodeStaticProperty(
const Graph *g) : std::vector<unsigned char>(g->numberOfNodes()), graph(g) {}
111 NodeStaticProperty(
const Graph *g,
bool b)
112 : std::vector<unsigned char>(g->numberOfNodes(), b), graph(g) {}
114 inline const Graph *getGraph()
const {
118 inline bool operator[](
unsigned int i)
const {
119 return static_cast<bool>(std::vector<unsigned char>::operator[](i));
122 inline std::vector<unsigned char>::reference operator[](
unsigned int i) {
123 return std::vector<unsigned char>::operator[](i);
126 inline bool operator[](node n)
const {
127 return (*
this)[graph->nodePos(n)];
130 inline std::vector<unsigned char>::reference operator[](node n) {
131 return (*
this)[graph->nodePos(n)];
135 inline bool getNodeValue(node n)
const {
136 return (*
this)[graph->nodePos(n)];
140 inline void setNodeValue(node n,
bool val) {
141 (*this)[graph->nodePos(n)] = val;
145 void setAll(
const bool &val) {
146 TLP_PARALLEL_MAP_INDICES(graph->numberOfNodes(), [&](
unsigned int i) { (*this)[i] = val; });
150 void addNodeValue(node n,
bool val) {
151 unsigned int nPos = graph->nodePos(n);
153 if (nPos + 1 > this->size())
154 this->resize(nPos + 1);
160 template <
typename PROP_PTR>
161 void copyFromProperty(PROP_PTR prop) {
163 graph, [&](
const node n,
unsigned int i) { (*this)[i] = prop->getNodeValue(n); });
167 template <
typename PROP_PTR>
168 void copyToProperty(PROP_PTR prop) {
169 const std::vector<node> &nodes = graph->nodes();
170 unsigned int nbNodes = nodes.size();
172 for (
unsigned int i = 0; i < nbNodes; ++i)
173 prop->setNodeValue(nodes[i], (*
this)[i]);
177 template <
typename TYPE>
178 class EdgeStaticProperty :
public std::vector<TYPE> {
183 EdgeStaticProperty(
const Graph *g) : std::vector<TYPE>(g->numberOfEdges()), graph(g) {}
184 EdgeStaticProperty(
const Graph *g, TYPE val)
185 : std::vector<TYPE>(g->numberOfEdges(), val), graph(g) {}
187 inline const Graph *getGraph()
const {
191 inline typename std::vector<TYPE>::const_reference operator[](
unsigned int i)
const {
192 return std::vector<TYPE>::operator[](i);
195 inline typename std::vector<TYPE>::reference operator[](
unsigned int i) {
196 return std::vector<TYPE>::operator[](i);
199 inline typename std::vector<TYPE>::const_reference operator[](edge e)
const {
200 return (*
this)[graph->edgePos(e)];
203 inline typename std::vector<TYPE>::reference operator[](edge e) {
204 return (*
this)[graph->edgePos(e)];
208 inline typename std::vector<TYPE>::const_reference getEdgeValue(edge e)
const {
213 inline void setEdgeValue(edge e, TYPE val) {
217 void setAll(
const TYPE &val) {
218 TLP_PARALLEL_MAP_INDICES(graph->numberOfEdges(), [&](
unsigned int i) { (*this)[i] = val; });
222 void addEdgeValue(edge e, TYPE val) {
223 unsigned int ePos = graph->edgePos(e);
225 if (ePos + 1 > this->size())
226 this->resize(ePos + 1);
232 template <
typename PROP_PTR>
233 void copyFromProperty(PROP_PTR prop) {
235 graph, [&](
const edge e,
unsigned int i) { (*this)[i] = prop->getEdgeValue(e); });
239 void copyFromNumericProperty(
const NumericProperty *prop) {
241 graph, [&](
const edge e,
unsigned int i) { (*this)[i] = prop->getEdgeDoubleValue(e); });
245 template <
typename PROP_PTR>
246 void copyToProperty(PROP_PTR prop) {
247 const std::vector<edge> &edges = graph->edges();
248 unsigned int nbEdges = edges.size();
250 for (
unsigned int i = 0; i < nbEdges; ++i)
251 prop->setEdgeValue(edges[i], (*
this)[i]);
256 class EdgeStaticProperty<bool> :
public std::vector<unsigned char> {
261 EdgeStaticProperty(
const Graph *g) : std::vector<unsigned char>(g->numberOfEdges()), graph(g) {}
263 EdgeStaticProperty(
const Graph *g,
bool b)
264 : std::vector<unsigned char>(g->numberOfEdges(), b), graph(g) {}
266 inline bool operator[](
unsigned int i)
const {
267 return static_cast<bool>(std::vector<unsigned char>::operator[](i));
270 inline std::vector<unsigned char>::reference operator[](
unsigned int i) {
271 return std::vector<unsigned char>::operator[](i);
274 inline bool operator[](edge e)
const {
275 return (*
this)[graph->edgePos(e)];
278 inline std::vector<unsigned char>::reference operator[](edge e) {
279 return (*
this)[graph->edgePos(e)];
283 inline bool getEdgeValue(edge e)
const {
284 return (*
this)[graph->edgePos(e)];
288 inline void setEdgeValue(edge e,
bool val) {
289 (*this)[graph->edgePos(e)] = val;
293 void setAll(
const bool &val) {
294 TLP_PARALLEL_MAP_INDICES(graph->numberOfEdges(), [&](
unsigned int i) { (*this)[i] = val; });
298 void addEdgeValue(edge e,
bool val) {
299 unsigned int ePos = graph->edgePos(e);
301 if (ePos + 1 > this->size())
302 this->resize(ePos + 1);
308 template <
typename PROP_PTR>
309 void copyFromProperty(PROP_PTR prop) {
311 graph, [&](
const edge e,
unsigned int i) { (*this)[i] = prop->getEdgeValue(e); });
315 template <
typename PROP_PTR>
316 void copyToProperty(PROP_PTR prop) {
317 const std::vector<edge> &edges = graph->edges();
318 unsigned int nbEdges = edges.size();
320 for (
unsigned int i = 0; i < nbEdges; ++i)
321 prop->setEdgeValue(edges[i], (*
this)[i]);
void TLP_PARALLEL_MAP_EDGES_AND_INDICES(const tlp::Graph *graph, const EdgeFunction &edgeFunction)
void TLP_PARALLEL_MAP_NODES_AND_INDICES(const tlp::Graph *graph, const NodeFunction &nodeFunction)