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>
45 class TLP_SCOPE GraphType:
public TypeInterface<tlp::Graph*> {
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)
54 class TLP_SCOPE EdgeSetType:
public TypeInterface<std::set<tlp::edge> > {
56 static void write(std::ostream &oss,
const RealType &v);
57 static bool read(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();
78 typedef SerializableVectorType<double,false> DoubleVectorType;
80 class TLP_SCOPE IntegerType:
public SerializableType<int> {
82 static int undefinedValue();
83 static int defaultValue();
86 class TLP_SCOPE LongType:
public SerializableType<long> {
88 static long undefinedValue();
89 static long defaultValue();
92 class TLP_SCOPE UnsignedIntegerType:
public SerializableType<unsigned int> {
94 static unsigned int undefinedValue();
95 static unsigned int defaultValue();
98 typedef SerializableVectorType<int,false> IntegerVectorType;
99 typedef SerializableVectorType<unsigned int,false> UnsignedIntegerVectorType;
101 class TLP_SCOPE BooleanType:
public TypeInterface<bool> {
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)
110 class TLP_SCOPE BooleanVectorType:
public TypeInterface<std::vector<bool> > {
112 static void write(std::ostream&,
const RealType&);
113 static bool read(std::istream&, RealType&);
114 FORWARD_STRING_METHODS(BooleanVectorType)
117 class TLP_SCOPE LineType:
public SerializableVectorType<tlp::Coord,false> {
119 static bool read(std::istream&, RealType&);
120 FORWARD_STRING_METHODS(LineType)
123 class TLP_SCOPE PointType:
public SerializableType<tlp::Coord> {
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)
132 class TLP_SCOPE SizeType:
public SerializableType<tlp::Size> {
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)
141 typedef SerializableVectorType<tlp::Size,true> SizeVectorType;
143 class TLP_SCOPE StringType:
public TypeInterface<std::string> {
145 static RealType undefinedValue();
146 static RealType defaultValue();
148 static void write(std::ostream&,
const RealType&);
149 static bool read(std::istream&, RealType&);
151 static std::string toString(
const RealType &v);
152 static bool fromString(RealType &v,
const std::string &s);
155 class TLP_SCOPE StringVectorType:
public TypeInterface<std::vector<std::string> > {
157 static void write(std::ostream&,
const RealType&);
158 static bool read(std::istream&, RealType&);
159 FORWARD_STRING_METHODS(StringVectorType)
162 class TLP_SCOPE ColorType:
public TypeInterface<tlp::Color> {
164 static RealType undefinedValue();
166 static void write(std::ostream&,
const RealType&);
167 static bool read(std::istream&, RealType&);
169 static std::string toString(
const RealType &v);
170 static bool fromString(RealType &v,
const std::string &s);
173 typedef SerializableVectorType<tlp::Color,true> ColorVectorType;
174 typedef SerializableVectorType<tlp::Coord,true> CoordVectorType;
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)
185 DECL_STORED_STRUCT(tlp::StringType::RealType)
186 DECL_STORED_STRUCT(tlp::StringVectorType::RealType)
187 DECL_STORED_STRUCT(tlp::ColorVectorType::RealType)
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)) {}
195 DataTypeSerializer* clone()
const {
196 return new KnownTypeSerializer<T>(this->outputTypeName);
199 void write(std::ostream& os,
const typename T::RealType& v) {
202 bool read(std::istream& iss,
typename T::RealType& v) {
203 return T::read(iss, v);
205 bool setData(
tlp::DataSet& ds,
const std::string& prop,
const std::string& value) {
207 typename T::RealType val;
210 val = T::defaultValue();
212 result = T::fromString(val, value);
214 ds.
set<
typename T::RealType>(prop, val);
219 extern void initTypeSerializers();
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>;
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>;