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