Tulip  5.3.1
Large graphs analysis and drawing
PropertyInterface.h
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 
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/Node.h>
30 #include <tulip/Edge.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 (e.g. "graph", "double", "layout",
128  * "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 the name of the property (e.g. viewLayout).
135  * @return The name of this property.
136  */
137  const std::string &getName() const {
138  return name;
139  }
140 
141  /**
142  * @brief Rename a property
143  * @param the new name
144  * @return returns true if the renaming succeeded.
145  * It may fails if a property with the given name already exists
146  */
147  bool rename(const std::string &newName);
148  /**
149  * @cond DOXYGEN_HIDDEN
150  * @brief Gets the graph on which this property has been defined.
151  * This is an internal function and its behavior can change.
152  * DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING.
153  *
154  * Be wary that is might be a different graph that the one you used to get this property.
155  * For instance:
156  * @code
157  * Graph* g = tlp::newGraph();
158  * Graph*sub = g->addCloneSubGraph();
159  *
160  * IntegerProperty* prop = g->getProperty<IntegerProperty>("test");
161  * //prop->getGraph() returns g
162  *
163  * IntegerProperty* prop2 = sub->getProperty<IntegerProperty>("test");
164  * //prop2->getGraph() returns g
165  * @endcode
166  *
167  * This is due to the inheritance system of the properties.
168  *
169  * @return The Graph this property is local to.
170  * @endcond
171  */
172  tlp::Graph *getGraph() const {
173  return graph;
174  }
175 
176  /**
177  * @brief Gets a string representation of the node default value.
178  * @param n The node to get the value of.
179  * @return A string representation of the node default value.
180  */
181  virtual std::string getNodeStringValue(const node n) const = 0;
182 
183  /**
184  * @brief Gets a string representation of the edge default value.
185  * @param e The edge to get the value of.
186  * @return A string representation of the edge default value.
187  */
188  virtual std::string getEdgeStringValue(const edge e) const = 0;
189 
190  /**
191  * @brief Sets a new value on the node, represented by the string parameter.
192  * @param n The node on which to set the new value.
193  * @param value A string representing the value to set on the node.
194  * @return Whether the string was a correct representation for this property's type. If not, the
195  * value is not set.
196  */
197  virtual bool setNodeStringValue(const node n, const std::string &value) = 0;
198 
199  /**
200  * @brief Sets a new value on the edge, represented by the string parameter.
201  * @param e The edge on which to set value on.
202  * @param value A string representing the value to set on the edge.
203  * @return Whether the string was a correct representation for this property's type. If not, the
204  * value is not set.
205  */
206  virtual bool setEdgeStringValue(const edge e, const std::string &value) = 0;
207 
208  /**
209  * @brief Gets a string representation of the node default value.
210  * @return A string representation of the node default value.
211  */
212  virtual std::string getNodeDefaultStringValue() const = 0;
213 
214  /**
215  * @brief Gets a string representation of the edge default value.
216  * @return A string representation of the edge default value.
217  */
218  virtual std::string getEdgeDefaultStringValue() const = 0;
219 
220  /**
221  * @brief Sets the value assigned as the default one to the future added nodes from a string
222  * representation.
223  *
224  * @since Tulip 5.0
225  *
226  * @param value A string representing the new value to set on future added nodes.
227  *
228  * @return Whether the given string was a correct representation for this property's type. If not,
229  * the default value is not set.
230  */
231  virtual bool setNodeDefaultStringValue(const std::string &value) = 0;
232 
233  /**
234  * @brief Sets all the nodes value to the value represented by the string. For some types, some
235  * parsing will be necessary (e.g. LayoutProperty).
236  * All previous values are lost and the represented value is assigned as the default one to the
237  * future added nodes.
238  *
239  * @param value A string representing the new value to set on all the nodes.
240  *
241  * @return Whether the given string was a correct representation for this property's type. If not,
242  * the values are not set.
243  */
244  virtual bool setAllNodeStringValue(const std::string &value) = 0;
245 
246  /**
247  * @brief Sets all the nodes value to the value represented by the string for a graph. For some
248  * types, some parsing will be necessary (e.g. LayoutProperty).
249  * Only the nodes from that graph will have their value modified in the property
250  * and the default node value will not be modified.
251  *
252  * @since Tulip 4.10
253  *
254  * @deprecated Since Tulip 5.0 this method signature is deprecated use method
255  * setStringValueToGraphNodes instead
256  *
257  * @param value A string representing the new value to set on all the nodes.
258  * @param graph A graph that defines the set of nodes.
259  *
260  * @warning If the provided graph is not a descendant of the one associated to that property
261  * (including itself), no node value will be modified in it.
262  *
263  * @return Whether the given string was a correct representation for this property's type. If not,
264  * the values are not set.
265  */
266  _DEPRECATED virtual bool setAllNodeStringValue(const std::string &value, const Graph *graph) = 0;
267 
268  /**
269  * @brief Sets all the nodes value to the value represented by the string for a graph. For some
270  * types, some parsing will be necessary (e.g. LayoutProperty).
271  * Only the nodes from that graph will have their value modified in the property
272  * and the default node value will not be modified.
273  *
274  * @since Tulip 5.0
275  *
276  * @param value A string representing the new value to set on all the nodes.
277  * @param graph A graph that defines the set of nodes.
278  *
279  * @warning If the provided graph is not a descendant of the one associated to that property
280  * (including itself), no node value will be modified in it.
281  *
282  * @return Whether the given string was a correct representation for this property's type. If not,
283  * the values are not set.
284  */
285  virtual bool setStringValueToGraphNodes(const std::string &value, const Graph *graph) = 0;
286 
287  /**
288  * @brief Sets the value assigned as the default one to the future added edges from a string
289  * representation.
290  *
291  * @since Tulip 5.0
292  *
293  * @param value A string representing the new value to set on future added edges.
294  *
295  * @return Whether the given string was a correct representation for this property's type. If not,
296  * the default value is not set.
297  */
298  virtual bool setEdgeDefaultStringValue(const std::string &value) = 0;
299 
300  /**
301  * @brief Sets all the edges value to the value represented by the string. For some types, some
302  * parsing will be necessary (e.g. LayoutProperty).
303  * All previous values are lost and the represented value is assigned as the default one to the
304  * future added edges.
305  *
306  * @param value A string representing the new value to set on all the edges.
307  *
308  * @return Whether the given string was a correct representation for this property's type. If not,
309  * the values are not set.
310  */
311  virtual bool setAllEdgeStringValue(const std::string &value) = 0;
312 
313  /**
314  * @brief Sets all the edges value to the value represented by the string for a graph. For some
315  * types, some parsing will be necessary (e.g. LayoutProperty).
316  * Only the edges from that graph will have their value modified in the property
317  * and the default edge value will not be modified.
318  *
319  * @since Tulip 4.10
320  *
321  * @deprecated Since Tulip 5.0 this method signature is deprecated use method
322  * setStringValueToGraphEdges instead
323  *
324  * @param value A string representing the new value to set on all the edges.
325  * @param graph A graph that defines the set of edges.
326  *
327  * @warning If the provided graph is not a descendant of the one associated to that property
328  * (including itself), no edge value will be modified in it.
329  *
330  * @return Whether the given string was a correct representation for this property's type. If not,
331  * the values are not set.
332  */
333  _DEPRECATED virtual bool setAllEdgeStringValue(const std::string &value, const Graph *graph) = 0;
334 
335  /**
336  * @brief Sets all the edges value to the value represented by the string for a graph. For some
337  * types, some parsing will be necessary (e.g. LayoutProperty).
338  * Only the edges from that graph will have their value modified in the property
339  * and the default edge value will not be modified.
340  *
341  * @since Tulip 5.0
342  *
343  * @param value A string representing the new value to set on all the edges.
344  * @param graph A graph that defines the set of edges.
345  *
346  * @warning If the provided graph is not a descendant of the one associated to that property
347  * (including itself), no edge value will be modified in it.
348  *
349  * @return Whether the given string was a correct representation for this property's type. If not,
350  * the values are not set.
351  */
352  virtual bool setStringValueToGraphEdges(const std::string &value, const Graph *graph) = 0;
353 
354  /**
355  * @brief Gets a pointer to the tlp::DataMem structure that contains the node default value.
356  * @return The DataMem structure containing the node default value.
357  * @warning The ownership of this pointer is given to the caller.
358  */
359  virtual DataMem *getNodeDefaultDataMemValue() const = 0;
360 
361  /**
362  * @brief Gets a pointer to the tlp::DataMem structure that contains the edge default value.
363  * @return The DataMem structure containing the edge default value.
364  * @warning The ownership of this pointer is given to the caller.
365  */
366  virtual DataMem *getEdgeDefaultDataMemValue() const = 0;
367 
368  /**
369  * @brief Sets all the nodes value to the value contained in the given DataMem structure.
370  * All previous values are lost.
371  * @param value The value to set on all the nodes.
372  */
373  virtual void setAllNodeDataMemValue(const DataMem *value) = 0;
374 
375  /**
376  * @brief Sets all the edges value to the value contained in the given DataMem structure.
377  * All previous values are lost.
378  * @param value The value to set on all the edges.
379  */
380  virtual void setAllEdgeDataMemValue(const DataMem *v) = 0;
381 
382  /**
383  * @brief Gets the node value, contained in a tlp::DataMem structure.
384  * @param n The node to get the value of.
385  * @return The value of the node, in a tlp::DataMem.
386  *
387  * @warning The ownership of this pointer is given to the caller.
388  */
389  virtual DataMem *getNodeDataMemValue(const node n) const = 0;
390 
391  /**
392  * @brief Gets the edge value, contained in a tlp::DataMem structure.
393  * @param n The edge to get the value of.
394  * @return The value of the edge, in a tlp::DataMem.
395  *
396  * @warning The ownership of this pointer is given to the caller.
397  */
398  virtual DataMem *getEdgeDataMemValue(const edge e) const = 0;
399 
400  /**
401  * @brief Returns the value in a DataMem if it is not default, otherwise returns nullptr.
402  * @param n The node to get the value of.
403  * @return The value of the node if it is not default, or nullptr.
404  *
405  * @warning The ownership of this pointer is given to the caller.
406  */
407  virtual DataMem *getNonDefaultDataMemValue(const node n) const = 0;
408 
409  /**
410  * @brief Returns the value in a DataMem if it is not default, otherwise returns nullptr.
411  * @param e The edge to get the value of.
412  * @return The value of the edge if it is not default, or nullptr.
413  *
414  * @warning The ownership of this pointer is given to the caller.
415  */
416  virtual DataMem *getNonDefaultDataMemValue(const edge e) const = 0;
417 
418  /**
419  * @brief Sets the node value.
420  * @param n The node to set the value of.
421  * @param value The value to set to this node.
422  */
423  virtual void setNodeDataMemValue(const node n, const DataMem *value) = 0;
424 
425  /**
426  * @brief Sets the edge value.
427  * @param e The edge to set the value of.
428  * @param value The value to set to this edge.
429  */
430  virtual void setEdgeDataMemValue(const edge e, const DataMem *v) = 0;
431 
432  /**
433  * @brief Gets an Iterator on all non-default valuated nodes.
434  * When given a Graph as parameter, only nodes belonging to this graph are iterated over.
435  * @return An Iterator over nodes whose value is not default.
436  *
437  * @warning The ownership of the iterator is given to the caller.
438  */
439  virtual tlp::Iterator<node> *getNonDefaultValuatedNodes(const Graph * = nullptr) const = 0;
440 
441  /**
442  * @brief Returns whether the property has nodes with a non default value.
443  * When given a Graph as parameter, only the nodes with a non default value belonging to
444  * this graph are taken into account.
445  * @return false if all nodes has the default value, true if not.
446  *
447  */
448  virtual bool hasNonDefaultValuatedNodes(const Graph * = nullptr) const = 0;
449 
450  /**
451  * @brief Returns the number of nodes with a non default value.
452  * When given a Graph as parameter, only the number of nodes with a non default value belonging to
453  * this graph is returned.
454  * @return the number of nodes with a non default value.
455  *
456  */
457  virtual unsigned int numberOfNonDefaultValuatedNodes(const Graph * = nullptr) const = 0;
458 
459  /**
460  * @brief Gets an Iterator on all non-default valuated edges.
461  * When given a Graph as parameter, only edges belonging to this graph are iterated over.
462  * @return An Iterator over edges whose value is not default.
463  *
464  * @warning The ownership of the iterator is given to the caller.
465  */
466  virtual tlp::Iterator<edge> *getNonDefaultValuatedEdges(const Graph * = nullptr) const = 0;
467 
468  /**
469  * @brief Returns whether the property has edges with a non default value.
470  * When given a Graph as parameter, only the edges with a non default value belonging to
471  * this graph are taken into account.
472  * @return false if all edges has the default value, true if not.
473  *
474  */
475  virtual bool hasNonDefaultValuatedEdges(const Graph * = nullptr) const = 0;
476 
477  /**
478  * @brief Returns the number of edges with a non default value.
479  * @return the number of edges with a non default value.
480  *
481  */
482  virtual unsigned int numberOfNonDefaultValuatedEdges(const Graph * = nullptr) const = 0;
483 
484  /**
485  * @brief Returns the size in bytes of a node's value.
486  * @return the size of a node's value (0 means the size is not fixed)
487  *
488  */
489  virtual unsigned int nodeValueSize() const = 0;
490 
491  /**
492  * @brief Writes the nodes default value
493  *
494  */
495  virtual void writeNodeDefaultValue(std::ostream &) const = 0;
496 
497  /**
498  * @brief Writes the value of a node
499  *
500  */
501  virtual void writeNodeValue(std::ostream &, node) const = 0;
502 
503  /**
504  * @brief Reads the nodes default value
505  *
506  */
507  virtual bool readNodeDefaultValue(std::istream &) = 0;
508 
509  /**
510  * @brief Reads the value of a node
511  *
512  */
513  virtual bool readNodeValue(std::istream &, node) = 0;
514 
515  /**
516  * @brief Returns the size in bytes of an edge's value.
517  * @return the size of a node's value (0 means the size is not fixed)
518  *
519  */
520  virtual unsigned int edgeValueSize() const = 0;
521 
522  /**
523  * @brief Writes the edges default value
524  *
525  */
526  virtual void writeEdgeDefaultValue(std::ostream &) const = 0;
527 
528  /**
529  * @brief Writes the value of an edge
530  *
531  */
532  virtual void writeEdgeValue(std::ostream &, edge) const = 0;
533 
534  /**
535  * @brief Reads the edges default value
536  *
537  */
538  virtual bool readEdgeDefaultValue(std::istream &) = 0;
539 
540  /**
541  * @brief Reads the value of an edge
542  *
543  */
544  virtual bool readEdgeValue(std::istream &, edge) = 0;
545 
546  /**
547  * @brief Sets the value of the metanode to a computed value.
548  *
549  * The value is computed by this property's MetaValueCalculator.
550  * @param metaNode The metanode to compute a value on.
551  * @param subgraph The subgraph pointed by the metanode.
552  * @param metaGraph The graph who owns the meta node.
553  */
554  virtual void computeMetaValue(node metaNode, Graph *subgraph, Graph *metaGraph) = 0;
555 
556  /**
557  * @brief Sets the value of the metaedge to a computed value.
558  * @param metaEdge The meta edge to compute a value on.
559  * @param it The edges represented by the meta edge.
560  * @param metaGraph The graph who owns the meta edge.
561  */
562  virtual void computeMetaValue(edge metaEdge, tlp::Iterator<edge> *it, Graph *metaGraph) = 0;
563 
564  /**
565  * @brief Base class for computing values on meta nodes and edges.
566  */
568  public:
569  virtual ~MetaValueCalculator() {}
570  };
571 
572  /**
573  * @brief Gets the MetaValueCalculator of this property.
574  * @return The MetaValueCalculator of this property
575  */
577  return metaValueCalculator;
578  }
579 
580  /**
581  * @brief Sets the Calculator for meta nodes and edges.
582  * @param calculator The object containing the logic for computing the meta values for the nodes
583  * and edges.
584  *
585  * @warning The ownership of the MetaValueCalculator is not taken by the property.
586  */
587  virtual void setMetaValueCalculator(MetaValueCalculator *calculator) {
588  metaValueCalculator = calculator;
589  }
590 
591  /**
592  * @brief Compares the value this property holds for the two given nodes.
593  * @param n1 The first node to compare the value of.
594  * @param n2 The second node to compare the value of.
595  * @return 0 if the values are identical, a positive value if n1 is greater than n2, and a
596  * negative value if n1 is less than n2.
597  */
598  virtual int compare(const node n1, const node n2) const = 0;
599 
600  /**
601  * @brief Compares the value this property holds for the two given edges.
602  * @param e1 The first edge to compare the value of.
603  * @param e2 The second edge to compare the value of.
604  * @return 0 if the values are identical, a positive value if e1 is greater than e2, and a
605  * negative value if e1 is less than e2.
606  */
607  virtual int compare(const edge e1, const edge e2) const = 0;
608 
609 protected:
610  MetaValueCalculator *metaValueCalculator;
611 
612  // for notification of PropertyObserver
613  void notifyBeforeSetNodeValue(const node n);
614  void notifyAfterSetNodeValue(const node n);
615  void notifyBeforeSetEdgeValue(const edge e);
616  void notifyAfterSetEdgeValue(const edge e);
617  void notifyBeforeSetAllNodeValue();
618  void notifyAfterSetAllNodeValue();
619  void notifyBeforeSetAllEdgeValue();
620  void notifyAfterSetAllEdgeValue();
621  void notifyDestroy();
622  void notifyRename(const std::string &newName);
623 };
624 
625 /**
626  * @ingroup Graph
627  * @brief VectorPropertyInterface describes the interface of a graph property whose holded value is
628  * a vector (std::vector)
629  *
630  */
631 class TLP_SCOPE VectorPropertyInterface : public PropertyInterface {
632 public:
634 
635  ~VectorPropertyInterface() override {}
636 
637  /**
638  * @brief split an input string into a vector of strings
639  * @param str A string listing the elements of the vector to set on a node/edge.
640  * @param vect An output vector containing the string elements
641  * @param openChar an optional character opening the list of elements. Default value is '('; when
642  * set to '\0' it indicates that there is no opening character.
643  * @param sepChar an optional character separing the elements of the list. Default value is ','.
644  * @param closeChar an optional character closing the list of elements. Default value is ')'; when
645  * set to '\0' it indicates that there is no opening character.
646  * @return Whether the string was a correct representation for this property's type.
647  */
648  virtual bool tokenize(const std::string &str, std::vector<std::string> &vect, char openChar = '(',
649  char sepChar = ',', char closeChar = ')') = 0;
650 
651  /**
652  * @brief Sets a new vector represented by the vector of string parameter as the node value.
653  * @param n The node on which to set the new value.
654  * @param values A vector of strings listing the string representations of elements of the vector
655  * to set on the node.
656  * @return Whether the vector was a correct representation for this property's type. If not, the
657  * value is not set.
658  */
659  virtual bool setNodeStringValueAsVector(const node n, const std::vector<std::string> &values) = 0;
660 
661  /**
662  * @brief Sets a new vector represented by the vector of string parameter as the edge value.
663  * @param e The edge on which to set the new value.
664  * @param values A vector of strings listing the string representations of elements of the vector
665  * to set on the edge.
666  * @return Whether the vector was a correct representation for this property's type. If not, the
667  * value is not set.
668  */
669  virtual bool setEdgeStringValueAsVector(const edge e, const std::vector<std::string> &values) = 0;
670 
671  /**
672  * @brief Sets a new vector represented by the string parameter as the node value.
673  * @param n The node on which to set the new value.
674  * @param value A string listing the elements of the vector to set on the node.
675  * @param openChar an optional character opening the list of elements. Default value is '('; when
676  * set to '\0' it indicates that there is no opening character.
677  * @param sepChar an optional character separing the elements of the list. Default value is ','.
678  * @param closeChar an optional character closing the list of elements. Default value is ')'; when
679  * set to '\0' it indicates that there is no opening character.
680  * @return Whether the string was a correct representation for this property's type. If not, the
681  * value is not set.
682  */
683  virtual bool setNodeStringValueAsVector(const node n, const std::string &value,
684  char openChar = '(', char sepChar = ',',
685  char closeChar = ')') = 0;
686 
687  /**
688  * @brief Sets a new vector represented by the string parameter as the edge value.
689  * @param e The edge on which to set value on.
690  * @param value A string listing the elements of the vector to set on the edge.
691  * @param openChar an optional character opening the list of elements. Default value is '('; when
692  * set to '\0' it indicates that there is no opening character.
693  * @param sepChar an optional character separing the elements of the list. Default value is ','.
694  * @param closeChar an optional character closing the list of elements. Default value is ')'; when
695  * set to '\0' it indicates that there is no opening character.
696  * @return Whether the string was a correct representation for this property's type. If not, the
697  * value is not set.
698  */
699  virtual bool setEdgeStringValueAsVector(const edge e, const std::string &value,
700  char openChar = '(', char sepChar = ',',
701  char closeChar = ')') = 0;
702 };
703 
704 /**
705  * @ingroup Observation
706  * @brief Contains additional information about events on a property,
707  * such as the property it happened on, the node/edge eventually concerned and such.
708  * It also contains the detailed type of the event.
709  */
710 class TLP_SCOPE PropertyEvent : public Event {
711 public:
712  // be careful about the ordering of the constants
713  // in the enum below because it is used in some assertions
714  enum PropertyEventType {
715  TLP_BEFORE_SET_NODE_VALUE = 0,
716  TLP_AFTER_SET_NODE_VALUE,
717  TLP_BEFORE_SET_ALL_NODE_VALUE,
718  TLP_AFTER_SET_ALL_NODE_VALUE,
719  TLP_BEFORE_SET_ALL_EDGE_VALUE,
720  TLP_AFTER_SET_ALL_EDGE_VALUE,
721  TLP_BEFORE_SET_EDGE_VALUE,
722  TLP_AFTER_SET_EDGE_VALUE
723  };
724  PropertyEvent(const PropertyInterface &prop, PropertyEventType propEvtType,
725  Event::EventType evtType = Event::TLP_MODIFICATION, unsigned int id = UINT_MAX)
726  : Event(prop, evtType), evtType(propEvtType), eltId(id) {}
727 
728  PropertyInterface *getProperty() const {
729  return static_cast<PropertyInterface *>(sender());
730  }
731 
732  node getNode() const {
733  assert(evtType < TLP_BEFORE_SET_ALL_NODE_VALUE);
734  return node(eltId);
735  }
736 
737  edge getEdge() const {
738  assert(evtType > TLP_AFTER_SET_ALL_EDGE_VALUE);
739  return edge(eltId);
740  }
741 
742  PropertyEventType getType() const {
743  return evtType;
744  }
745 
746 protected:
747  PropertyEventType evtType;
748  unsigned int eltId;
749 };
750 } // namespace tlp
751 
752 //================================================================================
753 // these functions allow to use tlp::PropertyInterface as a key in a hash-based data structure (e.g.
754 // hashmap).
755 //================================================================================
756 
757 ///@cond DOXYGEN_HIDDEN
758 namespace std {
759 template <>
760 struct TLP_SCOPE hash<const tlp::PropertyInterface *> {
761  size_t operator()(const tlp::PropertyInterface *prop) const {
762  return size_t(prop);
763  }
764 };
765 template <>
766 struct TLP_SCOPE hash<tlp::PropertyInterface *> {
767  size_t operator()(tlp::PropertyInterface *prop) const {
768  return size_t(prop);
769  }
770 };
771 } // namespace std
772 ///@endcond
773 
774 #endif // PROPERTY_INTERFACE_H
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Graph.h:43
PropertyInterface describes the interface of a graph property.
Definition: TlpTools.h:48
Contains additional information about events on a property, such as the property it happened on...
MetaValueCalculator * getMetaValueCalculator()
Gets the MetaValueCalculator of this property.
const std::string & getName() const
Gets the name of the property (e.g. viewLayout).
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
VectorPropertyInterface describes the interface of a graph property whose holded value is a vector (s...
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:52
Base class for computing values on meta nodes and edges.
virtual void setMetaValueCalculator(MetaValueCalculator *calculator)
Sets the Calculator for meta nodes and edges.
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:127