31 #include <tulip/StoredType.h>
32 #include <tulip/Coord.h>
33 #include <tulip/Size.h>
34 #include <tulip/Color.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>
46 class TLP_SCOPE GraphType:
public TypeInterface<tlp::Graph*> {
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)
57 class TLP_SCOPE EdgeSetType:
public TypeInterface<std::set<tlp::edge> > {
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)
66 class TLP_SCOPE DoubleType:
public TypeInterface<double> {
68 static double undefinedValue();
69 static double defaultValue();
70 static void write(std::ostream &oss,
const RealType &v) {
73 static bool read(std::istream& iss, RealType& v);
74 FORWARD_STRING_METHODS(DoubleType)
77 class TLP_SCOPE FloatType:
public SerializableType<float> {
79 static float undefinedValue();
80 static float defaultValue();
83 typedef SerializableVectorType<double,false> DoubleVectorType;
85 class TLP_SCOPE IntegerType:
public SerializableType<int> {
87 static int undefinedValue();
88 static int defaultValue();
91 class TLP_SCOPE LongType:
public SerializableType<long> {
93 static long undefinedValue();
94 static long defaultValue();
97 class TLP_SCOPE UnsignedIntegerType:
public SerializableType<unsigned int> {
99 static unsigned int undefinedValue();
100 static unsigned int defaultValue();
103 typedef SerializableVectorType<int,false> IntegerVectorType;
104 typedef SerializableVectorType<unsigned int,false> UnsignedIntegerVectorType;
106 class TLP_SCOPE BooleanType:
public TypeInterface<bool> {
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)
116 class TLP_SCOPE BooleanVectorType:
public TypeInterface<std::vector<bool> > {
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)
126 class TLP_SCOPE LineType:
public SerializableVectorType<tlp::Coord,false> {
128 static bool read(std::istream&, RealType&,
char openChar =
'(',
129 char sepChar =
',',
char closeChar =
')');
130 FORWARD_STRING_METHODS(LineType)
133 class TLP_SCOPE PointType:
public SerializableType<tlp::Coord> {
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)
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,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&,
161 char openChar =
'"',
char closeChar =
'"');
162 static bool readb(std::istream&, RealType&);
164 static std::string toString(
const RealType &v);
165 static bool fromString(RealType &v,
const std::string &s);
168 class TLP_SCOPE StringVectorType:
public TypeInterface<std::vector<std::string> > {
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)
178 class TLP_SCOPE ColorType:
public TypeInterface<tlp::Color> {
180 static RealType undefinedValue();
182 static void write(std::ostream&,
const RealType&);
183 static bool read(std::istream&, RealType&);
185 static std::string toString(
const RealType &v);
186 static bool fromString(RealType &v,
const std::string &s);
189 typedef SerializableVectorType<tlp::Color,true> ColorVectorType;
190 typedef SerializableVectorType<tlp::Coord,true> CoordVectorType;
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)
201 DECL_STORED_STRUCT(tlp::StringType::RealType)
202 DECL_STORED_STRUCT(tlp::StringVectorType::RealType)
203 DECL_STORED_STRUCT(tlp::ColorVectorType::RealType)
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)) {}
211 DataTypeSerializer* clone()
const {
212 return new KnownTypeSerializer<T>(this->outputTypeName);
215 void write(std::ostream& os,
const typename T::RealType& v) {
218 bool read(std::istream& iss,
typename T::RealType& v) {
219 return T::read(iss, v);
221 bool setData(
tlp::DataSet& ds,
const std::string& prop,
const std::string& value) {
223 typename T::RealType val;
226 val = T::defaultValue();
228 result = T::fromString(val, value);
235 extern void initTypeSerializers();
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>;
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>;
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...
A container that can store data from any type.