Skip to content

Commit edf92a7

Browse files
author
Bogdan Degtyariov
committed
WL#13877 Make sure that we use the approved version of RapidJSON code.
1 parent 3b942c8 commit edf92a7

29 files changed

+2273
-771
lines changed

cdk/extra/rapidjson/include/rapidjson/allocators.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ concept Allocator {
5252
\endcode
5353
*/
5454

55+
56+
/*! \def RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY
57+
\ingroup RAPIDJSON_CONFIG
58+
\brief User-defined kDefaultChunkCapacity definition.
59+
60+
User can define this as any \c size that is a power of 2.
61+
*/
62+
63+
#ifndef RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY
64+
#define RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY (64 * 1024)
65+
#endif
66+
67+
5568
///////////////////////////////////////////////////////////////////////////////
5669
// CrtAllocator
5770

@@ -236,7 +249,7 @@ class MemoryPoolAllocator {
236249
*/
237250
bool AddChunk(size_t capacity) {
238251
if (!baseAllocator_)
239-
ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator());
252+
ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)();
240253
if (ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity))) {
241254
chunk->capacity = capacity;
242255
chunk->size = 0;
@@ -248,7 +261,7 @@ class MemoryPoolAllocator {
248261
return false;
249262
}
250263

251-
static const int kDefaultChunkCapacity = 64 * 1024; //!< Default chunk capacity.
264+
static const int kDefaultChunkCapacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY; //!< Default chunk capacity.
252265

253266
//! Chunk header for perpending to each chunk.
254267
/*! Chunks are stored as a singly linked list.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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. All rights reserved.
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_CURSORSTREAMWRAPPER_H_
16+
#define RAPIDJSON_CURSORSTREAMWRAPPER_H_
17+
18+
#include "stream.h"
19+
20+
#if defined(__GNUC__)
21+
RAPIDJSON_DIAG_PUSH
22+
RAPIDJSON_DIAG_OFF(effc++)
23+
#endif
24+
25+
#if defined(_MSC_VER) && _MSC_VER <= 1800
26+
RAPIDJSON_DIAG_PUSH
27+
RAPIDJSON_DIAG_OFF(4702) // unreachable code
28+
RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
29+
#endif
30+
31+
RAPIDJSON_NAMESPACE_BEGIN
32+
33+
34+
//! Cursor stream wrapper for counting line and column number if error exists.
35+
/*!
36+
\tparam InputStream Any stream that implements Stream Concept
37+
*/
38+
template <typename InputStream, typename Encoding = UTF8<> >
39+
class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding> {
40+
public:
41+
typedef typename Encoding::Ch Ch;
42+
43+
CursorStreamWrapper(InputStream& is):
44+
GenericStreamWrapper<InputStream, Encoding>(is), line_(1), col_(0) {}
45+
46+
// counting line and column number
47+
Ch Take() {
48+
Ch ch = this->is_.Take();
49+
if(ch == '\n') {
50+
line_ ++;
51+
col_ = 0;
52+
} else {
53+
col_ ++;
54+
}
55+
return ch;
56+
}
57+
58+
//! Get the error line number, if error exists.
59+
size_t GetLine() const { return line_; }
60+
//! Get the error column number, if error exists.
61+
size_t GetColumn() const { return col_; }
62+
63+
private:
64+
size_t line_; //!< Current Line
65+
size_t col_; //!< Current Column
66+
};
67+
68+
#if defined(_MSC_VER) && _MSC_VER <= 1800
69+
RAPIDJSON_DIAG_POP
70+
#endif
71+
72+
#if defined(__GNUC__)
73+
RAPIDJSON_DIAG_POP
74+
#endif
75+
76+
RAPIDJSON_NAMESPACE_END
77+
78+
#endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_

0 commit comments

Comments
 (0)