Line data Source code
1 :
2 : // Implementations of Item value conversions
3 : //
4 : // note that these are classes declared in a source file;
5 : // ItemConversion::FromString is the one and only interface
6 : // for creating conversions
7 :
8 :
9 : #include "wibmod/WIB1/ItemConversion.hh"
10 :
11 : #include <stdio.h> // sscanf
12 : #include <boost/foreach.hpp>
13 :
14 : using boost::unordered_map;
15 :
16 : namespace itemconv {
17 :
18 : #define ARGS(...) __VA_ARGS__
19 : #define EXPAND(x) x
20 : #define STRIP(x) EXPAND( ARGS x )
21 : #define DEFINE_CONVERSION_CLASS(name,body) \
22 : class itemconv_##name : public ItemConversion { STRIP(body) };
23 : /*#define DEFINE_CONVERSION_CLASS_END \
24 : public: \
25 : itemconv_##name (unordered_map<std::string, std::string> params) { \
26 : init(params); \
27 : } \
28 : };*/
29 : #include "wibmod/WIB1/conversions-impl.hh"
30 : #undef DEFINE_CONVERSION_CLASS
31 : #undef STRIP
32 : #undef EXPAND
33 : #undef STRIP
34 :
35 : }
36 :
37 0 : ItemConversion * ItemConversion::FromString(std::string convstring) {
38 0 : unordered_map<std::string, std::string> params;
39 0 : int i = 0;
40 0 : while (i < (int)convstring.size() && convstring[i]!=' ') i++;
41 0 : std::string fnname = std::string(convstring.c_str(), i);
42 0 : while (i < (int)convstring.size()) {
43 0 : while (i < (int)convstring.size() && convstring[i]==' ') i++;
44 0 : int pair_start = i;
45 0 : while (i < (int)convstring.size() && convstring[i]!=' ') i++;
46 0 : int pair_end = i;
47 0 : int j = pair_start;
48 0 : while (j < (int)convstring.size() && convstring[j]!='=') j++;
49 0 : std::string key =
50 0 : std::string(convstring.c_str(), pair_start, j-pair_start);
51 0 : std::string value =
52 0 : std::string(convstring.c_str(), j+1, pair_end-(j+1));
53 0 : params[key]=value;
54 0 : }
55 :
56 :
57 : // if (fnname==#name) return new itemconv::itemconv_##name(params);
58 :
59 : #define DEFINE_CONVERSION_CLASS(name,body) \
60 : if (fnname==#name) { \
61 : itemconv::itemconv_##name *c = new itemconv::itemconv_##name(); \
62 : c->init(params); return c; }
63 : #include "wibmod/WIB1/conversions-impl.hh"
64 : #undef DEFINE_CONVERSION_CLASS
65 :
66 : return NULL;
67 0 : }
68 :
|