Tulip  6.0.0
Large graphs analysis and drawing
GraphProperty.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 TULIP_METAGRAPH_H
21 #define TULIP_METAGRAPH_H
22 
23 #include <set>
24 
25 #include <tulip/PropertyTypes.h>
26 #include <tulip/AbstractProperty.h>
27 
28 namespace tlp {
29 
30 class PropertyContext;
31 class GraphAbstract;
32 
33 typedef AbstractProperty<tlp::GraphType, tlp::EdgeSetType> AbstractGraphProperty;
34 
35 /**
36  * @ingroup Graph
37  * @brief A graph property that maps a tlp::Graph* value to graph elements.
38  *
39  * @warning This property is mainly used into the meta node engine. Using GraphProperty outside of
40  * this system is strongly discouraged since it could lead to unwanted behavior.
41  */
42 class TLP_SCOPE GraphProperty : public AbstractGraphProperty {
43  friend class GraphAbstract;
44 
45 public:
46  GraphProperty(Graph *, const std::string &n = "");
47  ~GraphProperty() override {}
48  using AbstractGraphProperty::operator=;
49  // override Observable::treatEvent
50  void treatEvent(const Event &) override;
51 
52  // redefinition of some PropertyInterface methods
53  PropertyInterface *clonePrototype(Graph *, const std::string &) const override;
54  bool setNodeStringValue(const node n, const std::string &v) override;
55  bool setAllNodeStringValue(const std::string &v) override;
56  bool setStringValueToGraphNodes(const std::string &v, const tlp::Graph *graph) override;
57  bool setEdgeStringValue(const edge e, const std::string &v) override;
58  bool setAllEdgeStringValue(const std::string &v) override;
59  bool setStringValueToGraphEdges(const std::string &v, const tlp::Graph *graph) override;
60  static const std::string propertyTypename;
61  const std::string &getTypename() const override {
62  return propertyTypename;
63  }
64  DEFINE_GET_CPP_CLASS_NAME;
65 
66  // redefinition of some AbstractProperty methods
67  void setNodeValue(const node n,
68  tlp::StoredType<GraphType::RealType>::ReturnedConstValue g) override;
69  void setAllNodeValue(tlp::StoredType<GraphType::RealType>::ReturnedConstValue g) override;
70  void setValueToGraphNodes(tlp::StoredType<GraphType::RealType>::ReturnedConstValue g,
71  const Graph *graph) override;
72  bool readNodeDefaultValue(std::istream &iss) override;
73  bool readNodeValue(std::istream &iss, node n) override;
74  // tlp::GraphType encapsulates a tlp::Graph pointer but that is the graph id
75  // that gets serialized when using the TLPB format
76  unsigned int nodeValueSize() const override {
77  return sizeof(unsigned int);
78  }
79  unsigned int edgeValueSize() const override {
80  return 0;
81  }
82 
83  // for optimizations purpose
84  bool hasNonDefaultValue(const node n) const {
85  return nodeProperties.hasNonDefaultValue(n.id);
86  }
87  bool hasNonDefaultValue(const edge e) const {
88  return !edgeProperties.get(e.id).empty();
89  }
90 
91 private:
92  MutableContainer<std::set<node>> referencedGraph;
93  const std::set<edge> &getReferencedEdges(const edge) const;
94 };
95 } // namespace tlp
96 #endif
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:52
A graph property that maps a tlp::Graph* value to graph elements.
Definition: GraphProperty.h:42
unsigned int edgeValueSize() const override
Returns the size in bytes of an edge's value.
Definition: GraphProperty.h:79
bool setAllEdgeStringValue(const std::string &v) override
Sets all the edges value to the value represented by the string. For some types, some parsing will be...
bool setAllNodeStringValue(const std::string &v) override
Sets all the nodes value to the value represented by the string. For some types, some parsing will be...
void treatEvent(const Event &) override
This function is called when events are sent to the Listeners, and Listeners only.
bool setEdgeStringValue(const edge e, const std::string &v) override
Sets a new value on the edge, represented by the string parameter.
bool setStringValueToGraphNodes(const std::string &v, const tlp::Graph *graph) override
Sets all the nodes value to the value represented by the string for a graph. For some types,...
unsigned int nodeValueSize() const override
Returns the size in bytes of a node's value.
Definition: GraphProperty.h:76
bool readNodeDefaultValue(std::istream &iss) override
Reads the nodes default value.
bool setNodeStringValue(const node n, const std::string &v) override
Sets a new value on the node, represented by the string parameter.
const std::string & getTypename() const override
Gets a string describing the type of the property value (e.g. "graph", "double", "layout",...
Definition: GraphProperty.h:61
bool setStringValueToGraphEdges(const std::string &v, const tlp::Graph *graph) override
Sets all the edges value to the value represented by the string for a graph. For some types,...
bool readNodeValue(std::istream &iss, node n) override
Reads the value of a node.
PropertyInterface * clonePrototype(Graph *, const std::string &) const override
Creates a property of the same type (e.g. tlp::DoubleProperty) in the graph. The new property will no...
PropertyInterface describes the interface of a graph property.
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
unsigned int id
id The identifier of the node.
Definition: Node.h:44