DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
conversions.cpp
Go to the documentation of this file.
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
11#include <stdio.h> // sscanf
12#include <boost/foreach.hpp>
13
14using boost::unordered_map;
15
16namespace 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) \
22class itemconv_##name : public ItemConversion { STRIP(body) };
23/*#define DEFINE_CONVERSION_CLASS_END \
24public: \
25 itemconv_##name (unordered_map<std::string, std::string> params) { \
26 init(params); \
27 } \
28};*/
30#undef DEFINE_CONVERSION_CLASS
31#undef STRIP
32#undef EXPAND
33#undef STRIP
34
35}
36
37ItemConversion * ItemConversion::FromString(std::string convstring) {
38 unordered_map<std::string, std::string> params;
39 int i = 0;
40 while (i < (int)convstring.size() && convstring[i]!=' ') i++;
41 std::string fnname = std::string(convstring.c_str(), i);
42 while (i < (int)convstring.size()) {
43 while (i < (int)convstring.size() && convstring[i]==' ') i++;
44 int pair_start = i;
45 while (i < (int)convstring.size() && convstring[i]!=' ') i++;
46 int pair_end = i;
47 int j = pair_start;
48 while (j < (int)convstring.size() && convstring[j]!='=') j++;
49 std::string key =
50 std::string(convstring.c_str(), pair_start, j-pair_start);
51 std::string value =
52 std::string(convstring.c_str(), j+1, pair_end-(j+1));
53 params[key]=value;
54 }
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; }
64#undef DEFINE_CONVERSION_CLASS
65
66 return NULL;
67}
68
static ItemConversion * FromString(std::string convstring)