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>
41 class TLP_SCOPE GraphType :
public TypeInterface<tlp::Graph *> {
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)
52 class TLP_SCOPE EdgeSetType :
public TypeInterface<std::set<tlp::edge>> {
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)
61 class TLP_SCOPE DoubleType :
public TypeInterface<double> {
63 static double undefinedValue();
64 static double defaultValue();
65 static void write(std::ostream &oss,
const RealType &v) {
68 static bool read(std::istream &iss, RealType &v);
69 FORWARD_STRING_METHODS(DoubleType)
72 class TLP_SCOPE FloatType :
public SerializableType<float> {
74 static float undefinedValue();
75 static float defaultValue();
76 static bool read(std::istream &iss, RealType &v);
77 FORWARD_STRING_METHODS(FloatType)
80 typedef SerializableVectorType<double, DoubleType, false> DoubleVectorType;
82 class TLP_SCOPE IntegerType :
public SerializableType<int> {
84 static int undefinedValue();
85 static int defaultValue();
88 class TLP_SCOPE LongType :
public SerializableType<long> {
90 static long undefinedValue();
91 static long defaultValue();
94 class TLP_SCOPE UnsignedIntegerType :
public SerializableType<unsigned int> {
96 static unsigned int undefinedValue();
97 static unsigned int defaultValue();
100 typedef SerializableVectorType<int, IntegerType, false> IntegerVectorType;
101 typedef SerializableVectorType<unsigned int, UnsignedIntegerType, false> UnsignedIntegerVectorType;
103 class TLP_SCOPE BooleanType :
public TypeInterface<bool> {
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)
113 class TLP_SCOPE BooleanVectorType :
public TypeInterface<std::vector<bool>> {
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)
126 class TLP_SCOPE PointType :
public SerializableType<tlp::Coord> {
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)
135 class TLP_SCOPE LineType :
public SerializableVectorType<tlp::Coord, PointType, false> {
137 static bool read(std::istream &, RealType &,
char openChar =
'(',
char sepChar =
',',
138 char closeChar =
')');
139 FORWARD_STRING_METHODS(LineType)
142 class TLP_SCOPE SizeType :
public SerializableType<tlp::Size> {
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)
151 typedef SerializableVectorType<tlp::Size, SizeType, true> SizeVectorType;
153 class TLP_SCOPE StringType :
public TypeInterface<std::string> {
155 static RealType undefinedValue();
156 static RealType defaultValue();
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 &);
163 static std::string toString(
const RealType &v);
164 static bool fromString(RealType &v,
const std::string &s);
167 class TLP_SCOPE StringVectorType :
public TypeInterface<std::vector<std::string>> {
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) {
175 v.reserve(vs.size());
176 for (
const std::string &s : vs)
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);
186 static bool readb(std::istream &iss, RealType &vStr);
187 FORWARD_STRING_METHODS(StringVectorType)
190 class TLP_SCOPE ColorType :
public TypeInterface<tlp::Color> {
192 static RealType undefinedValue();
194 static void write(std::ostream &,
const RealType &);
195 static bool read(std::istream &, RealType &);
197 static std::string toString(
const RealType &v);
198 static bool fromString(RealType &v,
const std::string &s);
201 typedef SerializableVectorType<tlp::Color, ColorType, true> ColorVectorType;
202 typedef SerializableVectorType<tlp::Coord, PointType, true> CoordVectorType;
204 DECL_STORED_STRUCT(tlp::EdgeSetType::RealType)
205 DECL_STORED_STRUCT(std::set<tlp::node>)
206 DECL_STORED_STRUCT(tlp::DoubleVectorType::RealType)
207 DECL_STORED_STRUCT(tlp::IntegerVectorType::RealType)
208 DECL_STORED_STRUCT(tlp::BooleanVectorType::RealType)
209 DECL_STORED_STRUCT(tlp::LineType::RealType)
210 DECL_STORED_STRUCT(tlp::PointType::RealType)
213 DECL_STORED_STRUCT(tlp::StringType::RealType)
214 DECL_STORED_STRUCT(tlp::StringVectorType::RealType)
215 DECL_STORED_STRUCT(tlp::ColorVectorType::RealType)
218 template <
typename T>
219 struct 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)) {}
224 DataTypeSerializer *clone()
const override {
225 return new KnownTypeSerializer<T>(this->outputTypeName);
228 void write(std::ostream &os,
const typename T::RealType &v)
override {
231 bool read(std::istream &iss,
typename T::RealType &v)
override {
232 return T::read(iss, v);
234 bool setData(
tlp::DataSet &ds,
const std::string &prop,
const std::string &value)
override {
236 typename T::RealType val;
239 val = T::defaultValue();
241 result = T::fromString(val, value);
248 extern void initTypeSerializers();
250 template class SerializableType<double>;
251 template class SerializableType<float>;
252 template class SerializableType<int>;
253 template class SerializableType<long>;
254 template class SerializableType<unsigned int>;
255 template class SerializableType<tlp::Coord>;
256 template class SerializableType<tlp::Size>;
257 template class SerializableVectorType<double, DoubleType, false>;
258 template class SerializableVectorType<int, IntegerType, false>;
259 template class SerializableVectorType<unsigned int, UnsignedIntegerType, false>;
260 template class SerializableVectorType<tlp::Coord, PointType, false>;
261 template class SerializableVectorType<tlp::Size, SizeType, true>;
262 template class SerializableVectorType<tlp::Color, ColorType, true>;
263 template class SerializableVectorType<tlp::Coord, PointType, true>;
264 template class TypeInterface<tlp::Graph *>;
265 template class TypeInterface<std::set<tlp::edge>>;
266 template class TypeInterface<bool>;
267 template class TypeInterface<std::vector<bool>>;
268 template class TypeInterface<std::vector<std::string>>;
269 template class TypeInterface<tlp::Color>;
270 template class TypeInterface<std::string>;
272 template class AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>;
273 template class AbstractVectorProperty<IntegerVectorType, tlp::IntegerType>;
274 template class AbstractVectorProperty<BooleanVectorType, tlp::BooleanType>;
275 template class AbstractVectorProperty<StringVectorType, tlp::StringType>;
276 template class AbstractVectorProperty<ColorVectorType, tlp::ColorType>;
277 template class AbstractVectorProperty<SizeVectorType, tlp::SizeType>;
278 template class AbstractVectorProperty<CoordVectorType, tlp::PointType>;
A container that can store data from any type.
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...