19 #ifndef STATICPROPERTY_H 20 #define STATICPROPERTY_H 25 #include <tulip/Graph.h> 28 template <
typename TYPE>
29 class NodeStaticProperty :
public std::vector<TYPE> {
34 NodeStaticProperty(
const Graph *g) :graph(g) {
37 this->resize(graph->numberOfNodes());
41 inline typename std::vector<TYPE>::const_reference getNodeValue(node n)
const {
42 return (*
this)[graph->nodePos(n)];
46 inline typename std::vector<TYPE>::const_reference setNodeValue(node n,
48 return (*
this)[graph->nodePos(n)] = val;
52 void setAll(
const TYPE &val) {
54 #pragma omp parallel for 57 for (
unsigned int i = 0; i < this->size(); ++i)
62 void addNodeValue(node n, TYPE val) {
63 unsigned int nPos = graph->nodePos(n);
65 if (nPos + 1 > this->size())
66 this->resize(nPos + 1);
72 template<
typename PROP_PTR>
73 void copyFromProperty(PROP_PTR prop) {
74 const std::vector<node>& nodes = graph->nodes();
75 unsigned int nbNodes = nodes.size();
77 #pragma omp parallel for 80 for (
unsigned int i = 0; i < nbNodes; ++i)
81 (*
this)[i] = prop->getNodeValue(nodes[i]);
85 template<
typename PROP_PTR>
86 void copyToProperty(PROP_PTR prop) {
87 const std::vector<node>& nodes = graph->nodes();
88 unsigned int nbNodes = nodes.size();
90 for (
unsigned int i = 0; i < nbNodes; ++i)
91 prop->setNodeValue(nodes[i], (*
this)[i]);
97 template<>
template<
typename PROP_PTR>
98 void NodeStaticProperty<bool>::copyFromProperty(PROP_PTR prop) {
99 const std::vector<node>& nodes = graph->nodes();
100 unsigned int nbNodes = nodes.size();
102 for (
unsigned int i = 0; i < nbNodes; ++i)
103 (*
this)[i] = prop->getNodeValue(nodes[i]);
106 template <
typename TYPE>
107 class EdgeStaticProperty :
public std::vector<TYPE> {
112 EdgeStaticProperty(
const Graph *g) :graph(g) {
115 this->resize(graph->numberOfEdges());
119 inline typename std::vector<TYPE>::const_reference getEdgeValue(edge n)
const {
120 return (*
this)[graph->edgePos(n)];
124 inline typename std::vector<TYPE>::const_reference setEdgeValue(edge n,
126 return (*
this)[graph->edgePos(n)] = val;
129 void setAll(
const TYPE &val) {
131 #pragma omp parallel for 134 for (
unsigned int i = 0; i < this->size(); ++i)
139 void addEdgeValue(edge n, TYPE val) {
140 unsigned int nPos = graph->edgePos(n);
142 if (nPos + 1 > this->size())
143 this->resize(nPos + 1);
145 setEdgeValue(n, val);
149 template<
typename PROP_PTR>
150 void copyFromProperty(PROP_PTR prop) {
151 const std::vector<edge>& edges = graph->edges();
152 unsigned int nbEdges = edges.size();
154 #pragma omp parallel for 157 for (
unsigned int i = 0; i < nbEdges; ++i)
158 (*
this)[i] = prop->getEdgeValue(edges[i]);
162 template<
typename PROP_PTR>
163 void copyToProperty(PROP_PTR prop) {
164 const std::vector<edge>& edges = graph->edges();
165 unsigned int nbEdges = edges.size();
167 for (
unsigned int i = 0; i < nbEdges; ++i)
168 prop->setEdgeValue(edges[i], (*
this)[i]);
174 template<>
template<
typename PROP_PTR>
175 void EdgeStaticProperty<bool>::copyFromProperty(PROP_PTR prop) {
176 const std::vector<edge>& edges = graph->edges();
177 unsigned int nbEdges = edges.size();
179 for (
unsigned int i = 0; i < nbEdges; ++i)
180 (*
this)[i] = prop->getEdgeValue(edges[i]);