Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces 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 1 and Inria Bordeaux - Sud Ouest
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/AbstractProperty.h>
38 #include <tulip/TypeInterface.h>
39 #include <tulip/SerializableType.h>
40 
41 namespace tlp {
42 
43 class Graph;
44 
45 class TLP_SCOPE GraphType: public TypeInterface<tlp::Graph*> {
46 public:
47  static RealType undefinedValue();
48  static RealType defaultValue();
49  static void write(std::ostream &oss, const RealType &v);
50  static bool read(std::istream& iss, RealType& v);
51  FORWARD_STRING_METHODS(GraphType)
52 };
53 
54 class TLP_SCOPE EdgeSetType: public TypeInterface<std::set<tlp::edge> > {
55 public:
56  static void write(std::ostream &oss, const RealType &v);
57  static bool read(std::istream& iss, RealType& v);
58  FORWARD_STRING_METHODS(EdgeSetType)
59 };
60 
61 class TLP_SCOPE DoubleType: public TypeInterface<double> {
62 public:
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 
72 class TLP_SCOPE FloatType: public SerializableType<float> {
73 public:
74  static float undefinedValue();
75  static float defaultValue();
76 };
77 
78 typedef SerializableVectorType<double,false> DoubleVectorType;
79 
80 class TLP_SCOPE IntegerType: public SerializableType<int> {
81 public:
82  static int undefinedValue();
83  static int defaultValue();
84 };
85 
86 class TLP_SCOPE LongType: public SerializableType<long> {
87 public:
88  static long undefinedValue();
89  static long defaultValue();
90 };
91 
92 class TLP_SCOPE UnsignedIntegerType: public SerializableType<unsigned int> {
93 public:
94  static unsigned int undefinedValue();
95  static unsigned int defaultValue();
96 };
97 
98 typedef SerializableVectorType<int,false> IntegerVectorType;
99 typedef SerializableVectorType<unsigned int,false> UnsignedIntegerVectorType;
100 
101 class TLP_SCOPE BooleanType: public TypeInterface<bool> {
102 public:
103  static RealType undefinedValue();
104  static RealType defaultValue();
105  static void write(std::ostream&, const RealType&);
106  static bool read(std::istream&, RealType&);
107  FORWARD_STRING_METHODS(BooleanType)
108 };
109 
110 class TLP_SCOPE BooleanVectorType: public TypeInterface<std::vector<bool> > {
111 public:
112  static void write(std::ostream&, const RealType&);
113  static bool read(std::istream&, RealType&);
114  FORWARD_STRING_METHODS(BooleanVectorType)
115 };
116 
117 class TLP_SCOPE LineType: public SerializableVectorType<tlp::Coord,false> {
118 public:
119  static bool read(std::istream&, RealType&);
120  FORWARD_STRING_METHODS(LineType)
121 };
122 
123 class TLP_SCOPE PointType: public SerializableType<tlp::Coord> {
124 public:
125  static RealType undefinedValue();
126  static RealType defaultValue();
127  static bool read(std::istream&, RealType&);
128  static bool fromString(RealType &, const std::string &);
129  FORWARD_TOSTRING(PointType)
130 };
131 
132 class TLP_SCOPE SizeType: public SerializableType<tlp::Size> {
133 public:
134  static RealType undefinedValue();
135  static RealType defaultValue();
136  static bool read(std::istream&, RealType&);
137  static bool fromString(RealType &, const std::string &);
138  FORWARD_TOSTRING(SizeType)
139 };
140 
141 typedef SerializableVectorType<tlp::Size,true> SizeVectorType;
142 
143 class TLP_SCOPE StringType: public TypeInterface<std::string> {
144 public:
145  static RealType undefinedValue();
146  static RealType defaultValue();
147 
148  static void write(std::ostream&, const RealType&);
149  static bool read(std::istream&, RealType&);
150 
151  static std::string toString(const RealType &v);
152  static bool fromString(RealType &v, const std::string &s);
153 };
154 
155 class TLP_SCOPE StringVectorType: public TypeInterface<std::vector<std::string> > {
156 public:
157  static void write(std::ostream&, const RealType&);
158  static bool read(std::istream&, RealType&);
159  FORWARD_STRING_METHODS(StringVectorType)
160 };
161 
162 class TLP_SCOPE ColorType: public TypeInterface<tlp::Color> {
163 public:
164  static RealType undefinedValue();
165 
166  static void write(std::ostream&, const RealType&);
167  static bool read(std::istream&, RealType&);
168 
169  static std::string toString(const RealType &v);
170  static bool fromString(RealType &v, const std::string &s);
171 };
172 
173 typedef SerializableVectorType<tlp::Color,true> ColorVectorType;
174 typedef SerializableVectorType<tlp::Coord,true> CoordVectorType;
175 
176 DECL_STORED_STRUCT(tlp::EdgeSetType::RealType)
177 DECL_STORED_STRUCT(std::set<tlp::node>)
178 DECL_STORED_STRUCT(tlp::DoubleVectorType::RealType)
179 DECL_STORED_STRUCT(tlp::IntegerVectorType::RealType)
180 DECL_STORED_STRUCT(tlp::BooleanVectorType::RealType)
181 DECL_STORED_STRUCT(tlp::LineType::RealType)
182 DECL_STORED_STRUCT(tlp::PointType::RealType)
183 //DECL_STORED_STRUCT(tlp::SizeType::RealType)
184 //DECL_STORED_STRUCT(tlp::SizeVectorType::RealType)
185 DECL_STORED_STRUCT(tlp::StringType::RealType)
186 DECL_STORED_STRUCT(tlp::StringVectorType::RealType)
187 DECL_STORED_STRUCT(tlp::ColorVectorType::RealType)
188 
189 // template class to automatize definition of serializers
190 template<typename T>
191 struct KnownTypeSerializer :public TypedDataSerializer<typename T::RealType> {
192  KnownTypeSerializer(const std::string& otn):TypedDataSerializer<typename T::RealType>(otn) {}
193  KnownTypeSerializer(const char* otn):TypedDataSerializer<typename T::RealType>(std::string(otn)) {}
194 
195  DataTypeSerializer* clone() const {
196  return new KnownTypeSerializer<T>(this->outputTypeName);
197  }
198 
199  void write(std::ostream& os, const typename T::RealType& v) {
200  T::write(os, v);
201  }
202  bool read(std::istream& iss, typename T::RealType& v) {
203  return T::read(iss, v);
204  }
205  bool setData(tlp::DataSet& ds, const std::string& prop, const std::string& value) {
206  bool result = true;
207  typename T::RealType val;
208 
209  if (value.empty())
210  val = T::defaultValue();
211  else
212  result = T::fromString(val, value);
213 
214  ds.set<typename T::RealType>(prop, val);
215  return result;
216  }
217 };
218 
219 extern void initTypeSerializers();
220 #ifdef _MSC_VER
221 template class SerializableType<double>;
222 template class SerializableType<float>;
223 template class SerializableType<int>;
224 template class SerializableType<long>;
225 template class SerializableType<unsigned int>;
226 template class SerializableType<tlp::Coord>;
227 template class SerializableType<tlp::Size>;
228 template class SerializableVectorType<double,false>;
229 template class SerializableVectorType<int,false>;
230 template class SerializableVectorType<tlp::Coord,false>;
231 template class SerializableVectorType<tlp::Size,true>;
232 template class SerializableVectorType<tlp::Color,true>;
233 template class SerializableVectorType<tlp::Coord,true>;
234 template class TypeInterface<tlp::Graph*>;
235 template class TypeInterface<std::set<tlp::edge> >;
236 template class TypeInterface<bool>;
237 template class TypeInterface<std::vector<bool> >;
238 template class TypeInterface<std::vector<std::string> >;
239 template class TypeInterface<tlp::Color>;
240 template class TypeInterface<std::string>;
241 
242 template class AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>;
243 template class AbstractVectorProperty<IntegerVectorType, tlp::IntegerType>;
244 template class AbstractVectorProperty<BooleanVectorType, tlp::BooleanType>;
245 template class AbstractVectorProperty<StringVectorType, tlp::StringType>;
246 template class AbstractVectorProperty<ColorVectorType, tlp::ColorType>;
247 template class AbstractVectorProperty<SizeVectorType, tlp::SizeType>;
248 template class AbstractVectorProperty<CoordVectorType, tlp::PointType>;
249 #endif
250 }
251 
252 
253 #endif
254 ///@endcond