-
Notifications
You must be signed in to change notification settings - Fork 1
/
State.h
300 lines (262 loc) · 6.65 KB
/
State.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#ifndef __STATE__H__
#define __STATE__H__
#include <vector>
#include <string.h>
#include <memory>
#include "StataHeader.h"
#include "StataVariables.h"
#include "StataRead.h"
#include "StateBitops.h"
#include "StataMap.h"
#include "StataValueLabel.h"
#include "StataDB.h"
using namespace std;
class Context;
#define CHECK_TAG(tag) ((!strcasecmp(buffer, tag)) ? true : false)
#define INITIAL_BUFFER 1024
class State
{
public:
virtual State *advanceState() = 0;
virtual bool check(char *) = 0;
virtual bool process(Context &ctx) = 0;
virtual ~State() {};
};
class Context
{
public:
Context(char *cursor, int length);
virtual ~Context();
void *advance();
StataHeader hdr;
StataMap map;
State *currentState;
bool strls;
char *origin;
vector< boost::shared_ptr<StataVariables> > vList;
vector < vector < char * > * > vData;
char *getCursor() { return cursor; }
void clearCursor() { cursor = NULL; }
void advanceNoState();
void advanceCursor(int c);
void advanceData(int c);
string getChars(int count)
{
string tmp;
tmp.assign(cursor, count);
cursor += count;
return tmp;
};
void resizeBuffer(int sz)
{
delete [] buffer;
buffer_size = sz + 1;
buffer = new char[buffer_size];
};
int exportToDB(DatabaseTypes db_type, void * params);
private:
char *buffer;
int buffer_size;
char *cursor;
char *start;
int length;
};
class OpenDTA : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_FILE); }
State *advanceState();
bool process(Context &ctx);
~OpenDTA() {};
};
class CloseDTA : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_CLOSE_FILE); }
State *advanceState();
bool process(Context &ctx);
~CloseDTA() {};
};
class OpenHeader : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_HEADER); }
State *advanceState();
bool process(Context &ctx);
~OpenHeader() {};
};
class CloseHeader : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_CLOSE_HEADER); }
State *advanceState();
bool process(Context &ctx);
~CloseHeader() {};
};
class OpenRelease : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_RELEASE); }
State *advanceState();
bool process(Context &ctx);
~OpenRelease() {};
};
class CloseRelease : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_CLOSE_RELEASE); }
State *advanceState();
bool process(Context &ctx);
~CloseRelease() {};
};
class OpenByteOrder : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_BYTEORDER); }
State *advanceState();
bool process(Context &ctx);
~OpenByteOrder() {};
};
class OpenK : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_VARIABLES_COUNT); }
State *advanceState();
bool process(Context &ctx);
~OpenK() {};
};
class OpenN : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_OBSERVATIONS_COUNT); }
State *advanceState();
bool process(Context &ctx);
~OpenN() {};
};
class OpenLabel : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_LABEL); }
State *advanceState();
bool process(Context &ctx);
~OpenLabel() {};
};
class OpenCH : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_CH); }
State *advanceState();
bool process(Context &ctx);
~OpenCH() {};
};
class CloseCH : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_CLOSE_CH); }
State *advanceState();
bool process(Context &ctx);
void setHasCharacteristics(bool v) { hasCharacteristics = v; };
bool getHasCharacteristics() { return hasCharacteristics; };
~CloseCH() {};
private:
bool hasCharacteristics;
};
class OpenTimeStamp : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_TIMESTAMP); }
State *advanceState();
bool process(Context &ctx);
~OpenTimeStamp() {};
};
class OpenMap : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_MAP); }
State *advanceState();
bool process(Context &ctx);
~OpenMap() {};
};
class OpenVarTypes : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_VARIABLE_TYPES); }
State *advanceState();
bool process(Context &ctx);
~OpenVarTypes() {};
};
class OpenVarNames : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_VARNAMES); }
State *advanceState();
bool process(Context &ctx);
~OpenVarNames() {};
};
class OpenSortList : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_SORTLIST); }
State *advanceState();
bool process(Context &ctx);
~OpenSortList() {};
};
class OpenFormats : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_FORMATS); }
State *advanceState();
bool process(Context &ctx);
~OpenFormats() {};
};
class OpenValueLabelNames : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_VALUE_LABEL_NAMES); }
State *advanceState();
bool process(Context &ctx);
~OpenValueLabelNames() {};
};
class OpenVariableLabels : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_VARIABLE_LABELS); }
State *advanceState();
bool process(Context &ctx);
~OpenVariableLabels() {};
};
class OpenCharacteristics : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_CHARACTERISTICS); }
State *advanceState();
bool process(Context &ctx);
void setHasCharacteristics(bool v) { hasCharacteristics = v; };
bool getHasCharacteristics() { return hasCharacteristics; };
~OpenCharacteristics() {};
private:
bool hasCharacteristics;
};
class OpenData : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_DATA); }
State *advanceState();
bool process(Context &ctx);
~OpenData() {};
};
class OpenSTRL : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_STRLS); }
State *advanceState();
bool process(Context &ctx);
~OpenSTRL() {};
};
class OpenValueLabel : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_VALUE_LABELS); }
State *advanceState();
bool process(Context &ctx);
void setHasLabels(bool v) { hasLabels = v; };
bool getHasLabels() { return hasLabels; };
~OpenValueLabel() {};
private:
bool hasLabels;
};
class CloseValueLabel : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_CLOSE_VALUE_LABELS); }
State *advanceState();
bool process(Context &ctx);
~CloseValueLabel() {};
};
class OpenInnerValueLabel : public State
{
bool check(char *buffer) { return CHECK_TAG(XML_OPEN_INNER_VALUE_LABELS); }
State *advanceState();
bool process(Context &ctx);
void setHasMoreLabels(bool v) { hasMoreLabels = v; };
bool getHasMoreLabels() { return hasMoreLabels; };
~OpenInnerValueLabel() {};
private:
bool hasMoreLabels;
};
#endif