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