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();
81 static bool read(std::istream &iss, RealType &v);
82 FORWARD_STRING_METHODS(FloatType)
85 typedef SerializableVectorType<double, DoubleType, false> DoubleVectorType;
87 class TLP_SCOPE IntegerType :
public SerializableType<int> {
89 static int undefinedValue();
90 static int defaultValue();
93 class TLP_SCOPE LongType :
public SerializableType<long> {
95 static long undefinedValue();
96 static long defaultValue();
99 class TLP_SCOPE UnsignedIntegerType :
public SerializableType<unsigned int> {
101 static unsigned int undefinedValue();
102 static unsigned int defaultValue();
105 typedef SerializableVectorType<int, IntegerType, false> IntegerVectorType;
106 typedef SerializableVectorType<unsigned int, UnsignedIntegerType, false> UnsignedIntegerVectorType;
108 class TLP_SCOPE BooleanType :
public TypeInterface<bool> {
110 static RealType undefinedValue();
111 static RealType defaultValue();
112 static void write(std::ostream &,
const RealType &);
113 static bool read(std::istream &, RealType &,
bool untilEnd =
false);
114 static bool fromString(RealType &,
const std::string &,
bool untilEnd =
false);
115 FORWARD_TOSTRING(BooleanType)
118 class TLP_SCOPE BooleanVectorType :
public TypeInterface<std::vector<bool>> {
120 static void write(std::ostream &,
const RealType &);
121 static void writeb(std::ostream &,
const RealType &);
122 static bool read(std::istream &, RealType &,
char openChar =
'(',
char sepChar =
',',
123 char closeChar =
')');
124 static bool read(
const std::vector<std::string> &vs, RealType &v);
125 static bool tokenize(
const std::string &, std::vector<std::string> &,
char openChar =
'(',
126 char sepChar =
',',
char closeChar =
')');
127 static bool readb(std::istream &, RealType &);
128 FORWARD_STRING_METHODS(BooleanVectorType)
131 class TLP_SCOPE PointType :
public SerializableType<tlp::Coord> {
133 static RealType undefinedValue();
134 static RealType defaultValue();
135 static bool read(std::istream &, RealType &);
136 static bool fromString(RealType &,
const std::string &);
137 FORWARD_TOSTRING(PointType)
140 class TLP_SCOPE LineType :
public SerializableVectorType<tlp::Coord, PointType, false> {
142 static bool read(std::istream &, RealType &,
char openChar =
'(',
char sepChar =
',',
143 char closeChar =
')');
144 FORWARD_STRING_METHODS(LineType)
147 class TLP_SCOPE SizeType :
public SerializableType<tlp::Size> {
149 static RealType undefinedValue();
150 static RealType defaultValue();
151 static bool read(std::istream &, RealType &);
152 static bool fromString(RealType &,
const std::string &);
153 FORWARD_TOSTRING(SizeType)
156 typedef SerializableVectorType<tlp::Size, SizeType, true> SizeVectorType;
158 class TLP_SCOPE StringType :
public TypeInterface<std::string> {
160 static RealType undefinedValue();
161 static RealType defaultValue();
163 static void write(std::ostream &,
const RealType &,
char openCloseChar =
'"');
164 static void writeb(std::ostream &,
const RealType &);
165 static bool read(std::istream &, RealType &,
char openChar =
'"',
char closeChar =
'"');
166 static bool readb(std::istream &, RealType &);
168 static std::string toString(
const RealType &v);
169 static bool fromString(RealType &v,
const std::string &s);
172 class TLP_SCOPE StringVectorType :
public TypeInterface<std::vector<std::string>> {
174 static void write(std::ostream &,
const RealType &);
175 static void writeb(std::ostream &oss,
const RealType &vStr);
176 static bool read(std::istream &, RealType &,
char openChar =
'(',
char sepchar =
',',
177 char closeChar =
')');
178 static bool read(
const std::vector<std::string> &vs, RealType &v) {
180 v.reserve(vs.size());
181 for (
const std::string &s : vs)
186 static bool tokenize(
const std::string &s, std::vector<std::string> &v,
char openChar =
'(',
187 char sepChar =
',',
char closeChar =
')') {
188 std::istringstream is(s);
189 return read(is, v, openChar, sepChar, closeChar);
191 static bool readb(std::istream &iss, RealType &vStr);
192 FORWARD_STRING_METHODS(StringVectorType)
195 class TLP_SCOPE ColorType :
public TypeInterface<tlp::Color> {
197 static RealType undefinedValue();
199 static void write(std::ostream &,
const RealType &);
200 static bool read(std::istream &, RealType &);
202 static std::string toString(
const RealType &v);
203 static bool fromString(RealType &v,
const std::string &s);
206 typedef SerializableVectorType<tlp::Color, ColorType, true> ColorVectorType;
207 typedef SerializableVectorType<tlp::Coord, PointType, true> CoordVectorType;
209 DECL_STORED_STRUCT(tlp::EdgeSetType::RealType)
210 DECL_STORED_STRUCT(std::set<tlp::node>)
211 DECL_STORED_STRUCT(tlp::DoubleVectorType::RealType)
212 DECL_STORED_STRUCT(tlp::IntegerVectorType::RealType)
213 DECL_STORED_STRUCT(tlp::BooleanVectorType::RealType)
214 DECL_STORED_STRUCT(tlp::LineType::RealType)
215 DECL_STORED_STRUCT(tlp::PointType::RealType)
218 DECL_STORED_STRUCT(tlp::StringType::RealType)
219 DECL_STORED_STRUCT(tlp::StringVectorType::RealType)
220 DECL_STORED_STRUCT(tlp::ColorVectorType::RealType)
223 template <
typename T>
224 struct KnownTypeSerializer :
public TypedDataSerializer<typename T::RealType> {
225 KnownTypeSerializer(
const std::string &otn) : TypedDataSerializer<typename T::RealType>(otn) {}
226 KnownTypeSerializer(
const char *otn)
227 : TypedDataSerializer<typename T::RealType>(
std::string(otn)) {}
229 DataTypeSerializer *clone()
const override {
230 return new KnownTypeSerializer<T>(this->outputTypeName);
233 void write(std::ostream &os,
const typename T::RealType &v)
override {
236 bool read(std::istream &iss,
typename T::RealType &v)
override {
237 return T::read(iss, v);
239 bool setData(
tlp::DataSet &ds,
const std::string &prop,
const std::string &value)
override {
241 typename T::RealType val;
244 val = T::defaultValue();
246 result = T::fromString(val, value);
253 extern void initTypeSerializers();
255 template class SerializableType<double>;
256 template class SerializableType<float>;
257 template class SerializableType<int>;
258 template class SerializableType<long>;
259 template class SerializableType<unsigned int>;
260 template class SerializableType<tlp::Coord>;
261 template class SerializableType<tlp::Size>;
262 template class SerializableVectorType<double, DoubleType, false>;
263 template class SerializableVectorType<int, IntegerType, false>;
264 template class SerializableVectorType<unsigned int, UnsignedIntegerType, false>;
265 template class SerializableVectorType<tlp::Coord, PointType, false>;
266 template class SerializableVectorType<tlp::Size, SizeType, true>;
267 template class SerializableVectorType<tlp::Color, ColorType, true>;
268 template class SerializableVectorType<tlp::Coord, PointType, true>;
269 template class TypeInterface<tlp::Graph *>;
270 template class TypeInterface<std::set<tlp::edge>>;
271 template class TypeInterface<bool>;
272 template class TypeInterface<std::vector<bool>>;
273 template class TypeInterface<std::vector<std::string>>;
274 template class TypeInterface<tlp::Color>;
275 template class TypeInterface<std::string>;
277 template class AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>;
278 template class AbstractVectorProperty<IntegerVectorType, tlp::IntegerType>;
279 template class AbstractVectorProperty<BooleanVectorType, tlp::BooleanType>;
280 template class AbstractVectorProperty<StringVectorType, tlp::StringType>;
281 template class AbstractVectorProperty<ColorVectorType, tlp::ColorType>;
282 template class AbstractVectorProperty<SizeVectorType, tlp::SizeType>;
283 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.