Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
PropertyTypes.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///@cond DOXYGEN_HIDDEN
20
21#ifndef TYPES_H
22#define TYPES_H
23
24#include <set>
25#include <vector>
26#include <iostream>
27#include <tulip/StoredType.h>
28#include <tulip/Coord.h>
29#include <tulip/Size.h>
30#include <tulip/Color.h>
31#include <tulip/Edge.h>
32#include <tulip/Node.h>
33#include <tulip/AbstractProperty.h>
34#include <tulip/TypeInterface.h>
35#include <tulip/SerializableType.h>
36
37namespace tlp {
38
39class Graph;
40
41class TLP_SCOPE GraphType : public TypeInterface<tlp::Graph *> {
42public:
43 static RealType undefinedValue();
44 static RealType defaultValue();
45 static void write(std::ostream &oss, const RealType &v);
46 static void writeb(std::ostream &oss, const RealType &v);
47 static bool read(std::istream &iss, RealType &v);
48 static bool readb(std::istream &iss, RealType &v);
49 FORWARD_STRING_METHODS(GraphType)
50};
51
52class TLP_SCOPE EdgeSetType : public TypeInterface<std::set<tlp::edge>> {
53public:
54 static void write(std::ostream &oss, const RealType &v);
55 static void writeb(std::ostream &oss, const RealType &v);
56 static bool read(std::istream &iss, RealType &v);
57 static bool readb(std::istream &iss, RealType &v);
58 FORWARD_STRING_METHODS(EdgeSetType)
59};
60
61class TLP_SCOPE DoubleType : public TypeInterface<double> {
62public:
63 static double undefinedValue();
64 static double defaultValue();
65 static void write(std::ostream &oss, const RealType &v) {
66 oss << v;
67 }
68 static bool read(std::istream &iss, RealType &v);
69 FORWARD_STRING_METHODS(DoubleType)
70};
71
72class TLP_SCOPE FloatType : public SerializableType<float> {
73public:
74 static float undefinedValue();
75 static float defaultValue();
76 static bool read(std::istream &iss, RealType &v);
77 FORWARD_STRING_METHODS(FloatType)
78};
79
80typedef SerializableVectorType<double, DoubleType, false> DoubleVectorType;
81
82class TLP_SCOPE IntegerType : public SerializableType<int> {
83public:
84 static int undefinedValue();
85 static int defaultValue();
86};
87
88class TLP_SCOPE LongType : public SerializableType<long> {
89public:
90 static long undefinedValue();
91 static long defaultValue();
92};
93
94class TLP_SCOPE UnsignedIntegerType : public SerializableType<unsigned int> {
95public:
96 static unsigned int undefinedValue();
97 static unsigned int defaultValue();
98};
99
100typedef SerializableVectorType<int, IntegerType, false> IntegerVectorType;
101typedef SerializableVectorType<unsigned int, UnsignedIntegerType, false> UnsignedIntegerVectorType;
102
103class TLP_SCOPE BooleanType : public TypeInterface<bool> {
104public:
105 static RealType undefinedValue();
106 static RealType defaultValue();
107 static void write(std::ostream &, const RealType &);
108 static bool read(std::istream &, RealType &, bool untilEnd = false);
109 static bool fromString(RealType &, const std::string &, bool untilEnd = false);
110 FORWARD_TOSTRING(BooleanType)
111};
112
113class TLP_SCOPE BooleanVectorType : public TypeInterface<std::vector<bool>> {
114public:
115 static void write(std::ostream &, const RealType &);
116 static void writeb(std::ostream &, const RealType &);
117 static bool read(std::istream &, RealType &, char openChar = '(', char sepChar = ',',
118 char closeChar = ')');
119 static bool read(const std::vector<std::string> &vs, RealType &v);
120 static bool tokenize(const std::string &, std::vector<std::string> &, char openChar = '(',
121 char sepChar = ',', char closeChar = ')');
122 static bool readb(std::istream &, RealType &);
123 FORWARD_STRING_METHODS(BooleanVectorType)
124};
125
126class TLP_SCOPE PointType : public SerializableType<tlp::Coord> {
127public:
128 static RealType undefinedValue();
129 static RealType defaultValue();
130 static bool read(std::istream &, RealType &);
131 static bool fromString(RealType &, const std::string &);
132 FORWARD_TOSTRING(PointType)
133};
134
135class TLP_SCOPE LineType : public SerializableVectorType<tlp::Coord, PointType, false> {
136public:
137 static bool read(std::istream &, RealType &, char openChar = '(', char sepChar = ',',
138 char closeChar = ')');
139 FORWARD_STRING_METHODS(LineType)
140};
141
142class TLP_SCOPE SizeType : public SerializableType<tlp::Size> {
143public:
144 static RealType undefinedValue();
145 static RealType defaultValue();
146 static bool read(std::istream &, RealType &);
147 static bool fromString(RealType &, const std::string &);
148 FORWARD_TOSTRING(SizeType)
149};
150
151typedef SerializableVectorType<tlp::Size, SizeType, true> SizeVectorType;
152
153class TLP_SCOPE StringType : public TypeInterface<std::string> {
154public:
155 static RealType undefinedValue();
156 static RealType defaultValue();
157
158 static void write(std::ostream &, const RealType &, char openCloseChar = '"');
159 static void writeb(std::ostream &, const RealType &);
160 static bool read(std::istream &, RealType &, char openChar = '"', char closeChar = '"');
161 static bool readb(std::istream &, RealType &);
162
163 static std::string toString(const RealType &v);
164 static bool fromString(RealType &v, const std::string &s);
165};
166
167class TLP_SCOPE StringVectorType : public TypeInterface<std::vector<std::string>> {
168public:
169 static void write(std::ostream &, const RealType &);
170 static void writeb(std::ostream &oss, const RealType &vStr);
171 static bool read(std::istream &, RealType &, char openChar = '(', char sepchar = ',',
172 char closeChar = ')');
173 static bool read(const std::vector<std::string> &vs, RealType &v) {
174 v.clear();
175 v.reserve(vs.size());
176 for (const std::string &s : vs)
177 v.push_back(s);
178
179 return true;
180 }
181 static bool tokenize(const std::string &s, std::vector<std::string> &v, char openChar = '(',
182 char sepChar = ',', char closeChar = ')') {
183 std::istringstream is(s);
184 return read(is, v, openChar, sepChar, closeChar);
185 }
186 static bool readb(std::istream &iss, RealType &vStr);
187 FORWARD_STRING_METHODS(StringVectorType)
188};
189
190class TLP_SCOPE ColorType : public TypeInterface<tlp::Color> {
191public:
192 static RealType undefinedValue();
193
194 static void write(std::ostream &, const RealType &);
195 static bool read(std::istream &, RealType &);
196
197 static std::string toString(const RealType &v);
198 static bool fromString(RealType &v, const std::string &s);
199};
200
201typedef SerializableVectorType<tlp::Color, ColorType, true> ColorVectorType;
202typedef SerializableVectorType<tlp::Coord, PointType, true> CoordVectorType;
203
204DECL_STORED_STRUCT(tlp::EdgeSetType::RealType)
205DECL_STORED_STRUCT(std::set<tlp::node>)
206DECL_STORED_STRUCT(tlp::DoubleVectorType::RealType)
207DECL_STORED_STRUCT(tlp::IntegerVectorType::RealType)
208DECL_STORED_STRUCT(tlp::BooleanVectorType::RealType)
209DECL_STORED_STRUCT(tlp::LineType::RealType)
210DECL_STORED_STRUCT(tlp::PointType::RealType)
211// DECL_STORED_STRUCT(tlp::SizeType::RealType) <=> PointType::RealType
212// DECL_STORED_STRUCT(tlp::SizeVectorType::RealType) <=> LineType::RealType
213DECL_STORED_STRUCT(tlp::StringType::RealType)
214DECL_STORED_STRUCT(tlp::StringVectorType::RealType)
215DECL_STORED_STRUCT(tlp::ColorVectorType::RealType)
216
217// template class to automate definition of serializers
218template <typename T>
219struct KnownTypeSerializer : public TypedDataSerializer<typename T::RealType> {
220 KnownTypeSerializer(const std::string &otn) : TypedDataSerializer<typename T::RealType>(otn) {}
221 KnownTypeSerializer(const char *otn)
222 : TypedDataSerializer<typename T::RealType>(std::string(otn)) {}
223
224 DataTypeSerializer *clone() const override {
225 return new KnownTypeSerializer<T>(this->outputTypeName);
226 }
227
228 void write(std::ostream &os, const typename T::RealType &v) override {
229 T::write(os, v);
230 }
231 bool read(std::istream &iss, typename T::RealType &v) override {
232 return T::read(iss, v);
233 }
234 bool setData(tlp::DataSet &ds, const std::string &prop, const std::string &value) override {
235 bool result = true;
236 typename T::RealType val;
237
238 if (value.empty())
239 val = T::defaultValue();
240 else
241 result = T::fromString(val, value);
242
243 ds.set(prop, val);
244 return result;
245 }
246};
247
248extern void initTypeSerializers();
249#ifdef _MSC_VER
250template class SerializableType<double>;
251template class SerializableType<float>;
252template class SerializableType<int>;
253template class SerializableType<long>;
254template class SerializableType<unsigned int>;
255template class SerializableType<tlp::Coord>;
256template class SerializableType<tlp::Size>;
257template class SerializableVectorType<double, DoubleType, false>;
258template class SerializableVectorType<int, IntegerType, false>;
259template class SerializableVectorType<unsigned int, UnsignedIntegerType, false>;
260template class SerializableVectorType<tlp::Coord, PointType, false>;
261template class SerializableVectorType<tlp::Size, SizeType, true>;
262template class SerializableVectorType<tlp::Color, ColorType, true>;
263template class SerializableVectorType<tlp::Coord, PointType, true>;
264template class TypeInterface<tlp::Graph *>;
265template class TypeInterface<std::set<tlp::edge>>;
266template class TypeInterface<bool>;
267template class TypeInterface<std::vector<bool>>;
268template class TypeInterface<std::vector<std::string>>;
269template class TypeInterface<tlp::Color>;
270template class TypeInterface<std::string>;
271
272template class AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>;
273template class AbstractVectorProperty<IntegerVectorType, tlp::IntegerType>;
274template class AbstractVectorProperty<BooleanVectorType, tlp::BooleanType>;
275template class AbstractVectorProperty<StringVectorType, tlp::StringType>;
276template class AbstractVectorProperty<ColorVectorType, tlp::ColorType>;
277template class AbstractVectorProperty<SizeVectorType, tlp::SizeType>;
278template class AbstractVectorProperty<CoordVectorType, tlp::PointType>;
279#endif
280} // namespace tlp
281
282#endif
283///@endcond
A container that can store data from any type.
Definition: DataSet.h:195
void set(const std::string &key, const T &value)
Stores a copy of the given param, associated with the key. The value must have a well-formed copy con...
Definition: DataSet.cxx:79