Tulip  6.0.0
Large graphs analysis and drawing
AbstractProperty.h
1 /*
2  *
3  * This file is part of Tulip (https://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 
20 #ifndef ABSTRACT_PROPERTY_H
21 #define ABSTRACT_PROPERTY_H
22 
23 #include <typeinfo>
24 #include <string>
25 #include <cstdlib>
26 #include <tulip/tulipconf.h>
27 #include <tulip/StoredType.h>
28 #include <tulip/MutableContainer.h>
29 #include <tulip/PropertyInterface.h>
30 #include <tulip/Iterator.h>
31 #include <tulip/DataSet.h>
32 #include <tulip/Graph.h>
33 
34 namespace tlp {
35 
36 class GraphView;
37 
38 //==============================================================
39 
40 /**
41  * @ingroup Graph
42  * @brief This class extends upon PropertyInterface, and adds type-safe methods to
43  * get and set the node and edge values, through the magic of template programming.
44  *
45  * Nodes and Edges can have different types (e.g. tlp::LayoutProperty has tlp::PointType as node
46  * type and tlp::LineType as edge type),
47  * but most of the time they have the same type (e.g. tlp::DoubleProperty, tlp::IntegerProperty).
48  *
49  * Some of the pure virtual functions of PropertyInterface are implemented in this class (e.g.
50  * erase()).
51  *
52  * The actual data is stored in this class, and it manages the default values.
53  */
54 template <class Tnode, class Tedge, class Tprop = PropertyInterface>
55 class TLP_SCOPE AbstractProperty : public Tprop {
56  friend class Graph;
57  friend class GraphView;
58 
59 public:
60  AbstractProperty(Graph *, const std::string &n = "");
61 
62  /**
63  * @brief Gets the default node value of the property.
64  * @return The default value of nodes.
65  */
66  typename Tnode::RealType getNodeDefaultValue() const;
67 
68  /**
69  * @brief Gets the default edge value of the property.
70  * @return The default value of edges.
71  **/
72  typename Tedge::RealType getEdgeDefaultValue() const;
73 
74  /**
75  * @brief Returns the value associated with the node n in this property.
76  * If there is no value, it returns the default node value.
77  *
78  * @param n The node for which we want to get the value of the property.
79  * @return :StoredType< Tnode::RealType >::ReturnedConstValue The value of the property for this
80  *node.
81  **/
82  typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue
83  getNodeValue(const node n) const;
84 
85  /**
86  * @brief overloading of operator[] to get a node value
87  **/
88  const typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue
89  operator[](node n) const {
90  return getNodeValue(n);
91  }
92 
93  /**
94  * @brief Returns the value associated to the edge e in this property.
95  * If there is no value, it returns the default edge value.
96  *
97  * @param e The edge for which we want to get the value of the property.
98  * @return :StoredType< Tedge::RealType >::ReturnedConstValue The value of the property for this
99  *edge.
100  **/
101  typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue
102  getEdgeValue(const edge e) const;
103 
104  /**
105  * @brief overloading of operator[] to get an edge value
106  **/
107  typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue operator[](edge e) const {
108  return getEdgeValue(e);
109  }
110 
111  /**
112  * Returns an iterator through all nodes belonging to g
113  * whose associated value is equal to val.
114  * If g is nullptr, the graph given when creating the property is considered.
115  */
116  virtual tlp::Iterator<node> *
117  getNodesEqualTo(typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
118  const Graph *g = nullptr) const;
119 
120  /**
121  * Returns an iterator through all edges belonging to g
122  * whose associated value is equal to val.
123  * If g is nullptr, the graph given when creating the property is considered.
124  */
125  virtual tlp::Iterator<edge> *
126  getEdgesEqualTo(typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
127  const Graph *g = nullptr) const;
128 
129  /**
130  * @brief Sets the value of a node and notify the observers of a modification.
131  *
132  * @param n The node to set the value of.
133  * @param v The value to affect for this node.
134  **/
135  virtual void
136  setNodeValue(const node n,
137  typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
138 
139  /**
140  * @brief inner class used to overload the operator[] to set a node value
141  **/
142  class nodeValueRef {
143  protected:
144  AbstractProperty *_prop;
145  node _n;
146 
147  public:
148  constexpr nodeValueRef(AbstractProperty *prop, node n) : _prop(prop), _n(n) {}
149 
150  typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue getValue() const {
151  return _prop->getNodeValue(_n);
152  }
153 
154  /**
155  * @brief overloading of operator= to assign a node value
156  * which allow to write: prop[n] = val
157  **/
158  nodeValueRef &
159  operator=(typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue val) noexcept {
160  _prop->setNodeValue(_n, val);
161  return *this;
162  }
163 
164  /**
165  * @brief overloading of operator= to assign a node value
166  * which allow to write: prop1[n] = prop2[m]
167  **/
168  nodeValueRef &operator=(const nodeValueRef &ref) noexcept {
169  _prop->setNodeValue(_n, ref.getValue());
170  return *this;
171  }
172 
173  /**
174  * @brief overloading of value type conversion operator
175  * which allow to write: if (prop[n])
176  **/
177  operator typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue() {
178  return getValue();
179  }
180  };
181 
182  /**
183  * @brief overloading of operator[] to set a node value
184  **/
185  constexpr nodeValueRef operator[](node n) {
186  return nodeValueRef(this, n);
187  }
188 
189  /**
190  * @brief Set the value of an edge and notify the observers of a modification.
191  *
192  * @param e The edge to set the value of.
193  * @param v The value to affect for this edge.
194  **/
195  virtual void
196  setEdgeValue(const edge e,
197  typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
198 
199  /**
200  * @brief inner class used to overload the operator[] to set an edge value
201  **/
202  class edgeValueRef {
203  protected:
204  AbstractProperty *_prop;
205  edge _e;
206 
207  public:
208  constexpr edgeValueRef(AbstractProperty *prop, edge e) : _prop(prop), _e(e) {}
209 
210  typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue getValue() const {
211  return _prop->getEdgeValue(_e);
212  }
213 
214  /**
215  * @brief overloading of operator= to assign an edge value
216  * which allow to write: prop[n] = val
217  **/
218  edgeValueRef &
219  operator=(typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue val) noexcept {
220  _prop->setEdgeValue(_e, val);
221  return *this;
222  }
223 
224  /**
225  * @brief overloading of operator= to assign an edge value
226  * which allow to write: prop1[e1] = prop2[e2]
227  **/
228  edgeValueRef &operator=(const edgeValueRef &ref) noexcept {
229  _prop->setEdgeValue(_e, ref.getValue());
230  return *this;
231  }
232 
233  /**
234  * @brief overloading of value type conversion operator
235  * which allow to write: if (prop[e])
236  **/
237  operator typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue() {
238  return getValue();
239  }
240  };
241 
242  /**
243  * @brief overloading of operator[] to set an edge value
244  **/
245  constexpr edgeValueRef operator[](edge e) {
246  return edgeValueRef(this, e);
247  }
248 
249  /**
250  * @brief Sets the value of all nodes and notify the observers.
251  * All previous values are lost and the given value is assigned as the default one to the future
252  *added nodes.
253  *
254  * @param v The value to set to all nodes.
255  *
256  **/
257  virtual void
258  setAllNodeValue(typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
259 
260  /**
261  * @brief Sets the value assigned as the default one to the future added nodes.
262  *
263  * @since Tulip 5.0
264  *
265  * @param v the new value to set on future added nodes.
266  *
267  * @return Whether the given string was a correct representation for this property's type. If not,
268  * the default value is not set.
269  */
270  virtual void
271  setNodeDefaultValue(typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
272 
273  /**
274  * @brief Sets the value of all nodes in a graph and notify the observers.
275  * Only the nodes from that graph will have their value modified in the property
276  * and the default node value will not be modified.
277  *
278  * @since Tulip 5.0
279  *
280  * @param v The value to set to all nodes.
281  * @param graph A graph that defines the set of nodes
282  *
283  *
284  * @warning If the provided graph is not a descendant of the one associated to that property
285  *(including itself),
286  * no node value will be modified.
287  *
288  **/
289  virtual void
290  setValueToGraphNodes(typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
291  const Graph *graph);
292 
293  /**
294  * @brief Sets the value assigned as the default one to the future added edges.
295  *
296  * @since Tulip 5.0
297  *
298  * @param value the new value to set on future added edges.
299  *
300  * @return Whether the given string was a correct representation for this property's type. If not,
301  * the default value is not set.
302  */
303  virtual void
304  setEdgeDefaultValue(typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
305 
306  /**
307  * @brief Sets the value of all edges and notify the observers.
308  * All previous values are lost and the given value is assigned as the default one to the future
309  *added edges.
310  *
311  * @param v The value to set to all edges.
312  *
313  **/
314  virtual void
315  setAllEdgeValue(typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
316 
317  /**
318  * @brief Sets the value of all edges in a graph and notify the observers.
319  * Only the edges from that graph will have their value modified in the property
320  * and the default edge value will not be modified.
321  *
322  * @since Tulip 5.0
323  *
324  * @param v The value to set to all edges.
325  * @param graph A graph on which to modify
326  *
327  *
328  * @warning If the provided graph is not a descendant of the one associated to that property
329  *(including itself),
330  * no edge value will be modified.
331  *
332  **/
333  virtual void
334  setValueToGraphEdges(typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
335  const Graph *graph);
336  //=================================================================================
337 
338  /**
339  * @brief Resets the value of a node to the default value.
340  *
341  * @param n The node to reset the value of.
342  *
343  **/
344  inline void erase(const node n) override {
345  setNodeValue(n, nodeDefaultValue);
346  }
347  //=================================================================================
348 
349  /**
350  * @brief Resets the value of an edge to the default value.
351  *
352  * @param e The edge to reset the value of.
353  *
354  **/
355  inline void erase(const edge e) override {
356  setEdgeValue(e, edgeDefaultValue);
357  }
358  //=================================================================================
359  /**
360  * @brief This operator overload allows to copy a property using the following syntax :
361  *
362  * @code
363  * IntegerProperty* shape = graph->getProperty<IntegerProperty>("viewShape");
364  * IntegerProperty* backup = graph->getProperty<IntegerProperty>("shapeBackup");
365  * *backup = *shape; // all the values from 'shape' will be copied into 'backup'.
366  * @endcode
367  * @param prop The property to copy the values from.
368  * @return This property with the values copied.
369  */
372  if (this != &prop) {
373  if (Tprop::graph == nullptr)
374  Tprop::graph = prop.Tprop::graph;
375 
376  if (Tprop::graph == prop.Tprop::graph) {
377  setAllNodeValue(prop.getNodeDefaultValue());
378  setAllEdgeValue(prop.getEdgeDefaultValue());
379 
380  for (auto itn : prop.getNonDefaultValuatedNodes()) {
381  setNodeValue(itn, prop.getNodeValue(itn));
382  }
383 
384  for (auto ite : prop.getNonDefaultValuatedEdges()) {
385  setEdgeValue(ite, prop.getEdgeValue(ite));
386  }
387 
388  } else {
389  //==============================================================*
390  for (auto n : Tprop::graph->nodes()) {
391  if (prop.Tprop::graph->isElement(n))
392  setNodeValue(n, prop.getNodeValue(n));
393  }
394 
395  for (auto e : Tprop::graph->edges()) {
396  if (prop.Tprop::graph->isElement(e))
397  setEdgeValue(e, prop.getEdgeValue(e));
398  }
399  }
400 
401  clone_handler(prop);
402  }
403 
404  return *this;
405  }
406  //=================================================================================
407  // Untyped accessors inherited from PropertyInterface, documentation is inherited
408  std::string getNodeDefaultStringValue() const override {
409  typename Tnode::RealType v = getNodeDefaultValue();
410  return Tnode::toString(v);
411  }
412  std::string getEdgeDefaultStringValue() const override {
413  typename Tedge::RealType v = getEdgeDefaultValue();
414  return Tedge::toString(v);
415  }
416  std::string getNodeStringValue(const node n) const override {
417  typename Tnode::RealType v = getNodeValue(n);
418  return Tnode::toString(v);
419  }
420  std::string getEdgeStringValue(const edge e) const override {
421  typename Tedge::RealType v = getEdgeValue(e);
422  return Tedge::toString(v);
423  }
424  bool setNodeStringValue(const node inN, const std::string &inV) override {
425  typename Tnode::RealType v;
426 
427  if (!Tnode::fromString(v, inV))
428  return false;
429 
430  setNodeValue(inN, v);
431  return true;
432  }
433  bool setEdgeStringValue(const edge inE, const std::string &inV) override {
434  typename Tedge::RealType v;
435 
436  if (!Tedge::fromString(v, inV))
437  return false;
438 
439  setEdgeValue(inE, v);
440  return true;
441  }
442  bool setNodeDefaultStringValue(const std::string &inV) override {
443  typename Tnode::RealType v;
444 
445  if (!Tnode::fromString(v, inV))
446  return false;
447 
448  setNodeDefaultValue(v);
449  return true;
450  }
451  bool setAllNodeStringValue(const std::string &inV) override {
452  typename Tnode::RealType v;
453 
454  if (!Tnode::fromString(v, inV))
455  return false;
456 
457  setAllNodeValue(v);
458  return true;
459  }
460  bool setStringValueToGraphNodes(const std::string &inV, const Graph *graph) override {
461  typename Tnode::RealType v;
462 
463  if (!Tnode::fromString(v, inV))
464  return false;
465 
466  setValueToGraphNodes(v, graph);
467  return true;
468  }
469  bool setEdgeDefaultStringValue(const std::string &inV) override {
470  typename Tedge::RealType v;
471 
472  if (!Tedge::fromString(v, inV))
473  return false;
474 
475  setEdgeDefaultValue(v);
476  return true;
477  }
478  bool setAllEdgeStringValue(const std::string &inV) override {
479  typename Tedge::RealType v;
480 
481  if (!Tedge::fromString(v, inV))
482  return false;
483 
484  setAllEdgeValue(v);
485  return true;
486  }
487  bool setStringValueToGraphEdges(const std::string &inV, const Graph *graph) override {
488  typename Tedge::RealType v;
489 
490  if (!Tedge::fromString(v, inV))
491  return false;
492 
493  setValueToGraphEdges(v, graph);
494  return true;
495  }
496  tlp::Iterator<node> *getNonDefaultValuatedNodes(const Graph *g = nullptr) const override;
497  bool hasNonDefaultValuatedNodes(const Graph *g = nullptr) const override;
498  unsigned int numberOfNonDefaultValuatedNodes(const Graph *g = nullptr) const override;
499  unsigned int nodeValueSize() const override;
500  void writeNodeDefaultValue(std::ostream &) const override;
501  void writeNodeValue(std::ostream &, node) const override;
502  bool readNodeDefaultValue(std::istream &) override;
503  bool readNodeValue(std::istream &, node) override;
504  tlp::Iterator<edge> *getNonDefaultValuatedEdges(const Graph *g = nullptr) const override;
505  bool hasNonDefaultValuatedEdges(const Graph *g = nullptr) const override;
506  unsigned int numberOfNonDefaultValuatedEdges(const Graph * = nullptr) const override;
507  unsigned int edgeValueSize() const override;
508  void writeEdgeDefaultValue(std::ostream &) const override;
509  void writeEdgeValue(std::ostream &, edge) const override;
510  bool readEdgeDefaultValue(std::istream &) override;
511  bool readEdgeValue(std::istream &, edge) override;
512  bool copy(const node destination, const node source, PropertyInterface *property,
513  bool ifNotDefault = false) override {
514  if (property == nullptr)
515  return false;
516 
518  dynamic_cast<tlp::AbstractProperty<Tnode, Tedge, Tprop> *>(property);
519  assert(tp);
520  bool notDefault;
521  typename StoredType<typename Tnode::RealType>::ReturnedValue value =
522  tp->nodeProperties.get(source.id, notDefault);
523 
524  if (ifNotDefault && !notDefault)
525  return false;
526 
527  setNodeValue(destination, value);
528  return true;
529  }
530  bool copy(const edge destination, const edge source, PropertyInterface *property,
531  bool ifNotDefault = false) override {
532  if (property == nullptr)
533  return false;
534 
536  dynamic_cast<tlp::AbstractProperty<Tnode, Tedge, Tprop> *>(property);
537  assert(tp);
538  bool notDefault;
539  typename StoredType<typename Tedge::RealType>::ReturnedValue value =
540  tp->edgeProperties.get(source.id, notDefault);
541 
542  if (ifNotDefault && !notDefault)
543  return false;
544 
545  setEdgeValue(destination, value);
546  return true;
547  }
548  void copy(PropertyInterface *property) override {
550  dynamic_cast<typename tlp::AbstractProperty<Tnode, Tedge, Tprop> *>(property);
551  assert(prop != nullptr);
552  *this = *prop;
553  }
554  // for performance reason and use in GraphUpdatesRecorder
555  DataMem *getNodeDefaultDataMemValue() const override {
556  return new TypedValueContainer<typename Tnode::RealType>(getNodeDefaultValue());
557  }
558  DataMem *getEdgeDefaultDataMemValue() const override {
559  return new TypedValueContainer<typename Tedge::RealType>(getEdgeDefaultValue());
560  }
561  DataMem *getNodeDataMemValue(const node n) const override {
562  return new TypedValueContainer<typename Tnode::RealType>(getNodeValue(n));
563  }
564  DataMem *getEdgeDataMemValue(const edge e) const override {
565  return new TypedValueContainer<typename Tedge::RealType>(getEdgeValue(e));
566  }
567  DataMem *getNonDefaultDataMemValue(const node n) const override {
568  bool notDefault;
569  typename StoredType<typename Tnode::RealType>::ReturnedValue value =
570  nodeProperties.get(n.id, notDefault);
571 
572  if (notDefault)
573  return new TypedValueContainer<typename Tnode::RealType>(value);
574 
575  return nullptr;
576  }
577  DataMem *getNonDefaultDataMemValue(const edge e) const override {
578  bool notDefault;
579  typename StoredType<typename Tedge::RealType>::ReturnedValue value =
580  edgeProperties.get(e.id, notDefault);
581 
582  if (notDefault)
583  return new TypedValueContainer<typename Tedge::RealType>(value);
584 
585  return nullptr;
586  }
587  void setNodeDataMemValue(const node n, const DataMem *v) override {
588  setNodeValue(n, static_cast<const TypedValueContainer<typename Tnode::RealType> *>(v)->value);
589  }
590  void setEdgeDataMemValue(const edge e, const DataMem *v) override {
591  setEdgeValue(e, static_cast<const TypedValueContainer<typename Tedge::RealType> *>(v)->value);
592  }
593  void setAllNodeDataMemValue(const DataMem *v) override {
594  setAllNodeValue(static_cast<const TypedValueContainer<typename Tnode::RealType> *>(v)->value);
595  }
596  void setAllEdgeDataMemValue(const DataMem *v) override {
597  setAllEdgeValue(static_cast<const TypedValueContainer<typename Tedge::RealType> *>(v)->value);
598  }
599 
600  // PropertyInterface methods
601  // mN is the meta node, sg is the corresponding subgraph
602  // and mg is the graph owning mN
603  void computeMetaValue(node n, Graph *sg, Graph *mg) override {
604  if (Tprop::metaValueCalculator)
606  Tprop::metaValueCalculator)
607  ->computeMetaValue(this, n, sg, mg);
608  }
609  // mE is the meta edge, itE is an iterator on the underlying edges
610  // mg is the graph owning mE
611  void computeMetaValue(edge e, tlp::Iterator<edge> *itE, Graph *mg) override {
612  if (Tprop::metaValueCalculator)
614  Tprop::metaValueCalculator)
615  ->computeMetaValue(this, e, itE, mg);
616  }
618  if (mvCalc &&
620  mvCalc)) {
621  tlp::warning()
622  << "Warning : " << __PRETTY_FUNCTION__ << " ... invalid conversion of "
623  << typeid(mvCalc).name() << "into "
625  .name()
626  << std::endl;
627  abort();
628  }
629 
630  Tprop::metaValueCalculator = mvCalc;
631  }
632 
633  int compare(const node n1, const node n2) const override;
634  int compare(const edge e1, const edge e2) const override;
635 
636  /**
637  * @brief This class is used to delegate the computation of the values associated to meta nodes or
638  *edges.
639  **/
641  public:
642  // computes the value of the meta node mN of the graph mg
643  // for the property prop, according to the values associated
644  // to the underlying nodes i.e the nodes of the subgraph sg.
645  virtual void computeMetaValue(AbstractProperty<Tnode, Tedge, Tprop> *, node, Graph *, Graph *) {
646  }
647  // computes the value of the meta node mE of the graph mg
648  // for the property prop, according to the values associated
649  // to the underlying edges given by the iterator itE.
650  // The method do not have to delete the iterator
651  virtual void computeMetaValue(AbstractProperty<Tnode, Tedge, Tprop> *, edge,
652  tlp::Iterator<edge> *, Graph *) {}
653  };
654 
655 protected:
656  //=================================================================================
657  /// Enable to clone part of sub_class
659 
660  MutableContainer<typename Tnode::RealType> nodeProperties;
661  MutableContainer<typename Tedge::RealType> edgeProperties;
662  typename Tnode::RealType nodeDefaultValue;
663  typename Tedge::RealType edgeDefaultValue;
664 };
665 
666 template <typename vectType, typename eltType, typename propType = VectorPropertyInterface>
667 class TLP_SCOPE AbstractVectorProperty : public AbstractProperty<vectType, vectType, propType> {
668 public:
669  AbstractVectorProperty(Graph *, const std::string &name = "");
670  using AbstractProperty<vectType, vectType, propType>::operator=;
671 
672  // 5 methods inherited from VectorPropertyInterface
673  bool tokenize(const std::string &str, std::vector<std::string> &vect, char openChar = '(',
674  char sepChar = ',', char closeChar = ')') override;
675 
676  bool setNodeStringValueAsVector(const node n, const std::vector<std::string> &values) override;
677 
678  bool setNodeStringValueAsVector(const node, const std::string &, char, char, char) override;
679 
680  bool setEdgeStringValueAsVector(const edge e, const std::vector<std::string> &values) override;
681 
682  bool setEdgeStringValueAsVector(const edge, const std::string &, char, char, char) override;
683 
684  /**
685  * @brief Sets the value for node n, at index i, to v, and notify the observers of a modification.
686  *
687  * @param n The node to set a value of.
688  * @param i The index at which the value should be set.
689  * @param v The value to set.
690  *
691  **/
692  void setNodeEltValue(const node n, unsigned int i,
693  typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
694  /**
695  * @brief Gets the value associated to node n, at index i.
696  *
697  * @param n The node to set a value of.
698  * @param i The index at which to set the value.
699  * @return const eltType& The value at index i in the vector for node n.
700  **/
701  typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
702  getNodeEltValue(const node n, unsigned int i) const;
703  /**
704  * @brief Appends a new value at the end of the vector associated to node n, and notify the
705  *observers of a modification.
706  *
707  * @param n The node to add a value to.
708  * @param v The value to append at the end of the vector.
709  *
710  **/
711  void
712  pushBackNodeEltValue(const node n,
713  typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
714  /**
715  * @brief Removes the value at the end of the vector associated to node n, and notify the
716  *observers of a modification.
717  *
718  * @param n The node to remove a value from.
719  *
720  **/
721  void popBackNodeEltValue(const node n);
722  /**
723  * @brief Resizes the vector associated to node n, and notify the observers of a modification.
724  *
725  * @param n The node associated to the vector to resize.
726  * @param size The new size of the vector.
727  * @param elt The default value to set at indices where there was no value before. Defaults to
728  *eltType().
729  *
730  **/
731  void resizeNodeValue(const node n, size_t size,
732  typename eltType::RealType elt = eltType::defaultValue());
733  /**
734  * @brief Sets the value for edge e, at index i, to v, and notify the observers of a modification.
735  *
736  * @param e The edge to set the value of.
737  * @param i The index at which the value should be set.
738  * @param v The value to set.
739  *
740  **/
741  void setEdgeEltValue(const edge e, unsigned int i,
742  typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
743  /**
744  * @brief Gets the value associated to edge e, at index i.
745  *
746  * @param e The edge to set a value of.
747  * @param i The index at which to set the value.
748  * @return const eltType& The value at index i in the vector for node n.
749  **/
750  typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
751  getEdgeEltValue(const edge n, unsigned int i) const;
752  /**
753  * @brief Appends a new value at the end of the vector associated to edge e, and notify the
754  *observers of a modification.
755  *
756  * @param e The node to add a value to.
757  * @param v The value to append at the end of the vector.
758  *
759  **/
760  void
761  pushBackEdgeEltValue(const edge e,
762  typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
763  /**
764  * @brief Removes the value at the end of the vector associated to edge e, and notify the
765  *observers of a modification.
766  *
767  * @param e The edge to remove a value from.
768  *
769  **/
770  void popBackEdgeEltValue(const edge e);
771  /**
772  * @brief Resizes the vector associated to edge e, and notify the observers of a modification.
773  *
774  * @param e The edge associated to the vector to resize.
775  * @param size The new size of the vector.
776  * @param elt The default value to set at indices where there was no value before. Defaults to
777  *eltType().
778  *
779  **/
780  void resizeEdgeValue(const edge e, size_t size,
781  typename eltType::RealType elt = eltType::defaultValue());
782 };
783 } // namespace tlp
784 #if !defined(_MSC_VER) || defined(DLL_TULIP) // When using VC++, we only want to include this when
785  // we are in the TULIP dll. With any other compiler,
786  // include it all the time
787 #include "cxx/AbstractProperty.cxx"
788 #endif
789 #endif
This class is used to delegate the computation of the values associated to meta nodes or edges.
inner class used to overload the operator[] to set an edge value
edgeValueRef & operator=(const edgeValueRef &ref) noexcept
overloading of operator= to assign an edge value which allow to write: prop1[e1] = prop2[e2]
edgeValueRef & operator=(typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue val) noexcept
overloading of operator= to assign an edge value which allow to write: prop[n] = val
inner class used to overload the operator[] to set a node value
nodeValueRef & operator=(typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue val) noexcept
overloading of operator= to assign a node value which allow to write: prop[n] = val
nodeValueRef & operator=(const nodeValueRef &ref) noexcept
overloading of operator= to assign a node value which allow to write: prop1[n] = prop2[m]
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
void erase(const edge e) override
Resets the value of an edge to the default value.
virtual void clone_handler(AbstractProperty< Tnode, Tedge, Tprop > &)
Enable to clone part of sub_class.
bool setNodeStringValue(const node inN, const std::string &inV) override
Sets a new value on the node, represented by the string parameter.
void setNodeDataMemValue(const node n, const DataMem *v) override
Sets the node value.
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.
bool setStringValueToGraphNodes(const std::string &inV, const Graph *graph) override
Sets all the nodes value to the value represented by the string for a graph. For some types,...
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,...
void setMetaValueCalculator(PropertyInterface::MetaValueCalculator *mvCalc) override
Sets the Calculator for meta nodes and edges.
constexpr nodeValueRef operator[](node n)
overloading of operator[] to set a node value
bool setAllNodeStringValue(const std::string &inV) override
Sets all the nodes value to the value represented by the string. For some types, some parsing will be...
void setEdgeDataMemValue(const edge e, const DataMem *v) override
Sets the edge value.
bool setStringValueToGraphEdges(const std::string &inV, const Graph *graph) override
Sets all the edges value to the value represented by the string for a graph. For some types,...
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,...
virtual AbstractProperty< Tnode, Tedge, Tprop > & operator=(AbstractProperty< Tnode, Tedge, Tprop > &prop)
This operator overload allows to copy a property using the following syntax :
DataMem * getNodeDefaultDataMemValue() const override
Gets a pointer to the tlp::DataMem structure that contains the node default value.
bool setEdgeStringValue(const edge inE, const std::string &inV) override
Sets a new value on the edge, represented by the string parameter.
void setAllNodeDataMemValue(const DataMem *v) override
Sets all the nodes value to the value contained in the given DataMem structure. All previous values a...
void computeMetaValue(node n, Graph *sg, Graph *mg) override
Sets the value of the metanode to a computed value.
bool setAllEdgeStringValue(const std::string &inV) override
Sets all the edges value to the value represented by the string. For some types, some parsing will be...
bool setNodeDefaultStringValue(const std::string &inV) override
Sets the value assigned as the default one to the future added nodes from a string representation.
std::string getNodeDefaultStringValue() const override
Gets a string representation of the node default value.
DataMem * getEdgeDataMemValue(const edge e) const override
Gets the edge value, contained in a tlp::DataMem structure.
void setAllEdgeDataMemValue(const DataMem *v) override
Sets all the edges value to the value contained in the given DataMem structure. All previous values a...
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,...
bool setEdgeDefaultStringValue(const std::string &inV) override
Sets the value assigned as the default one to the future added edges from a string representation.
std::string getNodeStringValue(const node n) const override
Gets a string representation of the node value.
Tnode::RealType getNodeDefaultValue() const
Gets the default node value of the property.
void erase(const node n) override
Resets the value of a node to the default value.
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.
bool copy(const edge destination, const edge source, PropertyInterface *property, bool ifNotDefault=false) override
Copies the value of an edge in another property to an edge in this property.
void computeMetaValue(edge e, tlp::Iterator< edge > *itE, Graph *mg) override
Sets the value of the metaedge to a computed value.
std::string getEdgeStringValue(const edge e) const override
Gets a string representation of the edge value.
DataMem * getNonDefaultDataMemValue(const node n) const override
Returns the value in a DataMem if it is not default, otherwise returns nullptr.
const tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue operator[](node n) const
overloading of operator[] to get a node value
bool copy(const node destination, const node source, PropertyInterface *property, bool ifNotDefault=false) override
Copies the value of a node in another property to a node in this property.
Tedge::RealType getEdgeDefaultValue() const
Gets the default edge value of the property.
tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue operator[](edge e) const
overloading of operator[] to get an edge value
void copy(PropertyInterface *property) override
Copies the values of the source property to this property.
constexpr edgeValueRef operator[](edge e)
overloading of operator[] to set an edge value
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,...
DataMem * getNodeDataMemValue(const node n) const override
Gets the node value, contained in a tlp::DataMem structure.
DataMem * getEdgeDefaultDataMemValue() const override
Gets a pointer to the tlp::DataMem structure that contains the edge default value.
std::string getEdgeDefaultStringValue() const override
Gets a string representation of the edge default value.
DataMem * getNonDefaultDataMemValue(const edge e) const override
Returns the value in a DataMem if it is not default, otherwise returns nullptr.
Base class for computing values on meta nodes and edges.
PropertyInterface describes the interface of a graph property.
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Iterator.h:74
The edge struct represents an edge in a Graph object.
Definition: Edge.h:40
unsigned int id
id The identifier of the edge.
Definition: Edge.h:44
The node struct represents a node in a Graph object.
Definition: Node.h:40
unsigned int id
id The identifier of the node.
Definition: Node.h:44