rapidjson 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +20 -0
- data/ext/rapidjson/buffer.hh +66 -0
- data/ext/rapidjson/cext.cc +77 -0
- data/ext/rapidjson/cext.hh +20 -0
- data/ext/rapidjson/encoder.hh +150 -0
- data/ext/rapidjson/extconf.rb +19 -0
- data/ext/rapidjson/parser.hh +149 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/allocators.h +692 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/cursorstreamwrapper.h +78 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/document.h +3027 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/encodedstream.h +299 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/encodings.h +716 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/error/en.h +122 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/error/error.h +216 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/filereadstream.h +99 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/filewritestream.h +104 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/fwd.h +151 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/biginteger.h +297 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/clzll.h +71 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/diyfp.h +261 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/dtoa.h +249 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/ieee754.h +78 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/itoa.h +308 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/meta.h +186 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/pow10.h +55 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/regex.h +739 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/stack.h +232 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/strfunc.h +83 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/strtod.h +293 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/swap.h +46 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/istreamwrapper.h +128 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/memorybuffer.h +70 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/memorystream.h +71 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/msinttypes/inttypes.h +316 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/msinttypes/stdint.h +300 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/ostreamwrapper.h +81 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/pointer.h +1482 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/prettywriter.h +277 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/rapidjson.h +741 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/reader.h +2246 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/schema.h +2795 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/stream.h +223 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/stringbuffer.h +121 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/uri.h +481 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/writer.h +710 -0
- data/lib/rapidjson/json_gem.rb +36 -0
- data/lib/rapidjson/version.rb +5 -0
- data/lib/rapidjson.rb +9 -0
- metadata +98 -0
@@ -0,0 +1,308 @@
|
|
1
|
+
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
|
+
//
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
|
+
//
|
5
|
+
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
|
+
// in compliance with the License. You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://opensource.org/licenses/MIT
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software distributed
|
11
|
+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
12
|
+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
13
|
+
// specific language governing permissions and limitations under the License.
|
14
|
+
|
15
|
+
#ifndef RAPIDJSON_ITOA_
|
16
|
+
#define RAPIDJSON_ITOA_
|
17
|
+
|
18
|
+
#include "../rapidjson.h"
|
19
|
+
|
20
|
+
RAPIDJSON_NAMESPACE_BEGIN
|
21
|
+
namespace internal {
|
22
|
+
|
23
|
+
inline const char* GetDigitsLut() {
|
24
|
+
static const char cDigitsLut[200] = {
|
25
|
+
'0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9',
|
26
|
+
'1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9',
|
27
|
+
'2','0','2','1','2','2','2','3','2','4','2','5','2','6','2','7','2','8','2','9',
|
28
|
+
'3','0','3','1','3','2','3','3','3','4','3','5','3','6','3','7','3','8','3','9',
|
29
|
+
'4','0','4','1','4','2','4','3','4','4','4','5','4','6','4','7','4','8','4','9',
|
30
|
+
'5','0','5','1','5','2','5','3','5','4','5','5','5','6','5','7','5','8','5','9',
|
31
|
+
'6','0','6','1','6','2','6','3','6','4','6','5','6','6','6','7','6','8','6','9',
|
32
|
+
'7','0','7','1','7','2','7','3','7','4','7','5','7','6','7','7','7','8','7','9',
|
33
|
+
'8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9',
|
34
|
+
'9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9'
|
35
|
+
};
|
36
|
+
return cDigitsLut;
|
37
|
+
}
|
38
|
+
|
39
|
+
inline char* u32toa(uint32_t value, char* buffer) {
|
40
|
+
RAPIDJSON_ASSERT(buffer != 0);
|
41
|
+
|
42
|
+
const char* cDigitsLut = GetDigitsLut();
|
43
|
+
|
44
|
+
if (value < 10000) {
|
45
|
+
const uint32_t d1 = (value / 100) << 1;
|
46
|
+
const uint32_t d2 = (value % 100) << 1;
|
47
|
+
|
48
|
+
if (value >= 1000)
|
49
|
+
*buffer++ = cDigitsLut[d1];
|
50
|
+
if (value >= 100)
|
51
|
+
*buffer++ = cDigitsLut[d1 + 1];
|
52
|
+
if (value >= 10)
|
53
|
+
*buffer++ = cDigitsLut[d2];
|
54
|
+
*buffer++ = cDigitsLut[d2 + 1];
|
55
|
+
}
|
56
|
+
else if (value < 100000000) {
|
57
|
+
// value = bbbbcccc
|
58
|
+
const uint32_t b = value / 10000;
|
59
|
+
const uint32_t c = value % 10000;
|
60
|
+
|
61
|
+
const uint32_t d1 = (b / 100) << 1;
|
62
|
+
const uint32_t d2 = (b % 100) << 1;
|
63
|
+
|
64
|
+
const uint32_t d3 = (c / 100) << 1;
|
65
|
+
const uint32_t d4 = (c % 100) << 1;
|
66
|
+
|
67
|
+
if (value >= 10000000)
|
68
|
+
*buffer++ = cDigitsLut[d1];
|
69
|
+
if (value >= 1000000)
|
70
|
+
*buffer++ = cDigitsLut[d1 + 1];
|
71
|
+
if (value >= 100000)
|
72
|
+
*buffer++ = cDigitsLut[d2];
|
73
|
+
*buffer++ = cDigitsLut[d2 + 1];
|
74
|
+
|
75
|
+
*buffer++ = cDigitsLut[d3];
|
76
|
+
*buffer++ = cDigitsLut[d3 + 1];
|
77
|
+
*buffer++ = cDigitsLut[d4];
|
78
|
+
*buffer++ = cDigitsLut[d4 + 1];
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
// value = aabbbbcccc in decimal
|
82
|
+
|
83
|
+
const uint32_t a = value / 100000000; // 1 to 42
|
84
|
+
value %= 100000000;
|
85
|
+
|
86
|
+
if (a >= 10) {
|
87
|
+
const unsigned i = a << 1;
|
88
|
+
*buffer++ = cDigitsLut[i];
|
89
|
+
*buffer++ = cDigitsLut[i + 1];
|
90
|
+
}
|
91
|
+
else
|
92
|
+
*buffer++ = static_cast<char>('0' + static_cast<char>(a));
|
93
|
+
|
94
|
+
const uint32_t b = value / 10000; // 0 to 9999
|
95
|
+
const uint32_t c = value % 10000; // 0 to 9999
|
96
|
+
|
97
|
+
const uint32_t d1 = (b / 100) << 1;
|
98
|
+
const uint32_t d2 = (b % 100) << 1;
|
99
|
+
|
100
|
+
const uint32_t d3 = (c / 100) << 1;
|
101
|
+
const uint32_t d4 = (c % 100) << 1;
|
102
|
+
|
103
|
+
*buffer++ = cDigitsLut[d1];
|
104
|
+
*buffer++ = cDigitsLut[d1 + 1];
|
105
|
+
*buffer++ = cDigitsLut[d2];
|
106
|
+
*buffer++ = cDigitsLut[d2 + 1];
|
107
|
+
*buffer++ = cDigitsLut[d3];
|
108
|
+
*buffer++ = cDigitsLut[d3 + 1];
|
109
|
+
*buffer++ = cDigitsLut[d4];
|
110
|
+
*buffer++ = cDigitsLut[d4 + 1];
|
111
|
+
}
|
112
|
+
return buffer;
|
113
|
+
}
|
114
|
+
|
115
|
+
inline char* i32toa(int32_t value, char* buffer) {
|
116
|
+
RAPIDJSON_ASSERT(buffer != 0);
|
117
|
+
uint32_t u = static_cast<uint32_t>(value);
|
118
|
+
if (value < 0) {
|
119
|
+
*buffer++ = '-';
|
120
|
+
u = ~u + 1;
|
121
|
+
}
|
122
|
+
|
123
|
+
return u32toa(u, buffer);
|
124
|
+
}
|
125
|
+
|
126
|
+
inline char* u64toa(uint64_t value, char* buffer) {
|
127
|
+
RAPIDJSON_ASSERT(buffer != 0);
|
128
|
+
const char* cDigitsLut = GetDigitsLut();
|
129
|
+
const uint64_t kTen8 = 100000000;
|
130
|
+
const uint64_t kTen9 = kTen8 * 10;
|
131
|
+
const uint64_t kTen10 = kTen8 * 100;
|
132
|
+
const uint64_t kTen11 = kTen8 * 1000;
|
133
|
+
const uint64_t kTen12 = kTen8 * 10000;
|
134
|
+
const uint64_t kTen13 = kTen8 * 100000;
|
135
|
+
const uint64_t kTen14 = kTen8 * 1000000;
|
136
|
+
const uint64_t kTen15 = kTen8 * 10000000;
|
137
|
+
const uint64_t kTen16 = kTen8 * kTen8;
|
138
|
+
|
139
|
+
if (value < kTen8) {
|
140
|
+
uint32_t v = static_cast<uint32_t>(value);
|
141
|
+
if (v < 10000) {
|
142
|
+
const uint32_t d1 = (v / 100) << 1;
|
143
|
+
const uint32_t d2 = (v % 100) << 1;
|
144
|
+
|
145
|
+
if (v >= 1000)
|
146
|
+
*buffer++ = cDigitsLut[d1];
|
147
|
+
if (v >= 100)
|
148
|
+
*buffer++ = cDigitsLut[d1 + 1];
|
149
|
+
if (v >= 10)
|
150
|
+
*buffer++ = cDigitsLut[d2];
|
151
|
+
*buffer++ = cDigitsLut[d2 + 1];
|
152
|
+
}
|
153
|
+
else {
|
154
|
+
// value = bbbbcccc
|
155
|
+
const uint32_t b = v / 10000;
|
156
|
+
const uint32_t c = v % 10000;
|
157
|
+
|
158
|
+
const uint32_t d1 = (b / 100) << 1;
|
159
|
+
const uint32_t d2 = (b % 100) << 1;
|
160
|
+
|
161
|
+
const uint32_t d3 = (c / 100) << 1;
|
162
|
+
const uint32_t d4 = (c % 100) << 1;
|
163
|
+
|
164
|
+
if (value >= 10000000)
|
165
|
+
*buffer++ = cDigitsLut[d1];
|
166
|
+
if (value >= 1000000)
|
167
|
+
*buffer++ = cDigitsLut[d1 + 1];
|
168
|
+
if (value >= 100000)
|
169
|
+
*buffer++ = cDigitsLut[d2];
|
170
|
+
*buffer++ = cDigitsLut[d2 + 1];
|
171
|
+
|
172
|
+
*buffer++ = cDigitsLut[d3];
|
173
|
+
*buffer++ = cDigitsLut[d3 + 1];
|
174
|
+
*buffer++ = cDigitsLut[d4];
|
175
|
+
*buffer++ = cDigitsLut[d4 + 1];
|
176
|
+
}
|
177
|
+
}
|
178
|
+
else if (value < kTen16) {
|
179
|
+
const uint32_t v0 = static_cast<uint32_t>(value / kTen8);
|
180
|
+
const uint32_t v1 = static_cast<uint32_t>(value % kTen8);
|
181
|
+
|
182
|
+
const uint32_t b0 = v0 / 10000;
|
183
|
+
const uint32_t c0 = v0 % 10000;
|
184
|
+
|
185
|
+
const uint32_t d1 = (b0 / 100) << 1;
|
186
|
+
const uint32_t d2 = (b0 % 100) << 1;
|
187
|
+
|
188
|
+
const uint32_t d3 = (c0 / 100) << 1;
|
189
|
+
const uint32_t d4 = (c0 % 100) << 1;
|
190
|
+
|
191
|
+
const uint32_t b1 = v1 / 10000;
|
192
|
+
const uint32_t c1 = v1 % 10000;
|
193
|
+
|
194
|
+
const uint32_t d5 = (b1 / 100) << 1;
|
195
|
+
const uint32_t d6 = (b1 % 100) << 1;
|
196
|
+
|
197
|
+
const uint32_t d7 = (c1 / 100) << 1;
|
198
|
+
const uint32_t d8 = (c1 % 100) << 1;
|
199
|
+
|
200
|
+
if (value >= kTen15)
|
201
|
+
*buffer++ = cDigitsLut[d1];
|
202
|
+
if (value >= kTen14)
|
203
|
+
*buffer++ = cDigitsLut[d1 + 1];
|
204
|
+
if (value >= kTen13)
|
205
|
+
*buffer++ = cDigitsLut[d2];
|
206
|
+
if (value >= kTen12)
|
207
|
+
*buffer++ = cDigitsLut[d2 + 1];
|
208
|
+
if (value >= kTen11)
|
209
|
+
*buffer++ = cDigitsLut[d3];
|
210
|
+
if (value >= kTen10)
|
211
|
+
*buffer++ = cDigitsLut[d3 + 1];
|
212
|
+
if (value >= kTen9)
|
213
|
+
*buffer++ = cDigitsLut[d4];
|
214
|
+
|
215
|
+
*buffer++ = cDigitsLut[d4 + 1];
|
216
|
+
*buffer++ = cDigitsLut[d5];
|
217
|
+
*buffer++ = cDigitsLut[d5 + 1];
|
218
|
+
*buffer++ = cDigitsLut[d6];
|
219
|
+
*buffer++ = cDigitsLut[d6 + 1];
|
220
|
+
*buffer++ = cDigitsLut[d7];
|
221
|
+
*buffer++ = cDigitsLut[d7 + 1];
|
222
|
+
*buffer++ = cDigitsLut[d8];
|
223
|
+
*buffer++ = cDigitsLut[d8 + 1];
|
224
|
+
}
|
225
|
+
else {
|
226
|
+
const uint32_t a = static_cast<uint32_t>(value / kTen16); // 1 to 1844
|
227
|
+
value %= kTen16;
|
228
|
+
|
229
|
+
if (a < 10)
|
230
|
+
*buffer++ = static_cast<char>('0' + static_cast<char>(a));
|
231
|
+
else if (a < 100) {
|
232
|
+
const uint32_t i = a << 1;
|
233
|
+
*buffer++ = cDigitsLut[i];
|
234
|
+
*buffer++ = cDigitsLut[i + 1];
|
235
|
+
}
|
236
|
+
else if (a < 1000) {
|
237
|
+
*buffer++ = static_cast<char>('0' + static_cast<char>(a / 100));
|
238
|
+
|
239
|
+
const uint32_t i = (a % 100) << 1;
|
240
|
+
*buffer++ = cDigitsLut[i];
|
241
|
+
*buffer++ = cDigitsLut[i + 1];
|
242
|
+
}
|
243
|
+
else {
|
244
|
+
const uint32_t i = (a / 100) << 1;
|
245
|
+
const uint32_t j = (a % 100) << 1;
|
246
|
+
*buffer++ = cDigitsLut[i];
|
247
|
+
*buffer++ = cDigitsLut[i + 1];
|
248
|
+
*buffer++ = cDigitsLut[j];
|
249
|
+
*buffer++ = cDigitsLut[j + 1];
|
250
|
+
}
|
251
|
+
|
252
|
+
const uint32_t v0 = static_cast<uint32_t>(value / kTen8);
|
253
|
+
const uint32_t v1 = static_cast<uint32_t>(value % kTen8);
|
254
|
+
|
255
|
+
const uint32_t b0 = v0 / 10000;
|
256
|
+
const uint32_t c0 = v0 % 10000;
|
257
|
+
|
258
|
+
const uint32_t d1 = (b0 / 100) << 1;
|
259
|
+
const uint32_t d2 = (b0 % 100) << 1;
|
260
|
+
|
261
|
+
const uint32_t d3 = (c0 / 100) << 1;
|
262
|
+
const uint32_t d4 = (c0 % 100) << 1;
|
263
|
+
|
264
|
+
const uint32_t b1 = v1 / 10000;
|
265
|
+
const uint32_t c1 = v1 % 10000;
|
266
|
+
|
267
|
+
const uint32_t d5 = (b1 / 100) << 1;
|
268
|
+
const uint32_t d6 = (b1 % 100) << 1;
|
269
|
+
|
270
|
+
const uint32_t d7 = (c1 / 100) << 1;
|
271
|
+
const uint32_t d8 = (c1 % 100) << 1;
|
272
|
+
|
273
|
+
*buffer++ = cDigitsLut[d1];
|
274
|
+
*buffer++ = cDigitsLut[d1 + 1];
|
275
|
+
*buffer++ = cDigitsLut[d2];
|
276
|
+
*buffer++ = cDigitsLut[d2 + 1];
|
277
|
+
*buffer++ = cDigitsLut[d3];
|
278
|
+
*buffer++ = cDigitsLut[d3 + 1];
|
279
|
+
*buffer++ = cDigitsLut[d4];
|
280
|
+
*buffer++ = cDigitsLut[d4 + 1];
|
281
|
+
*buffer++ = cDigitsLut[d5];
|
282
|
+
*buffer++ = cDigitsLut[d5 + 1];
|
283
|
+
*buffer++ = cDigitsLut[d6];
|
284
|
+
*buffer++ = cDigitsLut[d6 + 1];
|
285
|
+
*buffer++ = cDigitsLut[d7];
|
286
|
+
*buffer++ = cDigitsLut[d7 + 1];
|
287
|
+
*buffer++ = cDigitsLut[d8];
|
288
|
+
*buffer++ = cDigitsLut[d8 + 1];
|
289
|
+
}
|
290
|
+
|
291
|
+
return buffer;
|
292
|
+
}
|
293
|
+
|
294
|
+
inline char* i64toa(int64_t value, char* buffer) {
|
295
|
+
RAPIDJSON_ASSERT(buffer != 0);
|
296
|
+
uint64_t u = static_cast<uint64_t>(value);
|
297
|
+
if (value < 0) {
|
298
|
+
*buffer++ = '-';
|
299
|
+
u = ~u + 1;
|
300
|
+
}
|
301
|
+
|
302
|
+
return u64toa(u, buffer);
|
303
|
+
}
|
304
|
+
|
305
|
+
} // namespace internal
|
306
|
+
RAPIDJSON_NAMESPACE_END
|
307
|
+
|
308
|
+
#endif // RAPIDJSON_ITOA_
|
@@ -0,0 +1,186 @@
|
|
1
|
+
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
|
+
//
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
|
+
//
|
5
|
+
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
|
+
// in compliance with the License. You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://opensource.org/licenses/MIT
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software distributed
|
11
|
+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
12
|
+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
13
|
+
// specific language governing permissions and limitations under the License.
|
14
|
+
|
15
|
+
#ifndef RAPIDJSON_INTERNAL_META_H_
|
16
|
+
#define RAPIDJSON_INTERNAL_META_H_
|
17
|
+
|
18
|
+
#include "../rapidjson.h"
|
19
|
+
|
20
|
+
#ifdef __GNUC__
|
21
|
+
RAPIDJSON_DIAG_PUSH
|
22
|
+
RAPIDJSON_DIAG_OFF(effc++)
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#if defined(_MSC_VER) && !defined(__clang__)
|
26
|
+
RAPIDJSON_DIAG_PUSH
|
27
|
+
RAPIDJSON_DIAG_OFF(6334)
|
28
|
+
#endif
|
29
|
+
|
30
|
+
#if RAPIDJSON_HAS_CXX11_TYPETRAITS
|
31
|
+
#include <type_traits>
|
32
|
+
#endif
|
33
|
+
|
34
|
+
//@cond RAPIDJSON_INTERNAL
|
35
|
+
RAPIDJSON_NAMESPACE_BEGIN
|
36
|
+
namespace internal {
|
37
|
+
|
38
|
+
// Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching
|
39
|
+
template <typename T> struct Void { typedef void Type; };
|
40
|
+
|
41
|
+
///////////////////////////////////////////////////////////////////////////////
|
42
|
+
// BoolType, TrueType, FalseType
|
43
|
+
//
|
44
|
+
template <bool Cond> struct BoolType {
|
45
|
+
static const bool Value = Cond;
|
46
|
+
typedef BoolType Type;
|
47
|
+
};
|
48
|
+
typedef BoolType<true> TrueType;
|
49
|
+
typedef BoolType<false> FalseType;
|
50
|
+
|
51
|
+
|
52
|
+
///////////////////////////////////////////////////////////////////////////////
|
53
|
+
// SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr
|
54
|
+
//
|
55
|
+
|
56
|
+
template <bool C> struct SelectIfImpl { template <typename T1, typename T2> struct Apply { typedef T1 Type; }; };
|
57
|
+
template <> struct SelectIfImpl<false> { template <typename T1, typename T2> struct Apply { typedef T2 Type; }; };
|
58
|
+
template <bool C, typename T1, typename T2> struct SelectIfCond : SelectIfImpl<C>::template Apply<T1,T2> {};
|
59
|
+
template <typename C, typename T1, typename T2> struct SelectIf : SelectIfCond<C::Value, T1, T2> {};
|
60
|
+
|
61
|
+
template <bool Cond1, bool Cond2> struct AndExprCond : FalseType {};
|
62
|
+
template <> struct AndExprCond<true, true> : TrueType {};
|
63
|
+
template <bool Cond1, bool Cond2> struct OrExprCond : TrueType {};
|
64
|
+
template <> struct OrExprCond<false, false> : FalseType {};
|
65
|
+
|
66
|
+
template <typename C> struct BoolExpr : SelectIf<C,TrueType,FalseType>::Type {};
|
67
|
+
template <typename C> struct NotExpr : SelectIf<C,FalseType,TrueType>::Type {};
|
68
|
+
template <typename C1, typename C2> struct AndExpr : AndExprCond<C1::Value, C2::Value>::Type {};
|
69
|
+
template <typename C1, typename C2> struct OrExpr : OrExprCond<C1::Value, C2::Value>::Type {};
|
70
|
+
|
71
|
+
|
72
|
+
///////////////////////////////////////////////////////////////////////////////
|
73
|
+
// AddConst, MaybeAddConst, RemoveConst
|
74
|
+
template <typename T> struct AddConst { typedef const T Type; };
|
75
|
+
template <bool Constify, typename T> struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
|
76
|
+
template <typename T> struct RemoveConst { typedef T Type; };
|
77
|
+
template <typename T> struct RemoveConst<const T> { typedef T Type; };
|
78
|
+
|
79
|
+
|
80
|
+
///////////////////////////////////////////////////////////////////////////////
|
81
|
+
// IsSame, IsConst, IsMoreConst, IsPointer
|
82
|
+
//
|
83
|
+
template <typename T, typename U> struct IsSame : FalseType {};
|
84
|
+
template <typename T> struct IsSame<T, T> : TrueType {};
|
85
|
+
|
86
|
+
template <typename T> struct IsConst : FalseType {};
|
87
|
+
template <typename T> struct IsConst<const T> : TrueType {};
|
88
|
+
|
89
|
+
template <typename CT, typename T>
|
90
|
+
struct IsMoreConst
|
91
|
+
: AndExpr<IsSame<typename RemoveConst<CT>::Type, typename RemoveConst<T>::Type>,
|
92
|
+
BoolType<IsConst<CT>::Value >= IsConst<T>::Value> >::Type {};
|
93
|
+
|
94
|
+
template <typename T> struct IsPointer : FalseType {};
|
95
|
+
template <typename T> struct IsPointer<T*> : TrueType {};
|
96
|
+
|
97
|
+
///////////////////////////////////////////////////////////////////////////////
|
98
|
+
// IsBaseOf
|
99
|
+
//
|
100
|
+
#if RAPIDJSON_HAS_CXX11_TYPETRAITS
|
101
|
+
|
102
|
+
template <typename B, typename D> struct IsBaseOf
|
103
|
+
: BoolType< ::std::is_base_of<B,D>::value> {};
|
104
|
+
|
105
|
+
#else // simplified version adopted from Boost
|
106
|
+
|
107
|
+
template<typename B, typename D> struct IsBaseOfImpl {
|
108
|
+
RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0);
|
109
|
+
RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0);
|
110
|
+
|
111
|
+
typedef char (&Yes)[1];
|
112
|
+
typedef char (&No) [2];
|
113
|
+
|
114
|
+
template <typename T>
|
115
|
+
static Yes Check(const D*, T);
|
116
|
+
static No Check(const B*, int);
|
117
|
+
|
118
|
+
struct Host {
|
119
|
+
operator const B*() const;
|
120
|
+
operator const D*();
|
121
|
+
};
|
122
|
+
|
123
|
+
enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) };
|
124
|
+
};
|
125
|
+
|
126
|
+
template <typename B, typename D> struct IsBaseOf
|
127
|
+
: OrExpr<IsSame<B, D>, BoolExpr<IsBaseOfImpl<B, D> > >::Type {};
|
128
|
+
|
129
|
+
#endif // RAPIDJSON_HAS_CXX11_TYPETRAITS
|
130
|
+
|
131
|
+
|
132
|
+
//////////////////////////////////////////////////////////////////////////
|
133
|
+
// EnableIf / DisableIf
|
134
|
+
//
|
135
|
+
template <bool Condition, typename T = void> struct EnableIfCond { typedef T Type; };
|
136
|
+
template <typename T> struct EnableIfCond<false, T> { /* empty */ };
|
137
|
+
|
138
|
+
template <bool Condition, typename T = void> struct DisableIfCond { typedef T Type; };
|
139
|
+
template <typename T> struct DisableIfCond<true, T> { /* empty */ };
|
140
|
+
|
141
|
+
template <typename Condition, typename T = void>
|
142
|
+
struct EnableIf : EnableIfCond<Condition::Value, T> {};
|
143
|
+
|
144
|
+
template <typename Condition, typename T = void>
|
145
|
+
struct DisableIf : DisableIfCond<Condition::Value, T> {};
|
146
|
+
|
147
|
+
// SFINAE helpers
|
148
|
+
struct SfinaeTag {};
|
149
|
+
template <typename T> struct RemoveSfinaeTag;
|
150
|
+
template <typename T> struct RemoveSfinaeTag<SfinaeTag&(*)(T)> { typedef T Type; };
|
151
|
+
|
152
|
+
#define RAPIDJSON_REMOVEFPTR_(type) \
|
153
|
+
typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \
|
154
|
+
< ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type
|
155
|
+
|
156
|
+
#define RAPIDJSON_ENABLEIF(cond) \
|
157
|
+
typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
|
158
|
+
<RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
|
159
|
+
|
160
|
+
#define RAPIDJSON_DISABLEIF(cond) \
|
161
|
+
typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
|
162
|
+
<RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
|
163
|
+
|
164
|
+
#define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \
|
165
|
+
typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
|
166
|
+
<RAPIDJSON_REMOVEFPTR_(cond), \
|
167
|
+
RAPIDJSON_REMOVEFPTR_(returntype)>::Type
|
168
|
+
|
169
|
+
#define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \
|
170
|
+
typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
|
171
|
+
<RAPIDJSON_REMOVEFPTR_(cond), \
|
172
|
+
RAPIDJSON_REMOVEFPTR_(returntype)>::Type
|
173
|
+
|
174
|
+
} // namespace internal
|
175
|
+
RAPIDJSON_NAMESPACE_END
|
176
|
+
//@endcond
|
177
|
+
|
178
|
+
#if defined(_MSC_VER) && !defined(__clang__)
|
179
|
+
RAPIDJSON_DIAG_POP
|
180
|
+
#endif
|
181
|
+
|
182
|
+
#ifdef __GNUC__
|
183
|
+
RAPIDJSON_DIAG_POP
|
184
|
+
#endif
|
185
|
+
|
186
|
+
#endif // RAPIDJSON_INTERNAL_META_H_
|
@@ -0,0 +1,55 @@
|
|
1
|
+
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
|
+
//
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
|
+
//
|
5
|
+
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
|
+
// in compliance with the License. You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://opensource.org/licenses/MIT
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software distributed
|
11
|
+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
12
|
+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
13
|
+
// specific language governing permissions and limitations under the License.
|
14
|
+
|
15
|
+
#ifndef RAPIDJSON_POW10_
|
16
|
+
#define RAPIDJSON_POW10_
|
17
|
+
|
18
|
+
#include "../rapidjson.h"
|
19
|
+
|
20
|
+
RAPIDJSON_NAMESPACE_BEGIN
|
21
|
+
namespace internal {
|
22
|
+
|
23
|
+
//! Computes integer powers of 10 in double (10.0^n).
|
24
|
+
/*! This function uses lookup table for fast and accurate results.
|
25
|
+
\param n non-negative exponent. Must <= 308.
|
26
|
+
\return 10.0^n
|
27
|
+
*/
|
28
|
+
inline double Pow10(int n) {
|
29
|
+
static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes
|
30
|
+
1e+0,
|
31
|
+
1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20,
|
32
|
+
1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40,
|
33
|
+
1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60,
|
34
|
+
1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80,
|
35
|
+
1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100,
|
36
|
+
1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120,
|
37
|
+
1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140,
|
38
|
+
1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160,
|
39
|
+
1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180,
|
40
|
+
1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200,
|
41
|
+
1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220,
|
42
|
+
1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240,
|
43
|
+
1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260,
|
44
|
+
1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280,
|
45
|
+
1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300,
|
46
|
+
1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308
|
47
|
+
};
|
48
|
+
RAPIDJSON_ASSERT(n >= 0 && n <= 308);
|
49
|
+
return e[n];
|
50
|
+
}
|
51
|
+
|
52
|
+
} // namespace internal
|
53
|
+
RAPIDJSON_NAMESPACE_END
|
54
|
+
|
55
|
+
#endif // RAPIDJSON_POW10_
|