-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatatypes.h
214 lines (183 loc) · 3.78 KB
/
datatypes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#ifndef DATATYPES_GUARD
#define DATATYPES_GUARD
#include "defines.h"
#include "split.h"
#include <string>
#include <sys/stat.h>
#include <vector>
#include <map>
#include <sstream>
#include <iostream>
#include "proxy.h"
#include "errorhandling.h"
namespace ctb
{
/** Datatypes contains various general helper functions and datatypes
*
* Some (most) of these should later be (theoretically) moved into separate units.
* */
//various helper classes
template<typename F>
class tagmaster;
struct traits_conv_test
{
typedef int opid_t;
typedef int tid_t;
typedef int vid_t;
typedef uint32_t flag_t;
typedef string param_t;
static const int maxarity = 3;
} ;
struct traits
{
typedef string opid_t;
typedef string tid_t;
typedef string vid_t;
typedef uint32_t flag_t;
typedef int param_t;
//typedef tagmaster<uint32_t> tag_handler_t;
static const int maxarity = 3;
} ;
const int gmCOUNT = 3;
enum maskmodes { gSELECT = 0, gPRINT = 1, gONCE = 2};
enum maskmodes_masks { mSELECT = 1 , mPRINT = 2, mONCE = 4 };
enum flags
{
fINPUT = 1
, fOUTPUT = 2
, fDEBUG = 4
, fEXPANSION = 8
, fEFINPUT = 16
, fEFOUTPUT = 32
, fNOOUTPUT = 64
, fNOOP = 128
} ;
template <typename ... T> void pass(T...)
{
}
template<typename F>
map<string, F> flaghash()
{
map<string, F> hash = {
{"output",fOUTPUT}
,{"input",fINPUT}
,{"debug",fDEBUG}
,{"expansion",fEXPANSION}
,{"effectinput",fEFINPUT}
,{"effectoutput",fEFOUTPUT}
//,{"nooutput",fNOOUTPUT}
,{"noop",fNOOP}
};
return hash;
}
template<typename F>
F string_to_flags(string str)
{
auto hash = flaghash<F>();
F f = 0;
stringlist words = splitlist(str);
for(auto w : words)
{
if(hash.find(w) != hash.end() )
{
f |= hash[w];
}
else
{
error( string("unknown flag found: ").append(w).append("\n"), false);
}
}
return f;
}
template<typename F>
string flags_to_string(F f)
{
string b;
auto hash = flaghash<F>();
for(auto rec : hash)
{
if( (rec.second & f) > 0)
{
if(!b.empty())
b.append(",");
b.append(rec.first);
}
}
return b;
}
string exec_path;
string to_string(string str)
{
return str;
}
string to_string(int i)
{
return std::to_string(i);
}
string to_string(char* c)
{
return std::string(c);
}
template <typename L>
string l_to_string(const L& cont)
{
string buff;
for(const auto& s : cont)
{
if(!buff.empty())
buff = buff+",";
buff = buff+ctb::to_string(s);
}
return buff;
}
int stoi(string str)
{
//may want some evaluation here later...
int result = 0;
if(str == "true" || str == "True" || str == "TRUE")
return 1;
if(str == "false" || str == "False" || str == "FALSE")
return 0;
try
{
result = std::stoi(str);
}
catch(...)
{
error(string("'").append(str).append("' does not look like an integer"), false);
}
return result;
}
int stoi_def(string str, int d)
{
if(str.empty())
return d;
try
{
return ctb::stoi(str);
}
catch(...)
{
return d;
}
}
template <typename L>
vector<int> lstoi(const L& cont)
{
vector<int> res;
for(const auto& s : cont)
res.push_back(ctb::stoi(s));
return res;
}
template <typename A, typename B>
map<string,string> toparam(A a, B b)
{
return {{ctb::to_string(a), ctb::to_string(b)}};
}
template <typename T, T V>
struct value_container
{
static const T value = V;
};
};
#endif