Tulip  4.8.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 };
82 
83 typedef SerializableVectorType<double,false> DoubleVectorType;
84 
85 class TLP_SCOPE IntegerType: public SerializableType<int> {
86 public:
87  static int undefinedValue();
88  static int defaultValue();
89 };
90 
91 class TLP_SCOPE LongType: public SerializableType<long> {
92 public:
93  static long undefinedValue();
94  static long defaultValue();
95 };
96 
97 class TLP_SCOPE UnsignedIntegerType: public SerializableType<unsigned int> {
98 public:
99  static unsigned int undefinedValue();
100  static unsigned int defaultValue();
101 };
102 
103 typedef SerializableVectorType<int,false> IntegerVectorType;
104 typedef SerializableVectorType<unsigned int,false> UnsignedIntegerVectorType;
105 
106 class TLP_SCOPE BooleanType: public TypeInterface<bool> {
107 public:
108  static RealType undefinedValue();
109  static RealType defaultValue();
110  static void write(std::ostream&, const RealType&);
111  static bool read(std::istream&, RealType&, bool untilEnd = false);
112  static bool fromString(RealType &, const std::string &, bool untilEnd = false);
113  FORWARD_TOSTRING(BooleanType)
114 };
115 
116 class TLP_SCOPE BooleanVectorType: public TypeInterface<std::vector<bool> > {
117 public:
118  static void write(std::ostream&, const RealType&);
119  static void writeb(std::ostream&, const RealType&);
120  static bool read(std::istream&, RealType&, char openChar = '(',
121  char sepChar = ',', char closeChar = ')');
122  static bool readb(std::istream&, RealType&);
123  FORWARD_STRING_METHODS(BooleanVectorType)
124 };
125 
126 class TLP_SCOPE LineType: public SerializableVectorType<tlp::Coord,false> {
127 public:
128  static bool read(std::istream&, RealType&, char openChar = '(',
129  char sepChar = ',', char closeChar = ')');
130  FORWARD_STRING_METHODS(LineType)
131 };
132 
133 class TLP_SCOPE PointType: public SerializableType<tlp::Coord> {
134 public:
135  static RealType undefinedValue();
136  static RealType defaultValue();
137  static bool read(std::istream&, RealType&);
138  static bool fromString(RealType &, const std::string &);
139  FORWARD_TOSTRING(PointType)
140 };
141 
142 class TLP_SCOPE SizeType: public SerializableType<tlp::Size> {
143 public:
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 
151 typedef SerializableVectorType<tlp::Size,true> SizeVectorType;
152 
153 class TLP_SCOPE StringType: public TypeInterface<std::string> {
154 public:
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&,
161  char openChar = '"', char closeChar = '"');
162  static bool readb(std::istream&, RealType&);
163 
164  static std::string toString(const RealType &v);
165  static bool fromString(RealType &v, const std::string &s);
166 };
167 
168 class TLP_SCOPE StringVectorType: public TypeInterface<std::vector<std::string> > {
169 public:
170  static void write(std::ostream&, const RealType&);
171  static void writeb(std::ostream& oss, const RealType& vStr);
172  static bool read(std::istream&, RealType&, char openChar = '(',
173  char sepchar = ',', char closeChar = ')');
174  static bool readb(std::istream& iss, RealType& vStr);
175  FORWARD_STRING_METHODS(StringVectorType)
176 };
177 
178 class TLP_SCOPE ColorType: public TypeInterface<tlp::Color> {
179 public:
180  static RealType undefinedValue();
181 
182  static void write(std::ostream&, const RealType&);
183  static bool read(std::istream&, RealType&);
184 
185  static std::string toString(const RealType &v);
186  static bool fromString(RealType &v, const std::string &s);
187 };
188 
189 typedef SerializableVectorType<tlp::Color,true> ColorVectorType;
190 typedef SerializableVectorType<tlp::Coord,true> CoordVectorType;
191 
192 DECL_STORED_STRUCT(tlp::EdgeSetType::RealType)
193 DECL_STORED_STRUCT(std::set<tlp::node>)
194 DECL_STORED_STRUCT(tlp::DoubleVectorType::RealType)
195 DECL_STORED_STRUCT(tlp::IntegerVectorType::RealType)
196 DECL_STORED_STRUCT(tlp::BooleanVectorType::RealType)
197 DECL_STORED_STRUCT(tlp::LineType::RealType)
198 DECL_STORED_STRUCT(tlp::PointType::RealType)
199 //DECL_STORED_STRUCT(tlp::SizeType::RealType) <=> PointType::RealType
200 //DECL_STORED_STRUCT(tlp::SizeVectorType::RealType) <=> LineType::RealType
201 DECL_STORED_STRUCT(tlp::StringType::RealType)
202 DECL_STORED_STRUCT(tlp::StringVectorType::RealType)
203 DECL_STORED_STRUCT(tlp::ColorVectorType::RealType)
204 
205 // template class to automatize definition of serializers
206 template<typename T>
207 struct KnownTypeSerializer :public TypedDataSerializer<typename T::RealType> {
208  KnownTypeSerializer(const std::string& otn):TypedDataSerializer<typename T::RealType>(otn) {}
209  KnownTypeSerializer(const char* otn):TypedDataSerializer<typename T::RealType>(std::string(otn)) {}
210 
211  DataTypeSerializer* clone() const {
212  return new KnownTypeSerializer<T>(this->outputTypeName);
213  }
214 
215  void write(std::ostream& os, const typename T::RealType& v) {
216  T::write(os, v);
217  }
218  bool read(std::istream& iss, typename T::RealType& v) {
219  return T::read(iss, v);
220  }
221  bool setData(tlp::DataSet& ds, const std::string& prop, const std::string& value) {
222  bool result = true;
223  typename T::RealType val;
224 
225  if (value.empty())
226  val = T::defaultValue();
227  else
228  result = T::fromString(val, value);
229 
230  ds.set(prop, val);
231  return result;
232  }
233 };
234 
235 extern void initTypeSerializers();
236 #ifdef _MSC_VER
237 template class SerializableType<double>;
238 template class SerializableType<float>;
239 template class SerializableType<int>;
240 template class SerializableType<long>;
241 template class SerializableType<unsigned int>;
242 template class SerializableType<tlp::Coord>;
243 template class SerializableType<tlp::Size>;
244 template class SerializableVectorType<double,false>;
245 template class SerializableVectorType<int,false>;
246 template class SerializableVectorType<tlp::Coord,false>;
247 template class SerializableVectorType<tlp::Size,true>;
248 template class SerializableVectorType<tlp::Color,true>;
249 template class SerializableVectorType<tlp::Coord,true>;
250 template class TypeInterface<tlp::Graph*>;
251 template class TypeInterface<std::set<tlp::edge> >;
252 template class TypeInterface<bool>;
253 template class TypeInterface<std::vector<bool> >;
254 template class TypeInterface<std::vector<std::string> >;
255 template class TypeInterface<tlp::Color>;
256 template class TypeInterface<std::string>;
257 
258 template class AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>;
259 template class AbstractVectorProperty<IntegerVectorType, tlp::IntegerType>;
260 template class AbstractVectorProperty<BooleanVectorType, tlp::BooleanType>;
261 template class AbstractVectorProperty<StringVectorType, tlp::StringType>;
262 template class AbstractVectorProperty<ColorVectorType, tlp::ColorType>;
263 template class AbstractVectorProperty<SizeVectorType, tlp::SizeType>;
264 template class AbstractVectorProperty<CoordVectorType, tlp::PointType>;
265 #endif
266 }
267 
268 
269 #endif
270 ///@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