Tulip 6.1.0
Large graphs analysis and drawing
Loading...
Searching...
No Matches
IntegerProperty.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_INT_H
21#define TULIP_INT_H
22
23#include <tulip/PropertyTypes.h>
24#include <tulip/AbstractProperty.h>
25#include <tulip/minmaxproperty.h>
26#include <tulip/NumericProperty.h>
27
28namespace tlp {
29
30class Graph;
31class PropertyContext;
32
34 IntegerMinMaxProperty;
35
36/**
37 * @ingroup Graph
38 * @brief A graph property that maps an integer value to graph elements.
39 */
40class TLP_SCOPE IntegerProperty : public IntegerMinMaxProperty {
41
42public:
43 IntegerProperty(Graph *, const std::string &n = "");
44 using IntegerMinMaxProperty::operator=;
45 PropertyInterface *clonePrototype(Graph *, const std::string &) const override;
46 static const std::string propertyTypename;
47 const std::string &getTypename() const override {
48 return propertyTypename;
49 }
50 DEFINE_GET_CPP_CLASS_NAME;
51 void setNodeValue(const node n, tlp::StoredType<int>::ReturnedConstValue v) override;
52
53 // inner class used to extend the overloading of the operator[]
54 // to set a node value
55 class nodeValueRef : public AbstractProperty<tlp::IntegerType, tlp::IntegerType,
56 tlp::NumericProperty>::nodeValueRef {
57 public:
58 constexpr nodeValueRef(IntegerProperty *prop, node n)
59 : AbstractProperty<tlp::IntegerType, tlp::IntegerType, tlp::NumericProperty>::nodeValueRef(
60 prop, n) {}
61
62 nodeValueRef &operator=(
63 typename tlp::StoredType<typename IntegerType::RealType>::ReturnedConstValue val) noexcept {
64 _prop->setNodeValue(_n, val);
65 return *this;
66 }
67
68 // prefix increment
69 nodeValueRef &operator++() {
70 _prop->setNodeValue(_n, getValue() + 1);
71 return *this;
72 }
73
74 // postfix increment
75 auto operator++(int) {
76 auto val = getValue();
77 _prop->setNodeValue(_n, val + 1);
78 return val;
79 }
80
81 // increment and assign
82 nodeValueRef &operator+=(int val) {
83 _prop->setNodeValue(_n, getValue() + val);
84 return *this;
85 }
86
87 // prefix decrement
88 nodeValueRef &operator--() {
89 _prop->setNodeValue(_n, getValue() - 1);
90 return *this;
91 }
92
93 // postfix decrement
94 auto operator--(int) {
95 auto val = getValue();
96 _prop->setNodeValue(_n, val - 1);
97 return val;
98 }
99
100 // decrement and assign
101 nodeValueRef &operator-=(int val) {
102 _prop->setNodeValue(_n, getValue() - val);
103 return *this;
104 }
105 };
106
107 // overload operator[] to set a node value
108 constexpr nodeValueRef operator[](node n) {
109 return nodeValueRef(this, n);
110 }
111
112 void setEdgeValue(const edge e, tlp::StoredType<int>::ReturnedConstValue v) override;
113
114 // inner class used to extend the overloading of the operator[]
115 // to set an edge value
116 class edgeValueRef : public AbstractProperty<tlp::IntegerType, tlp::IntegerType,
117 tlp::NumericProperty>::edgeValueRef {
118 public:
119 constexpr edgeValueRef(IntegerProperty *prop, edge e)
120 : AbstractProperty<tlp::IntegerType, tlp::IntegerType, tlp::NumericProperty>::edgeValueRef(
121 prop, e) {}
122
123 edgeValueRef &operator=(
124 typename tlp::StoredType<typename IntegerType::RealType>::ReturnedConstValue val) noexcept {
125 _prop->setEdgeValue(_e, val);
126 return *this;
127 }
128
129 // prefix increment
130 edgeValueRef &operator++() {
131 _prop->setEdgeValue(_e, getValue() + 1);
132 return *this;
133 }
134
135 // postfix increment
136 auto operator++(int) {
137 auto val = getValue();
138 _prop->setEdgeValue(_e, val + 1);
139 return val;
140 }
141
142 // increase value
143 edgeValueRef &operator+=(int val) {
144 _prop->setEdgeValue(_e, getValue() + val);
145 return *this;
146 }
147
148 // prefix decrement
149 edgeValueRef &operator--() {
150 _prop->setEdgeValue(_e, getValue() - 1);
151 return *this;
152 }
153
154 // postfix decrement
155 auto operator--(int) {
156 auto val = getValue();
157 _prop->setEdgeValue(_e, val - 1);
158 return val;
159 }
160
161 // decrease value
162 edgeValueRef &operator-=(int val) {
163 _prop->setEdgeValue(_e, getValue() - val);
164 return *this;
165 }
166 };
167
168 // overload operator[] to set an edge value
169 constexpr edgeValueRef operator[](edge e) {
170 return edgeValueRef(this, e);
171 }
172
173 void setAllNodeValue(tlp::StoredType<int>::ReturnedConstValue v) override;
174
175 void setValueToGraphNodes(tlp::StoredType<int>::ReturnedConstValue v,
176 const Graph *graph) override;
177 void setAllEdgeValue(tlp::StoredType<int>::ReturnedConstValue v) override;
178 void setValueToGraphEdges(tlp::StoredType<int>::ReturnedConstValue v,
179 const Graph *graph) override;
180
181 int compare(const node n1, const node n2) const override;
182 int compare(const edge e1, const edge e2) const override;
183
184 // NumericProperty interface
185 double getNodeDoubleValue(const node n) const override {
186 return getNodeValue(n);
187 }
188 double getNodeDoubleDefaultValue() const override {
189 return getNodeDefaultValue();
190 }
191 double getNodeDoubleMin(const Graph *g = nullptr) override {
192 return getNodeMin(g);
193 }
194 double getNodeDoubleMax(const Graph *g = nullptr) override {
195 return getNodeMax(g);
196 }
197 double getEdgeDoubleValue(const edge e) const override {
198 return getEdgeValue(e);
199 }
200 double getEdgeDoubleDefaultValue() const override {
201 return getEdgeDefaultValue();
202 }
203 double getEdgeDoubleMin(const Graph *g = nullptr) override {
204 return getEdgeMin(g);
205 }
206 double getEdgeDoubleMax(const Graph *g = nullptr) override {
207 return getEdgeMax(g);
208 }
209
210 void nodesUniformQuantification(unsigned int) override;
211
212 void edgesUniformQuantification(unsigned int) override;
213
214 NumericProperty *copyProperty(Graph *g) override {
215 IntegerProperty *newProp = new IntegerProperty(g);
216 newProp->copy(this);
217
218 return newProp;
219 }
220
221protected:
222 void clone_handler(
223 AbstractProperty<tlp::IntegerType, tlp::IntegerType, tlp::NumericProperty> &) override;
224
225private:
226 // override Observable::treatEvent
227 void treatEvent(const Event &) override;
228};
229
230/**
231 * @ingroup Graph
232 * @brief A graph property that maps a std::vector<int> value to graph elements.
233 */
234class TLP_SCOPE IntegerVectorProperty
235 : public AbstractVectorProperty<tlp::IntegerVectorType, tlp::IntegerType> {
236public:
237 using AbstractVectorProperty<tlp::IntegerVectorType, tlp::IntegerType>::operator=;
238 IntegerVectorProperty(Graph *g, const std::string &n = "")
239 : AbstractVectorProperty<IntegerVectorType, tlp::IntegerType>(g, n) {}
240 // redefinition of some PropertyInterface methods
241 PropertyInterface *clonePrototype(Graph *, const std::string &) const override;
242 static const std::string propertyTypename;
243 const std::string &getTypename() const override {
244 return propertyTypename;
245 }
246 DEFINE_GET_CPP_CLASS_NAME;
247};
248} // namespace tlp
249#endif
250///@endcond
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
tlp::StoredType< typenameTnode::RealType >::ReturnedConstValue getNodeValue(const node n) const
Returns the value associated with the node n in this property. If there is no value,...
A graph property that maps an integer value to graph elements.
const std::string & getTypename() const override
Gets a string describing the type of the property value (e.g. "graph", "double", "layout",...
int compare(const node n1, const node n2) const override
Compares the value this property holds for the two given nodes.
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...
int compare(const edge e1, const edge e2) const override
Compares the value this property holds for the two given edges.
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...
const std::string & getTypename() const override
Gets a string describing the type of the property value (e.g. "graph", "double", "layout",...
Abstracts the computation of minimal and maximal values on node and edge values of properties.
Interface all numerical properties. Property values are always returned as double.
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