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