-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonpath.h
387 lines (341 loc) · 10.3 KB
/
jsonpath.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#pragma once
// Copyright David Lawrence Bien 1997 - 2021.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt).
// jsonpath.h
// JSON path objects and algorithms.
// dbien 09APR2020
#error Work in progress that may never progress.
#include <cstdint>
// JsonPath:
// This represents the complete path object.
template < class t_tyChar >
class JsonPath
{
typedef JsonPath _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
JsonPath() = default;
};
// _JsonPathElement:
// This reprsents a segment of a JaonPath.
// (.|..)( [name|*] | [ '['range|index|setofnames|expression']' ] )
// When array notation is used then any leading single dot is redundant.
template < class t_tyChar >
class _JsonPathElement
{
typedef _JsonPathElement _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
};
// _JsonExpression
// An expression that is within square brackets.
// Note that any numeric constant without a decimal point '.' will be treated as an integer
// and will cause *truncation* of any corresponding JSON value.
template < class t_tyChar >
class _JsonExpression
{
typedef _JsonExpression _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
};
enum _EJsonExprType : uint8_t
{
// Leaves - these form the basis of any expression.
ejetConstant, // A constant value. This is a JsoValue.
ejetArraySlice, // An array slice.
ejetSetOfKeys, // A set of 2 more more keys - referred to sometimes as a union - one or more of these names maybe matched.
ejetSingleKey, // a key must exist - not that if a key is included in an equation then we cannot match without it - keeping in mind that ORs are conditional.
ejetLastLeaf = ejetSingleKey,
// Unary:
ejetNot,
ejetBitwiseNot,
ejetLastUnary = ejetBitwiseNot,
// Binary:
ejetEquals,
ejetLessThan,
ejetLessThanOrEqual,
ejetGreaterThan,
ejetGreaterThanOrEqual,
ejetEJsonExprType // Leave this at the end.
};
typedef _EJsonExprType EJsonExprType;
//_JsonExprOpBase
// A single operation within a JsonExpression.
// Abstract base class.
template < class t_tyChar >
class _JsonExprOpBase
{
typedef _JsonExprOpBase _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
virtual ~_JsonExprOpBase() = 0;
_JsonExprOpBase( EJsonExprType _jet = ejetEJsonExprType )
: m_jet( _jet )
{
}
protected:
EJsonExprType m_jet{ejetEJsonExprType};
};
//_JsonExprArgBase<T,0>:
// A single operation within a JsonExpression.
// Abstract base class.
template < class t_tyChar, size_t t_knArgs >
class _JsonExprArgBase : public _JsonExprOpBase< t_tyChar >
{
typedef _JsonExprOpBase< t_tyChar > _tyBase;
typedef _JsonExprArgBase _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
virtual ~_JsonExprArgBase() = 0;
_JsonExprArgBase( EJsonExprType _jet = ejetEJsonExprType )
: _tyBase( _jet )
{
}
protected:
};
//_JsonExprArgBase<T,1>:
// A single operation within a JsonExpression.
// Abstract base class.
template < class t_tyChar >
class _JsonExprArgBase< t_tyChar, 1 > : public _JsonExprOpBase< t_tyChar >
{
typedef _JsonExprOpBase< t_tyChar > _tyBase;
typedef _JsonExprArgBase _tyThis;
public:
typedef _JsonExprOpBase< t_tyChar > _tyExprOpBase;
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
virtual ~_JsonExprArgBase() = 0;
_JsonExprArgBase( EJsonExprType _jet = ejetEJsonExprType )
: _tyBase( _jet )
{
}
protected:
_tyExprOpBase * m_peopArg0{nullptr};
};
//_JsonExprArgBase<T,2>:
// A single operation within a JsonExpression.
// Abstract base class.
template < class t_tyChar >
class _JsonExprArgBase< t_tyChar, 2 > : public _JsonExprOpBase< t_tyChar >
{
typedef _JsonExprOpBase< t_tyChar > _tyBase;
typedef _JsonExprArgBase _tyThis;
public:
typedef _JsonExprOpBase< t_tyChar > _tyExprOpBase;
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
virtual ~_JsonExprArgBase() = 0;
_JsonExprArgBase( EJsonExprType _jet = ejetEJsonExprType )
: _tyBase( _jet )
{
}
protected:
_tyExprOpBase * m_peopArg0{nullptr};
_tyExprOpBase * m_peopArg1{nullptr};
};
// Leaves:
// _JsonExprLeafConstant:
template < class t_tyChar >
class _JsonExprLeafConstant : public _JsonExprArgBase< t_tyChar, 0 >
{
typedef _JsonExprArgBase< t_tyChar, 0 > _tyBase;
typedef _JsonExprLeafConstant _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
_JsonExprLeafConstant()
: _tyBase( ejetConstant )
{
}
protected:
_tyJsoValue m_jvValue;
};
template < class t_tyChar >
class _JsonExprLeafArraySlice : public _JsonExprArgBase< t_tyChar, 0 >
{
typedef _JsonExprArgBase< t_tyChar, 0 > _tyBase;
typedef _JsonExprLeafArraySlice _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
_JsonExprLeafArraySlice()
: _tyBase( ejetArraySlice )
{
}
protected:
typedef int32_t _tyIdxType;
_tyIdxType m_idxBegin{};
_tyIdxType m_idxEnd{};
_tyIdxType m_idxStep{};
};
// _JsonExprLeafSingleKey:
template < class t_tyChar >
class _JsonExprLeafSingleKey : public _JsonExprArgBase< t_tyChar, 0 >
{
typedef _JsonExprArgBase< t_tyChar, 0 > _tyBase;
typedef _JsonExprLeafSingleKey _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
_JsonExprLeafSingleKey()
: _tyBase( ejetSingleKey )
{
}
protected:
_tyStrWRsv m_strKey;
};
// _JsonExprLeafSetOfKeys:
// This leaf has limited modifiers. There is no syntax for "!"(not) for instance currently.
template < class t_tyChar >
class _JsonExprLeafSetOfKeys : public _JsonExprArgBase< t_tyChar, 0 >
{
typedef _JsonExprArgBase< t_tyChar, 0 > _tyBase;
typedef _JsonExprLeafSetOfKeys _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
typedef std::vector< _tyStrWRsv > _tyRgKeys;
_JsonExprLeafSetOfKeys()
: _tyBase( ejetSetOfKeys )
{
}
protected:
_tyRgKeys m_rgKeys;
};
// Unary operators:
// _JsonExprOpNot:
template < class t_tyChar >
class _JsonExprOpNot : public _JsonExprArgBase< t_tyChar, 1 >
{
typedef _JsonExprArgBase< t_tyChar, 1 > _tyBase;
typedef _JsonExprOpNot _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
_JsonExprOpNot()
: _tyBase( ejetNot )
{
}
};
// _JsonExprOpBitwiseNot:
template < class t_tyChar >
class _JsonExprOpBitwiseNot : public _JsonExprArgBase< t_tyChar, 1 >
{
typedef _JsonExprArgBase< t_tyChar, 1 > _tyBase;
typedef _JsonExprOpBitwiseNot _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
_JsonExprOpBitwiseNot()
: _tyBase( ejetBitwiseNot )
{
}
};
// Binary operators:
// _JsonExprOpEquals:
template < class t_tyChar >
class _JsonExprOpEquals : public _JsonExprArgBase< t_tyChar, 2 >
{
typedef _JsonExprArgBase< t_tyChar, 1 > _tyBase;
typedef _JsonExprOpEquals _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
_JsonExprOpEquals()
: _tyBase( ejetEquals )
{
}
};
// _JsonExprOpLessThan:
template < class t_tyChar >
class _JsonExprOpLessThan : public _JsonExprArgBase< t_tyChar, 2 >
{
typedef _JsonExprArgBase< t_tyChar, 1 > _tyBase;
typedef _JsonExprOpLessThan _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
_JsonExprOpLessThan()
: _tyBase( ejetLessThan )
{
}
};
// _JsonExprOpLessThanOrEqual:
template < class t_tyChar >
class _JsonExprOpLessThanOrEqual : public _JsonExprArgBase< t_tyChar, 2 >
{
typedef _JsonExprArgBase< t_tyChar, 1 > _tyBase;
typedef _JsonExprOpLessThanOrEqual _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
_JsonExprOpLessThanOrEqual()
: _tyBase( ejetLessThanOrEqual )
{
}
};
// _JsonExprOpGreaterThan:
template < class t_tyChar >
class _JsonExprOpGreaterThan : public _JsonExprArgBase< t_tyChar, 2 >
{
typedef _JsonExprArgBase< t_tyChar, 1 > _tyBase;
typedef _JsonExprOpGreaterThan _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
_JsonExprOpGreaterThan()
: _tyBase( ejetGreaterThan )
{
}
};
// _JsonExprOpGreaterThanOrEqual:
template < class t_tyChar >
class _JsonExprOpGreaterThanOrEqual : public _JsonExprArgBase< t_tyChar, 2 >
{
typedef _JsonExprArgBase< t_tyChar, 1 > _tyBase;
typedef _JsonExprOpGreaterThanOrEqual _tyThis;
public:
typedef t_tyChar _tyChar;
typedef std::basic_string< _tyChar > _tyStdStr;
typedef StrWRsv< _tyStdStr > _tyStrWRsv;
typedef JsoValue< _tyChar > _tyJsoValue;
_JsonExprOpGreaterThanOrEqual()
: _tyBase( ejetGreaterThanOrEqual )
{
}
};