Tulip  6.0.0
Large graphs analysis and drawing
PropertyInterface.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 PROPERTY_INTERFACE_H
21 #define PROPERTY_INTERFACE_H
22 
23 #include <string>
24 #include <iostream>
25 #include <functional>
26 
27 #include <tulip/tulipconf.h>
28 #include <tulip/Observable.h>
29 #include <tulip/Edge.h>
30 #include <tulip/TlpTools.h>
31 
32 namespace tlp {
33 
34 struct DataMem;
35 struct node;
36 
37 class Graph;
38 template <class itType>
39 struct Iterator;
40 
41 //=============================================================
42 /**
43  * @ingroup Graph
44  * @brief PropertyInterface describes the interface of a graph property.
45  *
46  * The intent of a property is to hold a value for each node and edge (e.g. the degree of the
47  * nodes).
48  *
49  * A property can be used in two different ways :
50  * Either it is attached to a graph; and in this case creating and deleting the property is handled
51  * by the graph
52  * (@see Graph::getProperty()).
53  *
54  * Either is is detached from a graph, and you have to handle creation and deletion yourself.
55  * This is most useful for some algorithms that need a temporary property, but do not want the
56  * property to appear on the graph
57  * after the computation.
58  */
59 class TLP_SCOPE PropertyInterface : public Observable {
60  friend class PropertyManager;
61 
62 protected:
63  // name of the property when registered as a property of a graph
64  std::string name;
65  // the graph for whom the property is registered
66  Graph *graph;
67 
68 public:
70 
71  ~PropertyInterface() override;
72 
73  /**
74  * @brief Erases the value stored for the given node.
75  * The new value for the node is the default value.
76  */
77  virtual void erase(const node) = 0;
78 
79  /**
80  * @brief Erases the value stored for the given edge.
81  * The new value for the edge is the default value.
82  */
83  virtual void erase(const edge) = 0;
84 
85  /**
86  * @brief Copies the value of a node in another property to a node in this property.
87  * @param destination The node whose value will be set.
88  * @param source The node whose value to copy.
89  * @param property The property from which to copy the source node value.
90  * @param ifNotDefault If true, the copy will only be performed if the source node's value is not
91  * the default value.
92  * @return True if the copy was performed, false otherwise.
93  */
94  virtual bool copy(const node destination, const node source, PropertyInterface *property,
95  bool ifNotDefault = false) = 0;
96  /**
97  * @brief Copies the value of an edge in another property to an edge in this property.
98  * @param destination The edge whose value will be set.
99  * @param source The edge whose value to copy.
100  * @param property The property from which to copy the source edge value.
101  * @param ifNotDefault If true, the copy will only be performed if the source edge's value is not
102  * the default value.
103  * @return True if the copy was performed, false otherwise.
104  */
105  virtual bool copy(const edge destination, const edge source, PropertyInterface *property,
106  bool ifNotDefault = false) = 0;
107 
108  /**
109  * @brief Copies the values of the source property to this property.
110  * @param source The property from which to copy values.
111  * @warning Be careful when using this method, if you are interested by observing the updates of
112  * the values of the current property, because no event is sent for nodes/edges whose value is the
113  * default value of the source property.
114  */
115  virtual void copy(PropertyInterface *source) = 0;
116 
117  /**
118  * @brief Creates a property of the same type (e.g. tlp::DoubleProperty) in the graph.
119  * The new property will not contain a copy of this property's values.
120  * @param graph The Graph in which to create the new property.
121  * @param name The name of the new property.
122  * @return The newly created property.
123  */
124  virtual PropertyInterface *clonePrototype(Graph *graph, const std::string &name) const = 0;
125 
126  /**
127  * @brief Gets a string describing the type of the property value (e.g. "graph", "double",
128  * "layout", "string", "integer", "color", "size").
129  * @return The name of this property's type.
130  */
131  virtual const std::string &getTypename() const = 0;
132 
133  /**
134  * @brief Gets a string giving the name of a the PropertyInterface subclass
135  * (e.g "tlp::BooleanProperty", "tlp::DoubleProperty", ...)
136  * @return The subclass name.
137  */
138  virtual const std::string &getCppClassName() const = 0;
139 
140 ///@cond DOXYGEN_HIDDEN
141 // the following macro gives a generic definition of getCppClassName()
142 // it is used when declaring PropertyInterface subclasses
143 #define DEFINE_GET_CPP_CLASS_NAME \
144  const std::string &getCppClassName() const override { \
145  static std::string className; \
146  if (className.empty()) { \
147  std::string dcn(demangleClassName(typeid(this).name(), false)); \
148  className = dcn.substr(0, dcn.find(' ')); \
149  } \
150  return className; \
151  }
152  ///@endcond
153 
154  /**
155  * @brief Gets the name of the property (e.g. viewLayout).
156  * @return The name of this property.
157  */
158  const std::string &getName() const {
159  return name;
160  }
161 
162  /**
163  * @brief Rename a property
164  * @param the new name
165  * @return returns true if the renaming succeeded.
166  * It may fails if a property with the given name already exists
167  */
168  bool rename(const std::string &newName);
169  /**
170  * @cond DOXYGEN_HIDDEN
171  * @brief Gets the graph on which this property has been defined.
172  * This is an internal function and its behavior can change.
173  * DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING.
174  *
175  * Be wary that is might be a different graph that the one you used to get this property.
176  * For instance:
177  * @code
178  * Graph* g = tlp::newGraph();
179  * Graph*sub = g->addCloneSubGraph();
180  *
181  * IntegerProperty* prop = g->getProperty<IntegerProperty>("test");
182  * //prop->getGraph() returns g
183  *
184  * IntegerProperty* prop2 = sub->getProperty<IntegerProperty>("test");
185  * //prop2->getGraph() returns g
186  * @endcode
187  *
188  * This is due to the inheritance system of the properties.
189  *
190  * @return The Graph this property is local to.
191  * @endcond
192  */
193  tlp::Graph *getGraph() const {
194  return graph;
195  }
196 
197  /**
198  * @brief Gets a string representation of the node value.
199  * @param n The node to get the value of.
200  * @return A string representation of the node value.
201  */
202  virtual std::string getNodeStringValue(const node n) const = 0;
203 
204  /**
205  * @brief Sets a new value on the node, represented by the string parameter.
206  * @param n The node on which to set the new value.
207  * @param value A string representing the value to set on the node.
208  * @return Whether the string was a correct representation for this property's type. If not, the
209  * value is not set.
210  */
211  virtual bool setNodeStringValue(const node n, const std::string &value) = 0;
212 
213  /**
214  * @brief inner class used to overload the operator[] to set a node string value
215  **/
217  protected:
218  PropertyInterface *_prop;
219  node _n;
220 
221  public:
222  constexpr nodeStringValueRef(PropertyInterface *prop, node n) : _prop(prop), _n(n) {}
223 
224  std::string getStringValue() const {
225  return _prop->getNodeStringValue(_n);
226  }
227 
228  /**
229  * @brief overloading of operator= to assign a node string value
230  * which allows to write: prop[n] = strval
231  **/
232  nodeStringValueRef &operator=(std::string val) noexcept {
233  _prop->setNodeStringValue(_n, val);
234  return *this;
235  }
236 
237  /**
238  * @brief overloading of operator= to assign a node string value
239  * which allows to write: prop1[n] = prop2[m]
240  **/
242  _prop->setNodeStringValue(_n, ref.getStringValue());
243  return *this;
244  }
245 
246  /**
247  * @brief overloading of operator==
248  * which allows to write: prop1[n] == prop2[m]
249  **/
250  bool operator==(std::string str) noexcept {
251  return _prop->getNodeStringValue(_n) == str;
252  }
253 
254  /**
255  * @brief overloading of std::string conversion operator
256  **/
257  operator std::string() {
258  return getStringValue();
259  }
260  };
261 
262  /**
263  * @brief overloading of operator[] to set a node string value
264  **/
266  return nodeStringValueRef(this, n);
267  }
268 
269  /**
270  * @brief Gets a string representation of the edge value.
271  * @param e The edge to get the value of.
272  * @return A string representation of the edge value.
273  */
274  virtual std::string getEdgeStringValue(const edge e) const = 0;
275 
276  /**
277  * @brief Sets a new value on the edge, represented by the string parameter.
278  * @param e The edge on which to set value on.
279  * @param value A string representing the value to set on the edge.
280  * @return Whether the string was a correct representation for this property's type. If not, the
281  * value is not set.
282  */
283  virtual bool setEdgeStringValue(const edge e, const std::string &value) = 0;
284 
285  /**
286  * @brief inner class used to overload the operator[] to set an edge string value
287  **/
289  protected:
290  PropertyInterface *_prop;
291  edge _e;
292 
293  public:
294  constexpr edgeStringValueRef(PropertyInterface *prop, edge e) : _prop(prop), _e(e) {}
295 
296  std::string getStringValue() const {
297  return _prop->getEdgeStringValue(_e);
298  }
299 
300  /**
301  * @brief overloading of operator= to assign a edge string value
302  * which allows to write: prop[e] = strval
303  **/
304  edgeStringValueRef &operator=(std::string val) noexcept {
305  _prop->setEdgeStringValue(_e, val);
306  return *this;
307  }
308 
309  /**
310  * @brief overloading of operator= to assign a edge string value
311  * which allows to write: prop1[e1] = prop2[e2]
312  **/
314  _prop->setEdgeStringValue(_e, ref.getStringValue());
315  return *this;
316  }
317 
318  /**
319  * @brief overloading of operator==
320  * which allows to write: prop1[e1] == prop2[e2]
321  **/
322  bool operator==(std::string str) noexcept {
323  return _prop->getEdgeStringValue(_e) == str;
324  }
325 
326  /**
327  * @brief overloading of std::string conversion operator
328  **/
329  operator std::string() {
330  return getStringValue();
331  }
332  };
333 
334  /**
335  * @brief overloading of operator[] to set a edge string value value
336  **/
338  return edgeStringValueRef(this, e);
339  }
340 
341  /**
342  * @brief overloading of operator[] to get the edge string value
343  **/
344  std::string operator[](edge e) const {
345  return getEdgeStringValue(e);
346  }
347 
348  /**
349  * @brief Gets a string representation of the node default value.
350  * @return A string representation of the node default value.
351  */
352  virtual std::string getNodeDefaultStringValue() const = 0;
353 
354  /**
355  * @brief Gets a string representation of the edge default value.
356  * @return A string representation of the edge default value.
357  */
358  virtual std::string getEdgeDefaultStringValue() const = 0;
359 
360  /**
361  * @brief Sets the value assigned as the default one to the future added nodes from a string
362  * representation.
363  *
364  * @since Tulip 5.0
365  *
366  * @param value A string representing the new value to set on future added nodes.
367  *
368  * @return Whether the given string was a correct representation for this property's type. If not,
369  * the default value is not set.
370  */
371  virtual bool setNodeDefaultStringValue(const std::string &value) = 0;
372 
373  /**
374  * @brief Sets all the nodes value to the value represented by the string. For some types, some
375  * parsing will be necessary (e.g. LayoutProperty).
376  * All previous values are lost and the represented value is assigned as the default one to the
377  * future added nodes.
378  *
379  * @param value A string representing the new value to set on all the nodes.
380  *
381  * @return Whether the given string was a correct representation for this property's type. If not,
382  * the values are not set.
383  */
384  virtual bool setAllNodeStringValue(const std::string &value) = 0;
385 
386  /**
387  * @brief Sets all the nodes value to the value represented by the string for a graph. For some
388  * types, some parsing will be necessary (e.g. LayoutProperty).
389  * Only the nodes from that graph will have their value modified in the property
390  * and the default node value will not be modified.
391  *
392  * @since Tulip 5.0
393  *
394  * @param value A string representing the new value to set on all the nodes.
395  * @param graph A graph that defines the set of nodes.
396  *
397  * @warning If the provided graph is not a descendant of the one associated to that property
398  * (including itself), no node value will be modified in it.
399  *
400  * @return Whether the given string was a correct representation for this property's type. If not,
401  * the values are not set.
402  */
403  virtual bool setStringValueToGraphNodes(const std::string &value, const Graph *graph) = 0;
404 
405  /**
406  * @brief Sets the value assigned as the default one to the future added edges from a string
407  * representation.
408  *
409  * @since Tulip 5.0
410  *
411  * @param value A string representing the new value to set on future added edges.
412  *
413  * @return Whether the given string was a correct representation for this property's type. If not,
414  * the default value is not set.
415  */
416  virtual bool setEdgeDefaultStringValue(const std::string &value) = 0;
417 
418  /**
419  * @brief Sets all the edges value to the value represented by the string. For some types, some
420  * parsing will be necessary (e.g. LayoutProperty).
421  * All previous values are lost and the represented value is assigned as the default one to the
422  * future added edges.
423  *
424  * @param value A string representing the new value to set on all the edges.
425  *
426  * @return Whether the given string was a correct representation for this property's type. If not,
427  * the values are not set.
428  */
429  virtual bool setAllEdgeStringValue(const std::string &value) = 0;
430 
431  /**
432  * @brief Sets all the edges value to the value represented by the string for a graph. For some
433  * types, some parsing will be necessary (e.g. LayoutProperty).
434  * Only the edges from that graph will have their value modified in the property
435  * and the default edge value will not be modified.
436  *
437  * @since Tulip 5.0
438  *
439  * @param value A string representing the new value to set on all the edges.
440  * @param graph A graph that defines the set of edges.
441  *
442  * @warning If the provided graph is not a descendant of the one associated to that property
443  * (including itself), no edge value will be modified in it.
444  *
445  * @return Whether the given string was a correct representation for this property's type. If not,
446  * the values are not set.
447  */
448  virtual bool setStringValueToGraphEdges(const std::string &value, const Graph *graph) = 0;
449 
450  /**
451  * @brief Gets a pointer to the tlp::DataMem structure that contains the node default value.
452  * @return The DataMem structure containing the node default value.
453  * @warning The ownership of this pointer is given to the caller.
454  */
455  virtual DataMem *getNodeDefaultDataMemValue() const = 0;
456 
457  /**
458  * @brief Gets a pointer to the tlp::DataMem structure that contains the edge default value.
459  * @return The DataMem structure containing the edge default value.
460  * @warning The ownership of this pointer is given to the caller.
461  */
462  virtual DataMem *getEdgeDefaultDataMemValue() const = 0;
463 
464  /**
465  * @brief Sets all the nodes value to the value contained in the given DataMem structure.
466  * All previous values are lost.
467  * @param value The value to set on all the nodes.
468  */
469  virtual void setAllNodeDataMemValue(const DataMem *value) = 0;
470 
471  /**
472  * @brief Sets all the edges value to the value contained in the given DataMem structure.
473  * All previous values are lost.
474  * @param value The value to set on all the edges.
475  */
476  virtual void setAllEdgeDataMemValue(const DataMem *v) = 0;
477 
478  /**
479  * @brief Gets the node value, contained in a tlp::DataMem structure.
480  * @param n The node to get the value of.
481  * @return The value of the node, in a tlp::DataMem.
482  *
483  * @warning The ownership of this pointer is given to the caller.
484  */
485  virtual DataMem *getNodeDataMemValue(const node n) const = 0;
486 
487  /**
488  * @brief Gets the edge value, contained in a tlp::DataMem structure.
489  * @param n The edge to get the value of.
490  * @return The value of the edge, in a tlp::DataMem.
491  *
492  * @warning The ownership of this pointer is given to the caller.
493  */
494  virtual DataMem *getEdgeDataMemValue(const edge e) const = 0;
495 
496  /**
497  * @brief Returns the value in a DataMem if it is not default, otherwise returns nullptr.
498  * @param n The node to get the value of.
499  * @return The value of the node if it is not default, or nullptr.
500  *
501  * @warning The ownership of this pointer is given to the caller.
502  */
503  virtual DataMem *getNonDefaultDataMemValue(const node n) const = 0;
504 
505  /**
506  * @brief Returns the value in a DataMem if it is not default, otherwise returns nullptr.
507  * @param e The edge to get the value of.
508  * @return The value of the edge if it is not default, or nullptr.
509  *
510  * @warning The ownership of this pointer is given to the caller.
511  */
512  virtual DataMem *getNonDefaultDataMemValue(const edge e) const = 0;
513 
514  /**
515  * @brief Sets the node value.
516  * @param n The node to set the value of.
517  * @param value The value to set to this node.
518  */
519  virtual void setNodeDataMemValue(const node n, const DataMem *value) = 0;
520 
521  /**
522  * @brief Sets the edge value.
523  * @param e The edge to set the value of.
524  * @param value The value to set to this edge.
525  */
526  virtual void setEdgeDataMemValue(const edge e, const DataMem *v) = 0;
527 
528  /**
529  * @brief Gets an Iterator on all non-default valuated nodes.
530  * When given a Graph as parameter, only nodes belonging to this graph are iterated over.
531  * @return An Iterator over nodes whose value is not default.
532  *
533  * @warning The ownership of the iterator is given to the caller.
534  */
535  virtual tlp::Iterator<node> *getNonDefaultValuatedNodes(const Graph * = nullptr) const = 0;
536 
537  /**
538  * @brief Returns whether the property has nodes with a non default value.
539  * When given a Graph as parameter, only the nodes with a non default value belonging to
540  * this graph are taken into account.
541  * @return false if all nodes has the default value, true if not.
542  *
543  */
544  virtual bool hasNonDefaultValuatedNodes(const Graph * = nullptr) const = 0;
545 
546  /**
547  * @brief Returns the number of nodes with a non default value.
548  * When given a Graph as parameter, only the number of nodes with a non default value belonging to
549  * this graph is returned.
550  * @return the number of nodes with a non default value.
551  *
552  */
553  virtual unsigned int numberOfNonDefaultValuatedNodes(const Graph * = nullptr) const = 0;
554 
555  /**
556  * @brief Gets an Iterator on all non-default valuated edges.
557  * When given a Graph as parameter, only edges belonging to this graph are iterated over.
558  * @return An Iterator over edges whose value is not default.
559  *
560  * @warning The ownership of the iterator is given to the caller.
561  */
562  virtual tlp::Iterator<edge> *getNonDefaultValuatedEdges(const Graph * = nullptr) const = 0;
563 
564  /**
565  * @brief Returns whether the property has edges with a non default value.
566  * When given a Graph as parameter, only the edges with a non default value belonging to
567  * this graph are taken into account.
568  * @return false if all edges has the default value, true if not.
569  *
570  */
571  virtual bool hasNonDefaultValuatedEdges(const Graph * = nullptr) const = 0;
572 
573  /**
574  * @brief Returns the number of edges with a non default value.
575  * @return the number of edges with a non default value.
576  *
577  */
578  virtual unsigned int numberOfNonDefaultValuatedEdges(const Graph * = nullptr) const = 0;
579 
580  /**
581  * @brief Returns the size in bytes of a node's value.
582  * @return the size of a node's value (0 means the size is not fixed)
583  *
584  */
585  virtual unsigned int nodeValueSize() const = 0;
586 
587  /**
588  * @brief Writes the nodes default value
589  *
590  */
591  virtual void writeNodeDefaultValue(std::ostream &) const = 0;
592 
593  /**
594  * @brief Writes the value of a node
595  *
596  */
597  virtual void writeNodeValue(std::ostream &, node) const = 0;
598 
599  /**
600  * @brief Reads the nodes default value
601  *
602  */
603  virtual bool readNodeDefaultValue(std::istream &) = 0;
604 
605  /**
606  * @brief Reads the value of a node
607  *
608  */
609  virtual bool readNodeValue(std::istream &, node) = 0;
610 
611  /**
612  * @brief Returns the size in bytes of an edge's value.
613  * @return the size of a node's value (0 means the size is not fixed)
614  *
615  */
616  virtual unsigned int edgeValueSize() const = 0;
617 
618  /**
619  * @brief Writes the edges default value
620  *
621  */
622  virtual void writeEdgeDefaultValue(std::ostream &) const = 0;
623 
624  /**
625  * @brief Writes the value of an edge
626  *
627  */
628  virtual void writeEdgeValue(std::ostream &, edge) const = 0;
629 
630  /**
631  * @brief Reads the edges default value
632  *
633  */
634  virtual bool readEdgeDefaultValue(std::istream &) = 0;
635 
636  /**
637  * @brief Reads the value of an edge
638  *
639  */
640  virtual bool readEdgeValue(std::istream &, edge) = 0;
641 
642  /**
643  * @brief Sets the value of the metanode to a computed value.
644  *
645  * The value is computed by this property's MetaValueCalculator.
646  * @param metaNode The metanode to compute a value on.
647  * @param subgraph The subgraph pointed by the metanode.
648  * @param metaGraph The graph who owns the meta node.
649  */
650  virtual void computeMetaValue(node metaNode, Graph *subgraph, Graph *metaGraph) = 0;
651 
652  /**
653  * @brief Sets the value of the metaedge to a computed value.
654  * @param metaEdge The meta edge to compute a value on.
655  * @param it The edges represented by the meta edge.
656  * @param metaGraph The graph who owns the meta edge.
657  */
658  virtual void computeMetaValue(edge metaEdge, tlp::Iterator<edge> *it, Graph *metaGraph) = 0;
659 
660  /**
661  * @brief Base class for computing values on meta nodes and edges.
662  */
664  public:
665  virtual ~MetaValueCalculator() {}
666  };
667 
668  /**
669  * @brief Gets the MetaValueCalculator of this property.
670  * @return The MetaValueCalculator of this property
671  */
673  return metaValueCalculator;
674  }
675 
676  /**
677  * @brief Sets the Calculator for meta nodes and edges.
678  * @param calculator The object containing the logic for computing the meta values for the nodes
679  * and edges.
680  *
681  * @warning The ownership of the MetaValueCalculator is not taken by the property.
682  */
683  virtual void setMetaValueCalculator(MetaValueCalculator *calculator) {
684  metaValueCalculator = calculator;
685  }
686 
687  /**
688  * @brief Compares the value this property holds for the two given nodes.
689  * @param n1 The first node to compare the value of.
690  * @param n2 The second node to compare the value of.
691  * @return 0 if the values are identical, a positive value if n1 is greater than n2, and a
692  * negative value if n1 is less than n2.
693  */
694  virtual int compare(const node n1, const node n2) const = 0;
695 
696  /**
697  * @brief Compares the value this property holds for the two given edges.
698  * @param e1 The first edge to compare the value of.
699  * @param e2 The second edge to compare the value of.
700  * @return 0 if the values are identical, a positive value if e1 is greater than e2, and a
701  * negative value if e1 is less than e2.
702  */
703  virtual int compare(const edge e1, const edge e2) const = 0;
704 
705 protected:
706  MetaValueCalculator *metaValueCalculator;
707 
708  // for notification of PropertyObserver
709  void notifyBeforeSetNodeValue(const node n);
710  void notifyAfterSetNodeValue(const node n);
711  void notifyBeforeSetEdgeValue(const edge e);
712  void notifyAfterSetEdgeValue(const edge e);
713  void notifyBeforeSetAllNodeValue();
714  void notifyAfterSetAllNodeValue();
715  void notifyBeforeSetAllEdgeValue();
716  void notifyAfterSetAllEdgeValue();
717  void notifyDestroy();
718  void notifyRename(const std::string &newName);
719 };
720 
721 /**
722  * @ingroup Graph
723  * @brief VectorPropertyInterface describes the interface of a graph property whose holded value is
724  * a vector (std::vector)
725  *
726  */
727 class TLP_SCOPE VectorPropertyInterface : public PropertyInterface {
728 public:
730 
731  ~VectorPropertyInterface() override {}
732 
733  /**
734  * @brief split an input string into a vector of strings
735  * @param str A string listing the elements of the vector to set on a node/edge.
736  * @param vect An output vector containing the string elements
737  * @param openChar an optional character opening the list of elements. Default value is '('; when
738  * set to '\0' it indicates that there is no opening character.
739  * @param sepChar an optional character separating the elements of the list. Default value is ','.
740  * @param closeChar an optional character closing the list of elements. Default value is ')'; when
741  * set to '\0' it indicates that there is no opening character.
742  * @return Whether the string was a correct representation for this property's type.
743  */
744  virtual bool tokenize(const std::string &str, std::vector<std::string> &vect, char openChar = '(',
745  char sepChar = ',', char closeChar = ')') = 0;
746 
747  /**
748  * @brief Sets a new vector represented by the vector of string parameter as the node value.
749  * @param n The node on which to set the new value.
750  * @param values A vector of strings listing the string representations of elements of the vector
751  * to set on the node.
752  * @return Whether the vector was a correct representation for this property's type. If not, the
753  * value is not set.
754  */
755  virtual bool setNodeStringValueAsVector(const node n, const std::vector<std::string> &values) = 0;
756 
757  /**
758  * @brief Sets a new vector represented by the vector of string parameter as the edge value.
759  * @param e The edge on which to set the new value.
760  * @param values A vector of strings listing the string representations of elements of the vector
761  * to set on the edge.
762  * @return Whether the vector was a correct representation for this property's type. If not, the
763  * value is not set.
764  */
765  virtual bool setEdgeStringValueAsVector(const edge e, const std::vector<std::string> &values) = 0;
766 
767  /**
768  * @brief Sets a new vector represented by the string parameter as the node value.
769  * @param n The node on which to set the new value.
770  * @param value A string listing the elements of the vector to set on the node.
771  * @param openChar an optional character opening the list of elements. Default value is '('; when
772  * set to '\0' it indicates that there is no opening character.
773  * @param sepChar an optional character separating the elements of the list. Default value is ','.
774  * @param closeChar an optional character closing the list of elements. Default value is ')'; when
775  * set to '\0' it indicates that there is no opening character.
776  * @return Whether the string was a correct representation for this property's type. If not, the
777  * value is not set.
778  */
779  virtual bool setNodeStringValueAsVector(const node n, const std::string &value,
780  char openChar = '(', char sepChar = ',',
781  char closeChar = ')') = 0;
782 
783  /**
784  * @brief Sets a new vector represented by the string parameter as the edge value.
785  * @param e The edge on which to set value on.
786  * @param value A string listing the elements of the vector to set on the edge.
787  * @param openChar an optional character opening the list of elements. Default value is '('; when
788  * set to '\0' it indicates that there is no opening character.
789  * @param sepChar an optional character separating the elements of the list. Default value is ','.
790  * @param closeChar an optional character closing the list of elements. Default value is ')'; when
791  * set to '\0' it indicates that there is no opening character.
792  * @return Whether the string was a correct representation for this property's type. If not, the
793  * value is not set.
794  */
795  virtual bool setEdgeStringValueAsVector(const edge e, const std::string &value,
796  char openChar = '(', char sepChar = ',',
797  char closeChar = ')') = 0;
798 };
799 
800 /**
801  * @ingroup Observation
802  * @brief Contains additional information about events on a property,
803  * such as the property it happened on, the node/edge eventually concerned and such.
804  * It also contains the detailed type of the event.
805  */
806 class TLP_SCOPE PropertyEvent : public Event {
807 public:
808  // be careful about the ordering of the constants
809  // in the enum below because it is used in some assertions
810  enum PropertyEventType {
811  TLP_BEFORE_SET_NODE_VALUE = 0,
812  TLP_AFTER_SET_NODE_VALUE,
813  TLP_BEFORE_SET_ALL_NODE_VALUE,
814  TLP_AFTER_SET_ALL_NODE_VALUE,
815  TLP_BEFORE_SET_ALL_EDGE_VALUE,
816  TLP_AFTER_SET_ALL_EDGE_VALUE,
817  TLP_BEFORE_SET_EDGE_VALUE,
818  TLP_AFTER_SET_EDGE_VALUE
819  };
820  PropertyEvent(const PropertyInterface &prop, PropertyEventType propEvtType,
821  Event::EventType evtType = Event::TLP_MODIFICATION, unsigned int id = UINT_MAX)
822  : Event(prop, evtType), evtType(propEvtType), eltId(id) {}
823 
824  PropertyInterface *getProperty() const {
825  return static_cast<PropertyInterface *>(sender());
826  }
827 
828  node getNode() const {
829  assert(evtType < TLP_BEFORE_SET_ALL_NODE_VALUE);
830  return node(eltId);
831  }
832 
833  edge getEdge() const {
834  assert(evtType > TLP_AFTER_SET_ALL_EDGE_VALUE);
835  return edge(eltId);
836  }
837 
838  PropertyEventType getType() const {
839  return evtType;
840  }
841 
842 protected:
843  PropertyEventType evtType;
844  unsigned int eltId;
845 };
846 } // namespace tlp
847 
848 //================================================================================
849 // these functions allow to use tlp::PropertyInterface as a key in a hash-based data structure (e.g.
850 // hashmap).
851 //================================================================================
852 
853 ///@cond DOXYGEN_HIDDEN
854 namespace std {
855 template <>
856 struct TLP_SCOPE hash<const tlp::PropertyInterface *> {
857  size_t operator()(const tlp::PropertyInterface *prop) const {
858  return size_t(prop);
859  }
860 };
861 template <>
862 struct TLP_SCOPE hash<tlp::PropertyInterface *> {
863  size_t operator()(tlp::PropertyInterface *prop) const {
864  return size_t(prop);
865  }
866 };
867 } // namespace std
868 ///@endcond
869 
870 #endif // PROPERTY_INTERFACE_H
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:52
The Observable class is the base of Tulip's observation system.
Definition: Observable.h:127
Contains additional information about events on a property, such as the property it happened on,...
Base class for computing values on meta nodes and edges.
inner class used to overload the operator[] to set an edge string value
edgeStringValueRef & operator=(const edgeStringValueRef &ref) noexcept
overloading of operator= to assign a edge string value which allows to write: prop1[e1] = prop2[e2]
edgeStringValueRef & operator=(std::string val) noexcept
overloading of operator= to assign a edge string value which allows to write: prop[e] = strval
bool operator==(std::string str) noexcept
overloading of operator== which allows to write: prop1[e1] == prop2[e2]
inner class used to overload the operator[] to set a node string value
nodeStringValueRef & operator=(const nodeStringValueRef &ref) noexcept
overloading of operator= to assign a node string value which allows to write: prop1[n] = prop2[m]
nodeStringValueRef & operator=(std::string val) noexcept
overloading of operator= to assign a node string value which allows to write: prop[n] = strval
bool operator==(std::string str) noexcept
overloading of operator== which allows to write: prop1[n] == prop2[m]
PropertyInterface describes the interface of a graph property.
virtual void writeEdgeValue(std::ostream &, edge) const =0
Writes the value of an edge.
virtual std::string getNodeStringValue(const node n) const =0
Gets a string representation of the node value.
virtual bool readEdgeValue(std::istream &, edge)=0
Reads the value of an edge.
virtual tlp::Iterator< node > * getNonDefaultValuatedNodes(const Graph *=nullptr) const =0
Gets an Iterator on all non-default valuated nodes. When given a Graph as parameter,...
constexpr nodeStringValueRef operator[](node n)
overloading of operator[] to set a node string value
virtual DataMem * getEdgeDefaultDataMemValue() const =0
Gets a pointer to the tlp::DataMem structure that contains the edge default value.
virtual unsigned int numberOfNonDefaultValuatedNodes(const Graph *=nullptr) const =0
Returns the number of nodes with a non default value. When given a Graph as parameter,...
virtual void writeNodeDefaultValue(std::ostream &) const =0
Writes the nodes default value.
virtual std::string getNodeDefaultStringValue() const =0
Gets a string representation of the node default value.
virtual void setAllEdgeDataMemValue(const DataMem *v)=0
Sets all the edges value to the value contained in the given DataMem structure. All previous values a...
virtual bool setAllEdgeStringValue(const std::string &value)=0
Sets all the edges value to the value represented by the string. For some types, some parsing will be...
const std::string & getName() const
Gets the name of the property (e.g. viewLayout).
MetaValueCalculator * getMetaValueCalculator()
Gets the MetaValueCalculator of this property.
virtual bool setNodeDefaultStringValue(const std::string &value)=0
Sets the value assigned as the default one to the future added nodes from a string representation.
virtual unsigned int edgeValueSize() const =0
Returns the size in bytes of an edge's value.
virtual void writeEdgeDefaultValue(std::ostream &) const =0
Writes the edges default value.
virtual void setAllNodeDataMemValue(const DataMem *value)=0
Sets all the nodes value to the value contained in the given DataMem structure. All previous values a...
virtual bool setStringValueToGraphEdges(const std::string &value, const Graph *graph)=0
Sets all the edges value to the value represented by the string for a graph. For some types,...
virtual bool hasNonDefaultValuatedEdges(const Graph *=nullptr) const =0
Returns whether the property has edges with a non default value. When given a Graph as parameter,...
virtual void setMetaValueCalculator(MetaValueCalculator *calculator)
Sets the Calculator for meta nodes and edges.
virtual void computeMetaValue(node metaNode, Graph *subgraph, Graph *metaGraph)=0
Sets the value of the metanode to a computed value.
virtual DataMem * getEdgeDataMemValue(const edge e) const =0
Gets the edge value, contained in a tlp::DataMem structure.
virtual void erase(const node)=0
Erases the value stored for the given node. The new value for the node is the default value.
virtual void setNodeDataMemValue(const node n, const DataMem *value)=0
Sets the node value.
virtual const std::string & getTypename() const =0
Gets a string describing the type of the property value (e.g. "graph", "double", "layout",...
virtual DataMem * getNodeDataMemValue(const node n) const =0
Gets the node value, contained in a tlp::DataMem structure.
virtual bool setEdgeDefaultStringValue(const std::string &value)=0
Sets the value assigned as the default one to the future added edges from a string representation.
virtual void writeNodeValue(std::ostream &, node) const =0
Writes the value of a node.
virtual bool setStringValueToGraphNodes(const std::string &value, const Graph *graph)=0
Sets all the nodes value to the value represented by the string for a graph. For some types,...
virtual bool setEdgeStringValue(const edge e, const std::string &value)=0
Sets a new value on the edge, represented by the string parameter.
virtual bool readEdgeDefaultValue(std::istream &)=0
Reads the edges default value.
virtual unsigned int nodeValueSize() const =0
Returns the size in bytes of a node's value.
virtual tlp::Iterator< edge > * getNonDefaultValuatedEdges(const Graph *=nullptr) const =0
Gets an Iterator on all non-default valuated edges. When given a Graph as parameter,...
virtual const std::string & getCppClassName() const =0
Gets a string giving the name of a the PropertyInterface subclass (e.g "tlp::BooleanProperty",...
virtual DataMem * getNonDefaultDataMemValue(const node n) const =0
Returns the value in a DataMem if it is not default, otherwise returns nullptr.
virtual DataMem * getNonDefaultDataMemValue(const edge e) const =0
Returns the value in a DataMem if it is not default, otherwise returns nullptr.
virtual std::string getEdgeDefaultStringValue() const =0
Gets a string representation of the edge default value.
virtual bool readNodeValue(std::istream &, node)=0
Reads the value of a node.
virtual bool copy(const edge destination, const edge source, PropertyInterface *property, bool ifNotDefault=false)=0
Copies the value of an edge in another property to an edge in this property.
virtual unsigned int numberOfNonDefaultValuatedEdges(const Graph *=nullptr) const =0
Returns the number of edges with a non default value.
virtual std::string getEdgeStringValue(const edge e) const =0
Gets a string representation of the edge value.
virtual int compare(const edge e1, const edge e2) const =0
Compares the value this property holds for the two given edges.
virtual PropertyInterface * clonePrototype(Graph *graph, const std::string &name) const =0
Creates a property of the same type (e.g. tlp::DoubleProperty) in the graph. The new property will no...
virtual void setEdgeDataMemValue(const edge e, const DataMem *v)=0
Sets the edge value.
virtual DataMem * getNodeDefaultDataMemValue() const =0
Gets a pointer to the tlp::DataMem structure that contains the node default value.
virtual void computeMetaValue(edge metaEdge, tlp::Iterator< edge > *it, Graph *metaGraph)=0
Sets the value of the metaedge to a computed value.
virtual void copy(PropertyInterface *source)=0
Copies the values of the source property to this property.
virtual void erase(const edge)=0
Erases the value stored for the given edge. The new value for the edge is the default value.
bool rename(const std::string &newName)
Rename a property.
virtual bool setAllNodeStringValue(const std::string &value)=0
Sets all the nodes value to the value represented by the string. For some types, some parsing will be...
virtual bool hasNonDefaultValuatedNodes(const Graph *=nullptr) const =0
Returns whether the property has nodes with a non default value. When given a Graph as parameter,...
virtual bool copy(const node destination, const node source, PropertyInterface *property, bool ifNotDefault=false)=0
Copies the value of a node in another property to a node in this property.
virtual bool setNodeStringValue(const node n, const std::string &value)=0
Sets a new value on the node, represented by the string parameter.
virtual int compare(const node n1, const node n2) const =0
Compares the value this property holds for the two given nodes.
std::string operator[](edge e) const
overloading of operator[] to get the edge string value
virtual bool readNodeDefaultValue(std::istream &)=0
Reads the nodes default value.
constexpr edgeStringValueRef operator[](edge e)
overloading of operator[] to set a edge string value value
VectorPropertyInterface describes the interface of a graph property whose holded value is a vector (s...
virtual bool setEdgeStringValueAsVector(const edge e, const std::vector< std::string > &values)=0
Sets a new vector represented by the vector of string parameter as the edge value.
virtual bool tokenize(const std::string &str, std::vector< std::string > &vect, char openChar='(', char sepChar=',', char closeChar=')')=0
split an input string into a vector of strings
virtual bool setNodeStringValueAsVector(const node n, const std::string &value, char openChar='(', char sepChar=',', char closeChar=')')=0
Sets a new vector represented by the string parameter as the node value.
virtual bool setNodeStringValueAsVector(const node n, const std::vector< std::string > &values)=0
Sets a new vector represented by the vector of string parameter as the node value.
virtual bool setEdgeStringValueAsVector(const edge e, const std::string &value, char openChar='(', char sepChar=',', char closeChar=')')=0
Sets a new vector represented by the string parameter as the edge value.
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
The node struct represents a node in a Graph object.
Definition: Node.h:40