19 #ifndef STATICPROPERTY_H 20 #define STATICPROPERTY_H 22 #include <tulip/Graph.h> 23 #include <tulip/GraphParallelTools.h> 26 template <
typename TYPE>
27 class NodeStaticProperty :
public std::vector<TYPE> {
32 NodeStaticProperty(
const Graph *g) : graph(g) {
35 this->resize(graph->numberOfNodes());
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) {
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 template <
typename PROP_PTR>
88 void copyToProperty(PROP_PTR prop) {
89 const std::vector<node> &nodes = graph->nodes();
90 unsigned int nbNodes = nodes.size();
92 for (
unsigned int i = 0; i < nbNodes; ++i)
93 prop->setNodeValue(nodes[i], (*
this)[i]);
98 class NodeStaticProperty<bool> :
public std::vector<unsigned char> {
103 NodeStaticProperty(
const Graph *g) : graph(g) {
106 this->resize(graph->numberOfNodes());
109 inline const Graph *getGraph()
const {
113 inline bool operator[](
unsigned int i)
const {
114 return static_cast<bool>(std::vector<unsigned char>::operator[](i));
117 inline std::vector<unsigned char>::reference operator[](
unsigned int i) {
118 return std::vector<unsigned char>::operator[](i);
121 inline bool operator[](node n)
const {
122 return (*
this)[graph->nodePos(n)];
125 inline std::vector<unsigned char>::reference operator[](node n) {
126 return (*
this)[graph->nodePos(n)];
130 inline bool getNodeValue(node n)
const {
131 return (*
this)[graph->nodePos(n)];
135 inline void setNodeValue(node n,
bool val) {
136 (*this)[graph->nodePos(n)] = val;
140 void setAll(
const bool &val) {
145 void addNodeValue(node n,
bool val) {
146 unsigned int nPos = graph->nodePos(n);
148 if (nPos + 1 > this->size())
149 this->resize(nPos + 1);
155 template <
typename PROP_PTR>
156 void copyFromProperty(PROP_PTR prop) {
158 graph, [&](
const node n,
unsigned int i) { (*this)[i] = prop->getNodeValue(n); });
162 template <
typename PROP_PTR>
163 void copyToProperty(PROP_PTR prop) {
164 const std::vector<node> &nodes = graph->nodes();
165 unsigned int nbNodes = nodes.size();
167 for (
unsigned int i = 0; i < nbNodes; ++i)
168 prop->setNodeValue(nodes[i], (*
this)[i]);
172 template <
typename TYPE>
173 class EdgeStaticProperty :
public std::vector<TYPE> {
178 EdgeStaticProperty(
const Graph *g) : graph(g) {
181 this->resize(graph->numberOfEdges());
184 inline const Graph *getGraph()
const {
188 inline typename std::vector<TYPE>::const_reference operator[](
unsigned int i)
const {
189 return std::vector<TYPE>::operator[](i);
192 inline typename std::vector<TYPE>::reference operator[](
unsigned int i) {
193 return std::vector<TYPE>::operator[](i);
196 inline typename std::vector<TYPE>::const_reference operator[](edge e)
const {
197 return (*
this)[graph->edgePos(e)];
200 inline typename std::vector<TYPE>::reference operator[](edge e) {
201 return (*
this)[graph->edgePos(e)];
205 inline typename std::vector<TYPE>::const_reference getEdgeValue(edge e)
const {
210 inline void setEdgeValue(edge e, TYPE val) {
214 void setAll(
const TYPE &val) {
219 void addEdgeValue(edge e, TYPE val) {
220 unsigned int ePos = graph->edgePos(e);
222 if (ePos + 1 > this->size())
223 this->resize(ePos + 1);
229 template <
typename PROP_PTR>
230 void copyFromProperty(PROP_PTR prop) {
232 graph, [&](
const edge e,
unsigned int i) { (*this)[i] = prop->getEdgeValue(e); });
236 template <
typename PROP_PTR>
237 void copyToProperty(PROP_PTR prop) {
238 const std::vector<edge> &edges = graph->edges();
239 unsigned int nbEdges = edges.size();
241 for (
unsigned int i = 0; i < nbEdges; ++i)
242 prop->setEdgeValue(edges[i], (*
this)[i]);
247 class EdgeStaticProperty<bool> :
public std::vector<unsigned char> {
252 EdgeStaticProperty(
const Graph *g) : graph(g) {
255 this->resize(graph->numberOfEdges());
258 inline bool operator[](
unsigned int i)
const {
259 return static_cast<bool>(std::vector<unsigned char>::operator[](i));
262 inline std::vector<unsigned char>::reference operator[](
unsigned int i) {
263 return std::vector<unsigned char>::operator[](i);
266 inline bool operator[](edge e)
const {
267 return (*
this)[graph->edgePos(e)];
270 inline std::vector<unsigned char>::reference operator[](edge e) {
271 return (*
this)[graph->edgePos(e)];
275 inline bool getEdgeValue(edge e)
const {
276 return (*
this)[graph->edgePos(e)];
280 inline void setEdgeValue(edge e,
bool val) {
281 (*this)[graph->edgePos(e)] = val;
285 void setAll(
const bool &val) {
290 void addEdgeValue(edge e,
bool val) {
291 unsigned int ePos = graph->edgePos(e);
293 if (ePos + 1 > this->size())
294 this->resize(ePos + 1);
300 template <
typename PROP_PTR>
301 void copyFromProperty(PROP_PTR prop) {
303 graph, [&](
const edge e,
unsigned int i) { (*this)[i] = prop->getEdgeValue(e); });
307 template <
typename PROP_PTR>
308 void copyToProperty(PROP_PTR prop) {
309 const std::vector<edge> &edges = graph->edges();
310 unsigned int nbEdges = edges.size();
312 for (
unsigned int i = 0; i < nbEdges; ++i)
313 prop->setEdgeValue(edges[i], (*
this)[i]);
void TLP_PARALLEL_MAP_INDICES(size_t maxIdx, const IdxFunction &idxFunction)
void TLP_PARALLEL_MAP_NODES_AND_INDICES(const tlp::Graph *graph, const NodeFunction &nodeFunction)
void TLP_PARALLEL_MAP_EDGES_AND_INDICES(const tlp::Graph *graph, const EdgeFunction &edgeFunction)