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