Tulip  5.6.3
Large graphs analysis and drawing
AbstractProperty.cxx
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 #include <cstdlib>
20 #include <tulip/BasicIterators.h>
21 
22 template <class Tnode, class Tedge, class Tprop>
24  Tprop::graph = sg;
25  Tprop::name = n;
26  nodeDefaultValue = Tnode::defaultValue();
27  edgeDefaultValue = Tedge::defaultValue();
28  nodeProperties.setAll(Tnode::defaultValue());
29  edgeProperties.setAll(Tedge::defaultValue());
30  Tprop::metaValueCalculator = nullptr;
31 }
32 //=============================================================
33 template <class Tnode, class Tedge, class Tprop>
34 inline typename Tnode::RealType
36  return nodeDefaultValue;
37 }
38 //=============================================================
39 template <class Tnode, class Tedge, class Tprop>
40 inline typename Tedge::RealType
42  return edgeDefaultValue;
43 }
44 //=============================================================
45 template <class Tnode, class Tedge, class Tprop>
46 inline typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue
48  assert(n.isValid());
49  return nodeProperties.get(n.id);
50 }
51 //=============================================================
52 template <class Tnode, class Tedge, class Tprop>
53 inline typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue
55  assert(e.isValid());
56  return edgeProperties.get(e.id);
57 }
58 //=================================================================================
59 template <class Tnode, class Tedge, class Tprop>
61  typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue val,
62  const Graph *sg) const {
63  if (sg == nullptr)
64  sg = this->graph;
65 
66  tlp::Iterator<unsigned int> *it = nullptr;
67 
68  if (sg == this->graph)
69  it = nodeProperties.findAll(val);
70 
71  if (it == nullptr)
72  return new tlp::SGraphNodeIterator<typename Tnode::RealType>(sg, nodeProperties, val);
73 
74  return (new tlp::UINTIterator<node>(it));
75 }
76 //=================================================================================
77 template <class Tnode, class Tedge, class Tprop>
79  typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue val,
80  const Graph *sg) const {
81  if (sg == nullptr)
82  sg = this->graph;
83 
84  tlp::Iterator<unsigned int> *it = nullptr;
85 
86  if (sg == this->graph)
87  it = edgeProperties.findAll(val);
88 
89  if (it == nullptr)
90  return new tlp::SGraphEdgeIterator<typename Tedge::RealType>(sg, edgeProperties, val);
91 
92  return (new tlp::UINTIterator<edge>(it));
93 }
94 //=============================================================
95 template <class Tnode, class Tedge, class Tprop>
97  const tlp::node n, typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v) {
98  assert(n.isValid());
99  Tprop::notifyBeforeSetNodeValue(n);
100  nodeProperties.set(n.id, v);
101  Tprop::notifyAfterSetNodeValue(n);
102 }
103 //=============================================================
104 template <class Tnode, class Tedge, class Tprop>
106  const tlp::edge e, typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v) {
107  assert(e.isValid());
108  Tprop::notifyBeforeSetEdgeValue(e);
109  edgeProperties.set(e.id, v);
110  Tprop::notifyAfterSetEdgeValue(e);
111 }
112 //=============================================================
113 template <class Tnode, class Tedge, class Tprop>
115  typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v) {
116  Tprop::notifyBeforeSetAllNodeValue();
117  nodeDefaultValue = v;
118  nodeProperties.setAll(v);
119  Tprop::notifyAfterSetAllNodeValue();
120 }
121 //=============================================================
122 template <class Tnode, class Tedge, class Tprop>
124  typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v) {
125  if (nodeDefaultValue == v) {
126  return;
127  }
128 
129  // backup old default value
130  auto oldDefaultValue = nodeDefaultValue;
131  // we need to get the list of nodes whose value equals the current default one first
132  std::vector<tlp::node> nodesOldDefaultToUpdate;
133  std::vector<tlp::node> nodesDefaultToUpdate;
134 
135  for (auto n : this->getGraph()->nodes()) {
136  auto val = nodeProperties.get(n.id);
137 
138  if (val == oldDefaultValue) {
139  nodesOldDefaultToUpdate.push_back(n);
140  } else if (val == v) {
141  nodesDefaultToUpdate.push_back(n);
142  }
143  }
144 
145  // set new default value that will be associated to future added nodes
146  nodeDefaultValue = v;
147  nodeProperties.setDefault(v);
148 
149  // reset the backup nodes to the old default value as there is a new one in the
150  // underlying MutableContainer
151  for (size_t i = 0; i < nodesOldDefaultToUpdate.size(); ++i) {
152  nodeProperties.set(nodesOldDefaultToUpdate[i].id, oldDefaultValue);
153  }
154 
155  // reset the backup nodes to their current value in order
156  // to synchronize the underlying MutableContainer state
157  for (size_t i = 0; i < nodesDefaultToUpdate.size(); ++i) {
158  nodeProperties.set(nodesDefaultToUpdate[i].id, v, true);
159  }
160 }
161 //=============================================================
162 template <class Tnode, class Tedge, class Tprop>
164  typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v, const Graph *g) {
165  auto graph = this->getGraph();
166  if (v == nodeDefaultValue) {
167  // speedup update if v is the default value
168  if (graph == g)
169  setAllNodeValue(v);
170  else if (graph->isDescendantGraph(g)) {
171  auto it = getNonDefaultValuatedNodes(g);
172  while (it->hasNext()) {
173  setNodeValue(it->next(), v);
174  }
175  delete it;
176  }
177  } else if (graph == g || graph->isDescendantGraph(g)) {
178  for (auto n : g->nodes()) {
179  setNodeValue(n, v);
180  }
181  }
182 }
183 //=============================================================
184 template <class Tnode, class Tedge, class Tprop>
186  typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v) {
187  if (edgeDefaultValue == v) {
188  return;
189  }
190 
191  // backup old default value
192  auto oldDefaultValue = edgeDefaultValue;
193  // backup list of edges whose value equals the current default one
194  std::vector<tlp::edge> edgesOldDefaultToUpdate;
195  // backup list of edges whose value equals the new default one
196  std::vector<tlp::edge> edgesDefaultToUpdate;
197 
198  for (auto e : this->getGraph()->edges()) {
199  auto val = edgeProperties.get(e.id);
200 
201  if (val == oldDefaultValue) {
202  edgesOldDefaultToUpdate.push_back(e);
203  } else if (val == v) {
204  edgesDefaultToUpdate.push_back(e);
205  }
206  }
207 
208  // set new default value that will be associated to future added edges
209  edgeDefaultValue = v;
210  edgeProperties.setDefault(v);
211 
212  // reset the backup edges to the old default value as there is a new one in the
213  // underlying MutableContainer
214  for (size_t i = 0; i < edgesOldDefaultToUpdate.size(); ++i) {
215  edgeProperties.set(edgesOldDefaultToUpdate[i].id, oldDefaultValue);
216  }
217 
218  // reset the backup edges to their current value in order
219  // to synchronize the underlying MutableContainer state
220  for (size_t i = 0; i < edgesDefaultToUpdate.size(); ++i) {
221  edgeProperties.set(edgesDefaultToUpdate[i].id, v, true);
222  }
223 }
224 //============================================================
225 template <class Tnode, class Tedge, class Tprop>
227  typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v) {
228  Tprop::notifyBeforeSetAllEdgeValue();
229  edgeDefaultValue = v;
230  edgeProperties.setAll(v);
231  Tprop::notifyAfterSetAllEdgeValue();
232 }
233 //============================================================
234 template <class Tnode, class Tedge, class Tprop>
236  typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v, const Graph *g) {
237  auto graph = this->getGraph();
238  if (v == edgeDefaultValue) {
239  // speedup update if v is the default value
240  if (graph == g)
241  setAllEdgeValue(v);
242  else if (graph->isDescendantGraph(g)) {
243  auto it = getNonDefaultValuatedEdges(g);
244  while (it->hasNext()) {
245  setEdgeValue(it->next(), v);
246  }
247  delete it;
248  }
249  } else if (graph == g || graph->isDescendantGraph(g)) {
250  for (auto e : g->edges()) {
251  setEdgeValue(e, v);
252  }
253  }
254 }
255 //============================================================
256 template <class Tnode, class Tedge, class Tprop>
258  const typename Tnode::RealType &n1Value = getNodeValue(n1);
259  const typename Tnode::RealType &n2Value = getNodeValue(n2);
260  return (n1Value < n2Value) ? -1 : ((n1Value == n2Value) ? 0 : 1);
261 }
262 //============================================================
263 template <class Tnode, class Tedge, class Tprop>
265  const typename Tedge::RealType &e1Value = getEdgeValue(e1);
266  const typename Tedge::RealType &e2Value = getEdgeValue(e2);
267  return (e1Value < e2Value) ? -1 : ((e1Value == e2Value) ? 0 : 1);
268 }
269 ///@cond DOXYGEN_HIDDEN
270 //============================================================
271 // define a template iterator class to iterate over elts
272 // belonging to a given graph instance
273 // used by the two methods below
274 template <typename ELT_TYPE>
275 class GraphEltIterator : public tlp::Iterator<ELT_TYPE> {
276 public:
277  ELT_TYPE next() override {
278  ELT_TYPE tmp = _elt;
279 
280  if ((_hasnext = _it->hasNext())) {
281  _elt = _it->next();
282 
283  while (!_graph->isElement(_elt)) {
284  if (!_it->hasNext()) {
285  _hasnext = false;
286  return tmp;
287  }
288  _elt = _it->next();
289  }
290  _hasnext = true;
291  }
292 
293  return tmp;
294  }
295  GraphEltIterator(const tlp::Graph *g, tlp::Iterator<ELT_TYPE> *it)
296  : _it(it), _graph(g), _elt(ELT_TYPE()), _hasnext(false) {
297  assert(g);
298  next();
299  }
300 
301  bool hasNext() override {
302  return (_hasnext);
303  }
304  ~GraphEltIterator() override {
305  delete _it;
306  }
307 
308 private:
310  const tlp::Graph *_graph;
311  ELT_TYPE _elt;
312  bool _hasnext;
313 };
314 
315 //============================================================
316 // define a class to iterate over graph elts belonging to
317 // a given graph instance and whose property associated values
318 // are not the default
319 template <typename ELT_TYPE, typename VALUE_TYPE>
320 class GraphEltNonDefaultValueIterator : public tlp::Iterator<ELT_TYPE> {
321 public:
322  ELT_TYPE next() override {
323  ELT_TYPE tmp = _elt;
324 
325  if ((_hasnext = _it->hasNext())) {
326  _elt = _it->next();
327 
328  while (_values.get(_elt.id) == _defaultValue) {
329  if (!_it->hasNext()) {
330  _hasnext = false;
331  return tmp;
332  }
333  _elt = _it->next();
334  }
335  _hasnext = true;
336  }
337 
338  return tmp;
339  }
340  GraphEltNonDefaultValueIterator(
342  const tlp::MutableContainer<typename VALUE_TYPE::RealType> &values)
343  : _it(it), _values(values), _elt(ELT_TYPE()), _hasnext(false),
344  _defaultValue(values.getDefault()) {
345  next();
346  }
347 
348  bool hasNext() override {
349  return (_hasnext);
350  }
351  ~GraphEltNonDefaultValueIterator() override {
352  delete _it;
353  }
354 
355 private:
357  const tlp::MutableContainer<typename VALUE_TYPE::RealType> &_values;
358  ELT_TYPE _elt;
359  bool _hasnext;
360  typename tlp::StoredType<typename VALUE_TYPE::RealType>::ReturnedValue _defaultValue;
361 };
362 #define NB_THRESHOLD(nb) nb / 2
363 ///@endcond
364 //============================================================
365 template <class Tnode, class Tedge, class Tprop>
368  auto nb = nodeProperties.numberOfNonDefaultValues();
369  if (g == nullptr)
370  g = Tprop::graph;
371  // if the property is not registered or if the number of graph nodes
372  // is greater then a threshold regarding the number of non default
373  // valuated nodes, it is faster to iterate the nodeProperties container
374  if (Tprop::name.empty() || (g->numberOfNodes() > NB_THRESHOLD(nb))) {
376  new tlp::UINTIterator<tlp::node>(nodeProperties.findAll(nodeDefaultValue, false));
377 
378  if (Tprop::name.empty())
379  // we always need to check that nodes belong to graph
380  // for non registered properties, because deleted nodes are not erased
381  // from them
382  return new GraphEltIterator<tlp::node>(g, it);
383 
384  return (g == Tprop::graph) ? it : new GraphEltIterator<tlp::node>(g, it);
385  } else
386  // we iterate the graph nodes
387  return new GraphEltNonDefaultValueIterator<tlp::node, Tnode>(g->getNodes(), nodeProperties);
388 }
389 //============================================================
390 template <class Tnode, class Tedge, class Tprop>
392  if ((g == nullptr) || ((g == Tprop::graph) && !Tprop::name.empty())) {
393  return nodeProperties.hasNonDefaultValues();
394  } else {
395  return !tlp::iteratorEmpty(getNonDefaultValuatedNodes(g));
396  }
397 }
398 //============================================================
399 template <class Tnode, class Tedge, class Tprop>
400 unsigned int
402  if ((g == nullptr) || ((g == Tprop::graph) && !Tprop::name.empty())) {
403  return nodeProperties.numberOfNonDefaultValues();
404  } else {
405  return tlp::iteratorCount(getNonDefaultValuatedNodes(g));
406  }
407 }
408 //============================================================
409 template <class Tnode, class Tedge, class Tprop>
411  return Tnode::valueSize();
412 }
413 //============================================================
414 template <class Tnode, class Tedge, class Tprop>
416  Tnode::writeb(oss, nodeDefaultValue);
417 }
418 //============================================================
419 template <class Tnode, class Tedge, class Tprop>
421  assert(n.isValid());
422  Tnode::writeb(oss, nodeProperties.get(n.id));
423 }
424 //============================================================
425 template <class Tnode, class Tedge, class Tprop>
427  if (Tnode::readb(iss, nodeDefaultValue)) {
428  nodeProperties.setAll(nodeDefaultValue);
429  return true;
430  }
431 
432  return false;
433 }
434 //============================================================
435 template <class Tnode, class Tedge, class Tprop>
437  typename Tnode::RealType val;
438 
439  if (Tnode::readb(iss, val)) {
440  nodeProperties.set(n.id, val);
441  return true;
442  }
443 
444  return false;
445 }
446 //============================================================
447 template <class Tnode, class Tedge, class Tprop>
450  auto nb = edgeProperties.numberOfNonDefaultValues();
451  if (g == nullptr)
452  g = Tprop::graph;
453  // if the property is not registered or if the number of graph edges
454  // is greater then a threshold regarding the number of non default
455  // valuated edges, it is faster to iterate the edgeProperties container
456  if (Tprop::name.empty() || (g->numberOfEdges() > NB_THRESHOLD(nb))) {
458  new tlp::UINTIterator<tlp::edge>(edgeProperties.findAll(edgeDefaultValue, false));
459 
460  if (Tprop::name.empty())
461  // we always need to check that edges belong to graph
462  // for non registered properties, because deleted edges are not erased
463  // from them
464  return new GraphEltIterator<tlp::edge>(g != nullptr ? g : Tprop::graph, it);
465 
466  return ((g == nullptr) || (g == Tprop::graph)) ? it : new GraphEltIterator<tlp::edge>(g, it);
467  } else
468  // we iterate the graph edges
469  return new GraphEltNonDefaultValueIterator<tlp::edge, Tedge>(g->getEdges(), edgeProperties);
470 }
471 //============================================================
472 template <class Tnode, class Tedge, class Tprop>
474  if ((g == nullptr) || ((g == Tprop::graph) && !Tprop::name.empty())) {
475  return edgeProperties.hasNonDefaultValues();
476  } else {
477  return !tlp::iteratorEmpty(getNonDefaultValuatedEdges(g));
478  }
479 }
480 //============================================================
481 template <class Tnode, class Tedge, class Tprop>
482 unsigned int
484  if ((g == nullptr) || ((g == Tprop::graph) && !Tprop::name.empty())) {
485  return edgeProperties.numberOfNonDefaultValues();
486  } else {
487  return tlp::iteratorCount(getNonDefaultValuatedEdges(g));
488  }
489 }
490 //============================================================
491 template <class Tnode, class Tedge, class Tprop>
493  return Tedge::valueSize();
494 }
495 //============================================================
496 template <class Tnode, class Tedge, class Tprop>
498  Tedge::writeb(oss, edgeDefaultValue);
499 }
500 //============================================================
501 template <class Tnode, class Tedge, class Tprop>
503  assert(e.isValid());
504  Tedge::writeb(oss, edgeProperties.get(e.id));
505 }
506 //============================================================
507 template <class Tnode, class Tedge, class Tprop>
509  if (Tedge::readb(iss, edgeDefaultValue)) {
510  edgeProperties.setAll(edgeDefaultValue);
511  return true;
512  }
513 
514  return false;
515 }
516 //============================================================
517 template <class Tnode, class Tedge, class Tprop>
519  typename Tedge::RealType val;
520 
521  if (Tedge::readb(iss, val)) {
522  edgeProperties.set(e.id, val);
523  return true;
524  }
525 
526  return false;
527 }
528 //============================================================
529 template <typename vectType, typename eltType, typename propType>
530 tlp::AbstractVectorProperty<vectType, eltType, propType>::AbstractVectorProperty(
531  tlp::Graph *g, const std::string &name)
532  : AbstractProperty<vectType, vectType, propType>(g, name) {}
533 //============================================================
534 template <typename vectType, typename eltType, typename propType>
535 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::tokenize(
536  const std::string &s, std::vector<std::string> &vect, char openChar, char sepChar,
537  char closeChar) {
538  return vectType::tokenize(s, vect, openChar, sepChar, closeChar);
539 }
540 //============================================================
541 template <typename vectType, typename eltType, typename propType>
542 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::setNodeStringValueAsVector(
543  const node n, const std::vector<std::string> &vs) {
544  typename vectType::RealType v;
545  if (!vectType::read(vs, v))
546  return false;
547 
548  this->setNodeValue(n, v);
549  return true;
550 }
551 //============================================================
552 template <typename vectType, typename eltType, typename propType>
553 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::setNodeStringValueAsVector(
554  const node n, const std::string &s, char openChar, char sepChar, char closeChar) {
555  typename vectType::RealType v;
556  std::istringstream iss(s);
557 
558  if (!vectType::read(iss, v, openChar, sepChar, closeChar))
559  return false;
560 
561  this->setNodeValue(n, v);
562  return true;
563 }
564 //============================================================
565 template <typename vectType, typename eltType, typename propType>
566 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::setEdgeStringValueAsVector(
567  const edge e, const std::vector<std::string> &vs) {
568  typename vectType::RealType v;
569  if (!vectType::read(vs, v))
570  return false;
571 
572  this->setEdgeValue(e, v);
573  return true;
574 }
575 //============================================================
576 template <typename vectType, typename eltType, typename propType>
577 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::setEdgeStringValueAsVector(
578  const edge e, const std::string &s, char openChar, char sepChar, char closeChar) {
579  typename vectType::RealType v;
580  std::istringstream iss(s);
581 
582  if (!vectType::read(iss, v, openChar, sepChar, closeChar))
583  return false;
584 
585  this->setEdgeValue(e, v);
586  return true;
587 }
588 //============================================================
589 template <typename vectType, typename eltType, typename propType>
590 void tlp::AbstractVectorProperty<vectType, eltType, propType>::setNodeEltValue(
591  const node n, unsigned int i,
592  typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
593  assert(n.isValid());
594  bool isNotDefault;
595  typename vectType::RealType &vect =
596  AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
597  assert(vect.size() > i);
598  this->propType::notifyBeforeSetNodeValue(n);
599 
600  if (isNotDefault)
601  vect[i] = v;
602  else {
603  typename vectType::RealType tmp(vect);
604  tmp[i] = v;
605  AbstractProperty<vectType, vectType, propType>::nodeProperties.set(n.id, tmp);
606  }
607 
608  this->propType::notifyAfterSetNodeValue(n);
609 }
610 //============================================================
611 template <typename vectType, typename eltType, typename propType>
612 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
613 tlp::AbstractVectorProperty<vectType, eltType, propType>::getNodeEltValue(const node n,
614  unsigned int i) const {
615  assert(n.isValid());
616  const typename vectType::RealType &vect =
617  AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n);
618  assert(vect.size() > i);
619  return vect[i];
620 }
621 //============================================================
622 template <typename vectType, typename eltType, typename propType>
623 void tlp::AbstractVectorProperty<vectType, eltType, propType>::pushBackNodeEltValue(
624  const node n, typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
625  assert(n.isValid());
626  bool isNotDefault;
627  typename vectType::RealType &vect =
628  AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
629  this->propType::notifyBeforeSetNodeValue(n);
630 
631  if (isNotDefault)
632  vect.push_back(v);
633  else {
634  typename vectType::RealType tmp(vect);
635  tmp.push_back(v);
636  AbstractProperty<vectType, vectType, propType>::nodeProperties.set(n, tmp);
637  }
638 
639  this->propType::notifyAfterSetNodeValue(n);
640 }
641 //============================================================
642 template <typename vectType, typename eltType, typename propType>
643 void tlp::AbstractVectorProperty<vectType, eltType, propType>::popBackNodeEltValue(const node n) {
644  assert(n.isValid());
645  bool isNotDefault;
646  typename vectType::RealType &vect =
647  AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
648  this->propType::notifyBeforeSetNodeValue(n);
649  assert(isNotDefault);
650  vect.pop_back();
651  this->propType::notifyAfterSetNodeValue(n);
652 }
653 //============================================================
654 template <typename vectType, typename eltType, typename propType>
655 void tlp::AbstractVectorProperty<vectType, eltType, propType>::resizeNodeValue(
656  const node n, size_t size, typename eltType::RealType elt) {
657  assert(n.isValid());
658  bool isNotDefault;
659  typename vectType::RealType &vect =
660  AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
661  assert(isNotDefault);
662  this->propType::notifyBeforeSetNodeValue(n);
663  vect.resize(size, elt);
664  this->propType::notifyAfterSetNodeValue(n);
665 }
666 //============================================================
667 template <typename vectType, typename eltType, typename propType>
668 void tlp::AbstractVectorProperty<vectType, eltType, propType>::setEdgeEltValue(
669  const edge e, unsigned int i,
670  typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
671  assert(e.isValid());
672  bool isNotDefault;
673  typename vectType::RealType &vect =
674  AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
675  assert(vect.size() > i);
676  this->propType::notifyBeforeSetEdgeValue(e);
677 
678  if (isNotDefault)
679  vect[i] = v;
680  else {
681  typename vectType::RealType tmp(vect);
682  tmp[i] = v;
683  AbstractProperty<vectType, vectType, propType>::edgeProperties.set(e, tmp);
684  }
685 
686  this->propType::notifyAfterSetEdgeValue(e);
687 }
688 //============================================================
689 template <typename vectType, typename eltType, typename propType>
690 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
691 tlp::AbstractVectorProperty<vectType, eltType, propType>::getEdgeEltValue(const edge e,
692  unsigned int i) const {
693  assert(e.isValid());
694  const typename vectType::RealType &vect =
695  AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e);
696  assert(vect.size() > i);
697  return vect[i];
698 } //============================================================
699 template <typename vectType, typename eltType, typename propType>
700 void tlp::AbstractVectorProperty<vectType, eltType, propType>::pushBackEdgeEltValue(
701  const edge e, typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
702  assert(e.isValid());
703  bool isNotDefault;
704  typename vectType::RealType &vect =
705  AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
706  this->propType::notifyBeforeSetEdgeValue(e);
707 
708  if (isNotDefault)
709  vect.push_back(v);
710  else {
711  typename vectType::RealType tmp(vect);
712  tmp.push_back(v);
713  AbstractProperty<vectType, vectType, propType>::edgeProperties.set(e, tmp);
714  }
715 
716  this->propType::notifyAfterSetEdgeValue(e);
717 }
718 //============================================================
719 template <typename vectType, typename eltType, typename propType>
720 void tlp::AbstractVectorProperty<vectType, eltType, propType>::popBackEdgeEltValue(const edge e) {
721  assert(e.isValid());
722  bool isNotDefault;
723  typename vectType::RealType &vect =
724  AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
725  this->propType::notifyBeforeSetEdgeValue(e);
726  assert(isNotDefault);
727  vect.pop_back();
728  this->propType::notifyAfterSetEdgeValue(e);
729 }
730 //============================================================
731 template <typename vectType, typename eltType, typename propType>
732 void tlp::AbstractVectorProperty<vectType, eltType, propType>::resizeEdgeValue(
733  const edge e, size_t size, typename eltType::RealType elt) {
734  assert(e.isValid());
735  bool isNotDefault;
736  typename vectType::RealType &vect =
737  AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
738  assert(isNotDefault);
739  this->propType::notifyBeforeSetEdgeValue(e);
740  vect.resize(size, elt);
741  this->propType::notifyAfterSetEdgeValue(e);
742 }
tlp::AbstractProperty::hasNonDefaultValuatedNodes
bool hasNonDefaultValuatedNodes(const Graph *g=nullptr) const override
Returns whether the property has nodes with a non default value. When given a Graph as parameter,...
Definition: AbstractProperty.cxx:391
tlp::AbstractProperty::writeEdgeValue
void writeEdgeValue(std::ostream &, edge) const override
Writes the value of an edge.
Definition: AbstractProperty.cxx:502
tlp::AbstractProperty::setValueToGraphEdges
virtual void setValueToGraphEdges(typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue v, const Graph *graph)
Sets the value of all edges in a graph and notify the observers. Only the edges from that graph will ...
Definition: AbstractProperty.cxx:235
tlp::Iterator::next
virtual T next()=0
Moves the Iterator on the next element.
tlp::AbstractProperty::getEdgeValue
tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue getEdgeValue(const edge e) const
Returns the value associated to the edge e in this property. If there is no value,...
Definition: AbstractProperty.cxx:54
tlp::Graph
Definition: Graph.h:234
tlp::Graph::isDescendantGraph
virtual bool isDescendantGraph(const Graph *subGraph) const =0
Indicates if the graph argument is a descendant of this graph.
tlp::AbstractProperty::numberOfNonDefaultValuatedNodes
unsigned int numberOfNonDefaultValuatedNodes(const Graph *g=nullptr) const override
Returns the number of nodes with a non default value. When given a Graph as parameter,...
Definition: AbstractProperty.cxx:401
tlp::AbstractProperty::getEdgeDefaultValue
Tedge::RealType getEdgeDefaultValue() const
Gets the default edge value of the property.
Definition: AbstractProperty.cxx:41
tlp::iteratorCount
unsigned int iteratorCount(Iterator< T > *it)
Counts the number of iterated elements.
Definition: Iterator.h:177
tlp::AbstractProperty::getEdgesEqualTo
virtual tlp::Iterator< edge > * getEdgesEqualTo(typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue v, const Graph *g=nullptr) const
Definition: AbstractProperty.cxx:78
tlp::Graph::nodes
virtual const std::vector< node > & nodes() const =0
Return a const reference on the vector of nodes of the graph It is the fastest way to access to nodes...
tlp::Graph::numberOfNodes
virtual unsigned int numberOfNodes() const =0
Gets the number of nodes in this graph.
tlp::AbstractProperty::setEdgeDefaultValue
virtual void setEdgeDefaultValue(typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue v)
Sets the value assigned as the default one to the future added edges.
Definition: AbstractProperty.cxx:185
tlp::Graph::numberOfEdges
virtual unsigned int numberOfEdges() const =0
Gets the number of edges in this graph.
tlp::Graph::getEdges
virtual Iterator< edge > * getEdges() const =0
Get an iterator over all the graph's edges.
tlp::AbstractProperty::readEdgeDefaultValue
bool readEdgeDefaultValue(std::istream &) override
Reads the edges default value.
Definition: AbstractProperty.cxx:508
tlp::AbstractProperty::setEdgeValue
virtual void setEdgeValue(const edge e, typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue v)
Set the value of an edge and notify the observers of a modification.
Definition: AbstractProperty.cxx:105
tlp::AbstractProperty::getNodesEqualTo
virtual tlp::Iterator< node > * getNodesEqualTo(typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v, const Graph *g=nullptr) const
Definition: AbstractProperty.cxx:60
tlp::node::id
unsigned int id
id The identifier of the node.
Definition: Node.h:44
tlp::AbstractProperty::setAllEdgeValue
virtual void setAllEdgeValue(typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue v)
Sets the value of all edges and notify the observers. All previous values are lost and the given valu...
Definition: AbstractProperty.cxx:226
tlp::AbstractProperty::edgeValueSize
unsigned int edgeValueSize() const override
Returns the size in bytes of an edge's value.
Definition: AbstractProperty.cxx:492
tlp::AbstractProperty::writeNodeValue
void writeNodeValue(std::ostream &, node) const override
Writes the value of a node.
Definition: AbstractProperty.cxx:420
tlp::AbstractProperty
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
Definition: AbstractProperty.h:55
tlp::AbstractProperty::getNodeValue
tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue getNodeValue(const node n) const
Returns the value associated with the node n in this property. If there is no value,...
Definition: AbstractProperty.cxx:47
tlp::AbstractProperty::writeNodeDefaultValue
void writeNodeDefaultValue(std::ostream &) const override
Writes the nodes default value.
Definition: AbstractProperty.cxx:415
tlp::node::isValid
bool isValid() const
isValid checks if the node is valid. An invalid node is a node whose id is UINT_MAX.
Definition: Node.h:92
tlp::AbstractProperty::setNodeDefaultValue
virtual void setNodeDefaultValue(typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v)
Sets the value assigned as the default one to the future added nodes.
Definition: AbstractProperty.cxx:123
tlp::edge::id
unsigned int id
id The identifier of the edge.
Definition: Edge.h:44
tlp::AbstractProperty::readEdgeValue
bool readEdgeValue(std::istream &, edge) override
Reads the value of an edge.
Definition: AbstractProperty.cxx:518
tlp::AbstractProperty::hasNonDefaultValuatedEdges
bool hasNonDefaultValuatedEdges(const Graph *g=nullptr) const override
Returns whether the property has edges with a non default value. When given a Graph as parameter,...
Definition: AbstractProperty.cxx:473
tlp::iteratorEmpty
bool iteratorEmpty(Iterator< T > *it)
Checks if an iterator is empty.
Definition: Iterator.h:229
tlp::AbstractProperty::setNodeValue
virtual void setNodeValue(const node n, typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v)
Sets the value of a node and notify the observers of a modification.
Definition: AbstractProperty.cxx:96
tlp::AbstractProperty::setValueToGraphNodes
virtual void setValueToGraphNodes(typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v, const Graph *graph)
Sets the value of all nodes in a graph and notify the observers. Only the nodes from that graph will ...
Definition: AbstractProperty.cxx:163
tlp::Graph::getNodes
virtual Iterator< node > * getNodes() const =0
Gets an iterator over this graph's nodes.
tlp::AbstractProperty::readNodeValue
bool readNodeValue(std::istream &, node) override
Reads the value of a node.
Definition: AbstractProperty.cxx:436
tlp::AbstractProperty::setAllNodeValue
virtual void setAllNodeValue(typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v)
Sets the value of all nodes and notify the observers. All previous values are lost and the given valu...
Definition: AbstractProperty.cxx:114
tlp::Iterator< tlp::node >
tlp::AbstractProperty::numberOfNonDefaultValuatedEdges
unsigned int numberOfNonDefaultValuatedEdges(const Graph *=nullptr) const override
Returns the number of edges with a non default value.
Definition: AbstractProperty.cxx:483
tlp::AbstractProperty::writeEdgeDefaultValue
void writeEdgeDefaultValue(std::ostream &) const override
Writes the edges default value.
Definition: AbstractProperty.cxx:497
tlp::Graph::edges
virtual const std::vector< edge > & edges() const =0
Return a const reference on the vector of edges of the graph It is the fastest way to access to edges...
tlp::Iterator::hasNext
virtual bool hasNext()=0
Tells if the sequence is at its end.
tlp::AbstractProperty::nodeValueSize
unsigned int nodeValueSize() const override
Returns the size in bytes of a node's value.
Definition: AbstractProperty.cxx:410
tlp::edge::isValid
bool isValid() const
isValid checks if the edge is valid. An invalid edge is an edge whose id is UINT_MAX.
Definition: Edge.h:92
tlp::edge
The edge struct represents an edge in a Graph object.
Definition: Edge.h:40
tlp::node
The node struct represents a node in a Graph object.
Definition: Node.h:40
tlp::AbstractProperty::readNodeDefaultValue
bool readNodeDefaultValue(std::istream &) override
Reads the nodes default value.
Definition: AbstractProperty.cxx:426
tlp::AbstractProperty::getNodeDefaultValue
Tnode::RealType getNodeDefaultValue() const
Gets the default node value of the property.
Definition: AbstractProperty.cxx:35
tlp::AbstractProperty::compare
int compare(const node n1, const node n2) const override
Compares the value this property holds for the two given nodes.
Definition: AbstractProperty.cxx:257
tlp::AbstractProperty::getNonDefaultValuatedNodes
tlp::Iterator< node > * getNonDefaultValuatedNodes(const Graph *g=nullptr) const override
Gets an Iterator on all non-default valuated nodes. When given a Graph as parameter,...
Definition: AbstractProperty.cxx:367
tlp::AbstractProperty::getNonDefaultValuatedEdges
tlp::Iterator< edge > * getNonDefaultValuatedEdges(const Graph *g=nullptr) const override
Gets an Iterator on all non-default valuated edges. When given a Graph as parameter,...
Definition: AbstractProperty.cxx:449