├── .gitmodules ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── cmake └── BuildType.cmake ├── config ├── csgo.cfg └── formats.cfg ├── libs └── rapidjson │ ├── include │ └── rapidjson │ │ ├── allocators.h │ │ ├── cursorstreamwrapper.h │ │ ├── document.h │ │ ├── encodedstream.h │ │ ├── encodings.h │ │ ├── error │ │ ├── en.h │ │ └── error.h │ │ ├── filereadstream.h │ │ ├── filewritestream.h │ │ ├── fwd.h │ │ ├── internal │ │ ├── biginteger.h │ │ ├── diyfp.h │ │ ├── dtoa.h │ │ ├── ieee754.h │ │ ├── itoa.h │ │ ├── meta.h │ │ ├── pow10.h │ │ ├── regex.h │ │ ├── stack.h │ │ ├── strfunc.h │ │ ├── strtod.h │ │ └── swap.h │ │ ├── istreamwrapper.h │ │ ├── memorybuffer.h │ │ ├── memorystream.h │ │ ├── msinttypes │ │ ├── inttypes.h │ │ └── stdint.h │ │ ├── ostreamwrapper.h │ │ ├── pointer.h │ │ ├── prettywriter.h │ │ ├── rapidjson.h │ │ ├── reader.h │ │ ├── schema.h │ │ ├── stream.h │ │ ├── stringbuffer.h │ │ └── writer.h │ └── license.txt └── src ├── formatter.cpp ├── formatter.h ├── globals.h ├── logger.h ├── main.cpp └── tools ├── netvars.cpp ├── signatures.cpp ├── tools.cpp └── tools.h /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libs/fmt"] 2 | path = libs/fmt 3 | url = https://github.com/fmtlib/fmt.git 4 | [submodule "libs/tuxproc"] 5 | path = libs/tuxproc 6 | url = https://github.com/Teklad/tuxproc.git 7 | [submodule "libs/libconfig"] 8 | path = libs/libconfig 9 | url = https://github.com/hyperrealm/libconfig.git 10 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | 3 | project(tuxdump VERSION 1.0.0 LANGUAGES CXX) 4 | 5 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") 6 | 7 | include(BuildType) 8 | 9 | find_package(PkgConfig QUIET) 10 | 11 | # Disable some unused things in the subprojects 12 | set(BUILD_TESTS OFF CACHE BOOL "Build libconfig tests") 13 | set(BUILD_EXAMPLES OFF CACHE BOOL "Build libconfig examples") 14 | set(FMT_TEST OFF CACHE BOOL "Disable fmt tests") 15 | 16 | pkg_check_modules(LIBCONFIG REQUIRED libconfig++) 17 | 18 | add_executable(${PROJECT_NAME} 19 | src/formatter.cpp 20 | src/main.cpp 21 | src/tools/signatures.cpp 22 | src/tools/netvars.cpp 23 | ) 24 | 25 | target_include_directories(${PROJECT_NAME} PRIVATE 26 | ${LIBCONFIG_INCLUDE_DIRS} 27 | libs/rapidjson/include 28 | ) 29 | 30 | target_link_libraries(${PROJECT_NAME} PRIVATE 31 | ${LIBCONFIG_LIBRARIES} 32 | fmt 33 | tuxproc 34 | ) 35 | 36 | configure_file("config/csgo.cfg" "${CMAKE_BINARY_DIR}/csgo.cfg" COPYONLY) 37 | configure_file("config/formats.cfg" "${CMAKE_BINARY_DIR}/formats.cfg" COPYONLY) 38 | 39 | target_compile_definitions(${PROJECT_NAME} PRIVATE 40 | PROJECT_NAME="${PROJECT_NAME}") 41 | target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) 42 | target_compile_options(${PROJECT_NAME} PRIVATE 43 | $<$:-Wall -Wextra> 44 | ) 45 | 46 | add_subdirectory(libs/tuxproc) 47 | add_subdirectory(libs/fmt) 48 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2018 Justin Kinnaird 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TuxDump 2 | A Linux offset and CSGO netvar dumper using libconfig. 3 | 4 | ## Getting Started 5 | The following instructions should help you get started using TuxDump. 6 | 7 | ### Prerequisites 8 | * A working C++ compiler (C++11 or higher) 9 | * cmake 10 | * sudo (execution) 11 | 12 | ### Building 13 | First you will need to clone the repository. This can be done with the following command: 14 | ``` 15 | git clone https://github.com/Teklad/tuxdump.git 16 | ``` 17 | 18 | You will need to cd into the created directory and update the submodules: 19 | ``` 20 | cd tuxdump 21 | git submodule update --init --recursive 22 | ``` 23 | 24 | All that is left now is to compile: 25 | ``` 26 | mkdir build && cd build 27 | cmake .. 28 | make 29 | ``` 30 | 31 | You should now have a working copy of TuxDump. 32 | 33 | ### Usage 34 | Basic usage of tuxdump is as follows: 35 | ``` 36 | sudo ./tuxdump [options] [tool] 37 | ``` 38 | 39 | So if you wanted to output netvars in C++ format, you would run: 40 | ``` 41 | sudo ./tuxdump -fcpp netvars 42 | ``` 43 | 44 | The currently available tools are: 45 | * classids 46 | * netvars 47 | * signatures 48 | 49 | The currently available formats are: 50 | * cpp 51 | * java 52 | * json 53 | 54 | For an always up to date list of formats and tools, simply run: 55 | ``` 56 | sudo ./tuxdump -h 57 | ``` 58 | 59 | ### Custom formatting 60 | If you're needing some kind of formatted output that isn't already provided, there is preliminary support for this in the form of formats.cfg. If you add a new format, please feel free to create a pull request so I can get it included into the master branch. 61 | 62 | ### Licensing 63 | This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) file for details. 64 | 65 | -------------------------------------------------------------------------------- /cmake/BuildType.cmake: -------------------------------------------------------------------------------- 1 | # Set a default build type if none was specified 2 | set(default_build_type "Release") 3 | 4 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 5 | message(STATUS "Setting build type to '${default_build_type}' as none was specified.") 6 | set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE 7 | STRING "Choose the type of build." FORCE) 8 | # Set the possible values of build type for cmake-gui 9 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 10 | "Debug" "Release" "MinSizeRel" "RelWithDebInfo") 11 | endif() 12 | -------------------------------------------------------------------------------- /config/csgo.cfg: -------------------------------------------------------------------------------- 1 | signatures: { 2 | dwClientState: { 3 | region = "engine_client.so" 4 | pattern = "488b?????5548??5d48??08c3" 5 | comment = "Add 0x8 after read" 6 | offset = [2] 7 | extra = 0 8 | relative = 1 9 | } 10 | 11 | dwClientState_DeltaTick: { 12 | region = "engine_client.so" 13 | pattern = "8b80??00002b83??000048" 14 | offset = [2] 15 | extra = 4 16 | relative = 0 17 | } 18 | 19 | dwClientState_Map: { 20 | region = "engine_client.so" 21 | pattern = "488d???00004889?c366?55" 22 | offset = [3] 23 | extra = 0 24 | relative = 0 25 | } 26 | 27 | dwClientState_MapDirectory: { 28 | region = "engine_client.so" 29 | pattern = "488d???00004889?c366?48" 30 | offset = [3] 31 | extra = 0 32 | relative = 0 33 | } 34 | 35 | dwClientState_MaxPlayer: { 36 | region = "engine_client.so" 37 | pattern = "443b???00000f8c????488d" 38 | offset = [3] 39 | extra = 0 40 | relative = 0 41 | } 42 | 43 | dwClientState_NextCommandTime: { 44 | region = "engine_client.so" 45 | pattern = "8b93???004183?ff" 46 | offset = [2] 47 | extra = 0 48 | relative = 0 49 | } 50 | 51 | dwClientState_IsHLTV: { 52 | region = "engine_client.so" 53 | pattern = "80???00000148??81" 54 | offset = [2] 55 | extra = 0 56 | relative = 0 57 | } 58 | 59 | dwClientState_PlayerInfo: { 60 | region = "engine_client.so" 61 | pattern = "488b???0000488b?ff??48??49??0f" 62 | offset = [3] 63 | extra = 0 64 | relative = 0 65 | } 66 | 67 | dwClientState_State: { 68 | region = "engine_client.so" 69 | pattern = "488b???000048c1??48??????488b" 70 | offset = [3] 71 | extra = 0 72 | relative = 0 73 | } 74 | 75 | dwClientState_ViewAngles: { 76 | region = "engine_client.so" 77 | pattern = "e8????f30f????0000f30f" 78 | offset = [9] 79 | extra = 0 80 | relative = 0 81 | } 82 | 83 | dwEntityList: { 84 | region = "client_client.so" 85 | pattern = "488d?????488d?????e8????5d488d?????488d?????488d?????e9????????55488d" 86 | offset = [2] 87 | extra = 8 88 | relative = 1 89 | } 90 | 91 | dwForceAlt1: { 92 | region = "client_client.so" 93 | pattern = "8b15????89?80??f6??0f??44??c1?11" 94 | offset = [1] 95 | extra = 0 96 | relative = 1 97 | } 98 | 99 | dwForceAlt2: { 100 | region = "client_client.so" 101 | pattern = "8b15????89?80??f6??0f??44??c1?10" 102 | offset = [1] 103 | extra = 0 104 | relative = 1 105 | } 106 | 107 | dwForceAttack: { 108 | region = "client_client.so" 109 | pattern = "8b15????89?83??f6??0f??44??83??f7?83??45??74?21?8905" 110 | offset = [1] 111 | extra = 0 112 | relative = 1 113 | } 114 | 115 | dwForceAttack2: { 116 | region = "client_client.so" 117 | pattern = "8b15????89?80??f6??0f??44??c1?14" 118 | offset = [1] 119 | extra = 0 120 | relative = 1 121 | } 122 | 123 | dwForceBackward: { 124 | region = "client_client.so" 125 | pattern = "8b15????89?83??f6??0f??44??c1?1b" 126 | offset = [1] 127 | extra = 0 128 | relative = 1 129 | } 130 | 131 | dwForceCrouch: { 132 | region = "client_client.so" 133 | pattern = "8b15????89?83??f6??0f??44??c1?1d" 134 | offset = [1] 135 | extra = 0 136 | relative = 1 137 | } 138 | 139 | dwForceForward: { 140 | region = "client_client.so" 141 | pattern = "8b15????89?83??f6??0f??44??c1?1c" 142 | offset = [1] 143 | extra = 0 144 | relative = 1 145 | } 146 | 147 | dwForceJump: { 148 | region = "client_client.so" 149 | pattern = "8b15????89?83??f6??0f??44??c1?1e" 150 | offset = [1] 151 | extra = 0 152 | relative = 1 153 | } 154 | 155 | dwForceLeft: { 156 | region = "client_client.so" 157 | pattern = "8b15????89?80??f6??0f??44??c1?16" 158 | offset = [1] 159 | extra = 0 160 | relative = 1 161 | } 162 | 163 | dwForceReload: { 164 | region = "client_client.so" 165 | pattern = "8b15????89?80??f6??0f??44??c1?12" 166 | offset = [1] 167 | extra = 0 168 | relative = 1 169 | } 170 | 171 | dwForceRight: { 172 | region = "client_client.so" 173 | pattern = "8b15????89?80??f6??0f??44??c1?15" 174 | offset = [1] 175 | extra = 0 176 | relative = 1 177 | } 178 | 179 | dwForceScoreboard: { 180 | region = "client_client.so" 181 | pattern = "8b15????89?0d????f6??0f??44??c1?0f" 182 | offset = [1] 183 | extra = 0 184 | relative = 1 185 | } 186 | 187 | dwForceTurnLeft: { 188 | region = "client_client.so" 189 | pattern = "8b15????89?0c?f6??0f??44??c1?18" 190 | offset = [1] 191 | extra = 0 192 | relative = 1 193 | } 194 | 195 | dwForceTurnRight: { 196 | region = "client_client.so" 197 | pattern = "8b15????89?80??f6??0f??44??c1?17" 198 | offset = [1] 199 | extra = 0 200 | relative = 1 201 | } 202 | 203 | dwForceUse: { 204 | region = "client_client.so" 205 | pattern = "8b15????89?83??f6??0f??44??c1?1a" 206 | offset = [1] 207 | extra = 0 208 | relative = 1 209 | } 210 | 211 | dwForceWalk: { 212 | region = "client_client.so" 213 | pattern = "8b15????48??41?49??41?41??41?53" 214 | offset = [1] 215 | extra = 0 216 | relative = 1 217 | } 218 | 219 | dwGameDir: { 220 | region = "engine_client.so" 221 | pattern = "488d????004c??e8????48??4c??e8" 222 | offset = [2] 223 | extra = 0 224 | relative = 1 225 | } 226 | 227 | dwGameRulesProxy: { 228 | region = "client_client.so" 229 | pattern = "4c8b?????5389?49???48??74" 230 | offset = [2, 0] 231 | extra = 0 232 | relative = 1 233 | } 234 | 235 | dwGetAllClasses: { 236 | region = "client_client.so" 237 | pattern = "488b?????8b??48??48??75?e9????66" 238 | offset = [2, 0, 0] 239 | extra = 0 240 | relative = 1 241 | } 242 | 243 | dwGlobalVars: { 244 | region = "client_client.so" 245 | pattern = "488b?????f30f???f30f???e8????f30f???48??0f??e8" 246 | offset = [2] 247 | extra = 0 248 | relative = 1 249 | } 250 | 251 | dwGlowObjectManager: { 252 | region = "client_client.so" 253 | pattern = "488d?????488d?????e8????488d?????5dc390" 254 | offset = [2] 255 | extra = 0 256 | relative = 1 257 | } 258 | 259 | dwInput: { 260 | region = "client_client.so" 261 | pattern = "488d?????48??48???48c1??48??c3" 262 | offset = [2] 263 | extra = 0 264 | relative = 1 265 | } 266 | 267 | dwInCrossID: { 268 | region = "client_client.so" 269 | pattern = "8B83????85?75?448b" 270 | offset = [2] 271 | extra = 0 272 | relative = 0 273 | } 274 | 275 | dwLocalPlayer: { 276 | region = "client_client.so" 277 | pattern = "4889e5740e488d05" 278 | offset = [7] 279 | extra = 0 280 | relative = 1 281 | } 282 | 283 | dwPlayerResource: { 284 | region = "client_client.so" 285 | pattern = "4c89?????415c5dc34889?4c89?488d" 286 | offset = [2] 287 | extra = 0 288 | relative = 1 289 | } 290 | 291 | dwPostProcessing: { 292 | region = "client_client.so" 293 | pattern = "803d????0089b5????0f85????85?41" 294 | offset = [1] 295 | extra = 1 296 | relative = 1 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /config/formats.cfg: -------------------------------------------------------------------------------- 1 | formats: { 2 | cpp: { 3 | timestamp = "// Generated on {:%Y-%m-%d %H:%M:%S}\n" 4 | offset = "constexpr uintptr_t {0} = {1:#x};\n" 5 | indent = " " 6 | header = "#ifndef __TD_{0}_H__\n#define __TD_{0}_H__\n#include \n\nnamespace {0} {{\n" 7 | footer = "}}\n#endif //__TD_{0}_H__\n" 8 | table_begin = "namespace {0} {{\n" 9 | table_end = "}}\n" 10 | strip_table_prefix = true 11 | default_depth = 1 12 | replace_chars = ( 13 | ["[", "_"], 14 | [".", "_"], 15 | ["]"] 16 | ) 17 | } 18 | java: { 19 | timestamp = "// Generated on {:%Y-%m-%d %H:%M:%S}\n" 20 | offset = "public static final long {0} = {1:#x};\n" 21 | indent = " " 22 | header = "package me.teklad.tuxdump.{0};\n\npublic class Netvars {{" 23 | footer = "}}\n" 24 | table_begin = "public static class {0} {{\n" 25 | table_end = "}}\n" 26 | strip_table_prefix = true 27 | default_depth = 1 28 | replace_chars = ( 29 | ["[", "_"], 30 | [".", "_"], 31 | ["]"] 32 | ) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/allocators.h: -------------------------------------------------------------------------------- 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_ALLOCATORS_H_ 16 | #define RAPIDJSON_ALLOCATORS_H_ 17 | 18 | #include "rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | 22 | /////////////////////////////////////////////////////////////////////////////// 23 | // Allocator 24 | 25 | /*! \class rapidjson::Allocator 26 | \brief Concept for allocating, resizing and freeing memory block. 27 | 28 | Note that Malloc() and Realloc() are non-static but Free() is static. 29 | 30 | So if an allocator need to support Free(), it needs to put its pointer in 31 | the header of memory block. 32 | 33 | \code 34 | concept Allocator { 35 | static const bool kNeedFree; //!< Whether this allocator needs to call Free(). 36 | 37 | // Allocate a memory block. 38 | // \param size of the memory block in bytes. 39 | // \returns pointer to the memory block. 40 | void* Malloc(size_t size); 41 | 42 | // Resize a memory block. 43 | // \param originalPtr The pointer to current memory block. Null pointer is permitted. 44 | // \param originalSize The current size in bytes. (Design issue: since some allocator may not book-keep this, explicitly pass to it can save memory.) 45 | // \param newSize the new size in bytes. 46 | void* Realloc(void* originalPtr, size_t originalSize, size_t newSize); 47 | 48 | // Free a memory block. 49 | // \param pointer to the memory block. Null pointer is permitted. 50 | static void Free(void *ptr); 51 | }; 52 | \endcode 53 | */ 54 | 55 | 56 | /*! \def RAPIDJSON_ALLOCATOR_DEFUALT_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 | 68 | /////////////////////////////////////////////////////////////////////////////// 69 | // CrtAllocator 70 | 71 | //! C-runtime library allocator. 72 | /*! This class is just wrapper for standard C library memory routines. 73 | \note implements Allocator concept 74 | */ 75 | class CrtAllocator { 76 | public: 77 | static const bool kNeedFree = true; 78 | void* Malloc(size_t size) { 79 | if (size) // behavior of malloc(0) is implementation defined. 80 | return std::malloc(size); 81 | else 82 | return NULL; // standardize to returning NULL. 83 | } 84 | void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { 85 | (void)originalSize; 86 | if (newSize == 0) { 87 | std::free(originalPtr); 88 | return NULL; 89 | } 90 | return std::realloc(originalPtr, newSize); 91 | } 92 | static void Free(void *ptr) { std::free(ptr); } 93 | }; 94 | 95 | /////////////////////////////////////////////////////////////////////////////// 96 | // MemoryPoolAllocator 97 | 98 | //! Default memory allocator used by the parser and DOM. 99 | /*! This allocator allocate memory blocks from pre-allocated memory chunks. 100 | 101 | It does not free memory blocks. And Realloc() only allocate new memory. 102 | 103 | The memory chunks are allocated by BaseAllocator, which is CrtAllocator by default. 104 | 105 | User may also supply a buffer as the first chunk. 106 | 107 | If the user-buffer is full then additional chunks are allocated by BaseAllocator. 108 | 109 | The user-buffer is not deallocated by this allocator. 110 | 111 | \tparam BaseAllocator the allocator type for allocating memory chunks. Default is CrtAllocator. 112 | \note implements Allocator concept 113 | */ 114 | template 115 | class MemoryPoolAllocator { 116 | public: 117 | static const bool kNeedFree = false; //!< Tell users that no need to call Free() with this allocator. (concept Allocator) 118 | 119 | //! Constructor with chunkSize. 120 | /*! \param chunkSize The size of memory chunk. The default is kDefaultChunkSize. 121 | \param baseAllocator The allocator for allocating memory chunks. 122 | */ 123 | MemoryPoolAllocator(size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : 124 | chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(0), baseAllocator_(baseAllocator), ownBaseAllocator_(0) 125 | { 126 | } 127 | 128 | //! Constructor with user-supplied buffer. 129 | /*! The user buffer will be used firstly. When it is full, memory pool allocates new chunk with chunk size. 130 | 131 | The user buffer will not be deallocated when this allocator is destructed. 132 | 133 | \param buffer User supplied buffer. 134 | \param size Size of the buffer in bytes. It must at least larger than sizeof(ChunkHeader). 135 | \param chunkSize The size of memory chunk. The default is kDefaultChunkSize. 136 | \param baseAllocator The allocator for allocating memory chunks. 137 | */ 138 | MemoryPoolAllocator(void *buffer, size_t size, size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : 139 | chunkHead_(0), chunk_capacity_(chunkSize), userBuffer_(buffer), baseAllocator_(baseAllocator), ownBaseAllocator_(0) 140 | { 141 | RAPIDJSON_ASSERT(buffer != 0); 142 | RAPIDJSON_ASSERT(size > sizeof(ChunkHeader)); 143 | chunkHead_ = reinterpret_cast(buffer); 144 | chunkHead_->capacity = size - sizeof(ChunkHeader); 145 | chunkHead_->size = 0; 146 | chunkHead_->next = 0; 147 | } 148 | 149 | //! Destructor. 150 | /*! This deallocates all memory chunks, excluding the user-supplied buffer. 151 | */ 152 | ~MemoryPoolAllocator() { 153 | Clear(); 154 | RAPIDJSON_DELETE(ownBaseAllocator_); 155 | } 156 | 157 | //! Deallocates all memory chunks, excluding the user-supplied buffer. 158 | void Clear() { 159 | while (chunkHead_ && chunkHead_ != userBuffer_) { 160 | ChunkHeader* next = chunkHead_->next; 161 | baseAllocator_->Free(chunkHead_); 162 | chunkHead_ = next; 163 | } 164 | if (chunkHead_ && chunkHead_ == userBuffer_) 165 | chunkHead_->size = 0; // Clear user buffer 166 | } 167 | 168 | //! Computes the total capacity of allocated memory chunks. 169 | /*! \return total capacity in bytes. 170 | */ 171 | size_t Capacity() const { 172 | size_t capacity = 0; 173 | for (ChunkHeader* c = chunkHead_; c != 0; c = c->next) 174 | capacity += c->capacity; 175 | return capacity; 176 | } 177 | 178 | //! Computes the memory blocks allocated. 179 | /*! \return total used bytes. 180 | */ 181 | size_t Size() const { 182 | size_t size = 0; 183 | for (ChunkHeader* c = chunkHead_; c != 0; c = c->next) 184 | size += c->size; 185 | return size; 186 | } 187 | 188 | //! Allocates a memory block. (concept Allocator) 189 | void* Malloc(size_t size) { 190 | if (!size) 191 | return NULL; 192 | 193 | size = RAPIDJSON_ALIGN(size); 194 | if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity) 195 | if (!AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size)) 196 | return NULL; 197 | 198 | void *buffer = reinterpret_cast(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size; 199 | chunkHead_->size += size; 200 | return buffer; 201 | } 202 | 203 | //! Resizes a memory block (concept Allocator) 204 | void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { 205 | if (originalPtr == 0) 206 | return Malloc(newSize); 207 | 208 | if (newSize == 0) 209 | return NULL; 210 | 211 | originalSize = RAPIDJSON_ALIGN(originalSize); 212 | newSize = RAPIDJSON_ALIGN(newSize); 213 | 214 | // Do not shrink if new size is smaller than original 215 | if (originalSize >= newSize) 216 | return originalPtr; 217 | 218 | // Simply expand it if it is the last allocation and there is sufficient space 219 | if (originalPtr == reinterpret_cast(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size - originalSize) { 220 | size_t increment = static_cast(newSize - originalSize); 221 | if (chunkHead_->size + increment <= chunkHead_->capacity) { 222 | chunkHead_->size += increment; 223 | return originalPtr; 224 | } 225 | } 226 | 227 | // Realloc process: allocate and copy memory, do not free original buffer. 228 | if (void* newBuffer = Malloc(newSize)) { 229 | if (originalSize) 230 | std::memcpy(newBuffer, originalPtr, originalSize); 231 | return newBuffer; 232 | } 233 | else 234 | return NULL; 235 | } 236 | 237 | //! Frees a memory block (concept Allocator) 238 | static void Free(void *ptr) { (void)ptr; } // Do nothing 239 | 240 | private: 241 | //! Copy constructor is not permitted. 242 | MemoryPoolAllocator(const MemoryPoolAllocator& rhs) /* = delete */; 243 | //! Copy assignment operator is not permitted. 244 | MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) /* = delete */; 245 | 246 | //! Creates a new chunk. 247 | /*! \param capacity Capacity of the chunk in bytes. 248 | \return true if success. 249 | */ 250 | bool AddChunk(size_t capacity) { 251 | if (!baseAllocator_) 252 | ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)(); 253 | if (ChunkHeader* chunk = reinterpret_cast(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity))) { 254 | chunk->capacity = capacity; 255 | chunk->size = 0; 256 | chunk->next = chunkHead_; 257 | chunkHead_ = chunk; 258 | return true; 259 | } 260 | else 261 | return false; 262 | } 263 | 264 | static const int kDefaultChunkCapacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY; //!< Default chunk capacity. 265 | 266 | //! Chunk header for perpending to each chunk. 267 | /*! Chunks are stored as a singly linked list. 268 | */ 269 | struct ChunkHeader { 270 | size_t capacity; //!< Capacity of the chunk in bytes (excluding the header itself). 271 | size_t size; //!< Current size of allocated memory in bytes. 272 | ChunkHeader *next; //!< Next chunk in the linked list. 273 | }; 274 | 275 | ChunkHeader *chunkHead_; //!< Head of the chunk linked-list. Only the head chunk serves allocation. 276 | size_t chunk_capacity_; //!< The minimum capacity of chunk when they are allocated. 277 | void *userBuffer_; //!< User supplied buffer. 278 | BaseAllocator* baseAllocator_; //!< base allocator for allocating memory chunks. 279 | BaseAllocator* ownBaseAllocator_; //!< base allocator created by this object. 280 | }; 281 | 282 | RAPIDJSON_NAMESPACE_END 283 | 284 | #endif // RAPIDJSON_ENCODINGS_H_ 285 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/cursorstreamwrapper.h: -------------------------------------------------------------------------------- 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 > 39 | class CursorStreamWrapper : public GenericStreamWrapper { 40 | public: 41 | typedef typename Encoding::Ch Ch; 42 | 43 | CursorStreamWrapper(InputStream& is): 44 | GenericStreamWrapper(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_ 79 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/encodedstream.h: -------------------------------------------------------------------------------- 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_ENCODEDSTREAM_H_ 16 | #define RAPIDJSON_ENCODEDSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include "memorystream.h" 20 | 21 | #ifdef __GNUC__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(effc++) 24 | #endif 25 | 26 | #ifdef __clang__ 27 | RAPIDJSON_DIAG_PUSH 28 | RAPIDJSON_DIAG_OFF(padded) 29 | #endif 30 | 31 | RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | //! Input byte stream wrapper with a statically bound encoding. 34 | /*! 35 | \tparam Encoding The interpretation of encoding of the stream. Either UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE. 36 | \tparam InputByteStream Type of input byte stream. For example, FileReadStream. 37 | */ 38 | template 39 | class EncodedInputStream { 40 | RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); 41 | public: 42 | typedef typename Encoding::Ch Ch; 43 | 44 | EncodedInputStream(InputByteStream& is) : is_(is) { 45 | current_ = Encoding::TakeBOM(is_); 46 | } 47 | 48 | Ch Peek() const { return current_; } 49 | Ch Take() { Ch c = current_; current_ = Encoding::Take(is_); return c; } 50 | size_t Tell() const { return is_.Tell(); } 51 | 52 | // Not implemented 53 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 54 | void Flush() { RAPIDJSON_ASSERT(false); } 55 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 56 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 57 | 58 | private: 59 | EncodedInputStream(const EncodedInputStream&); 60 | EncodedInputStream& operator=(const EncodedInputStream&); 61 | 62 | InputByteStream& is_; 63 | Ch current_; 64 | }; 65 | 66 | //! Specialized for UTF8 MemoryStream. 67 | template <> 68 | class EncodedInputStream, MemoryStream> { 69 | public: 70 | typedef UTF8<>::Ch Ch; 71 | 72 | EncodedInputStream(MemoryStream& is) : is_(is) { 73 | if (static_cast(is_.Peek()) == 0xEFu) is_.Take(); 74 | if (static_cast(is_.Peek()) == 0xBBu) is_.Take(); 75 | if (static_cast(is_.Peek()) == 0xBFu) is_.Take(); 76 | } 77 | Ch Peek() const { return is_.Peek(); } 78 | Ch Take() { return is_.Take(); } 79 | size_t Tell() const { return is_.Tell(); } 80 | 81 | // Not implemented 82 | void Put(Ch) {} 83 | void Flush() {} 84 | Ch* PutBegin() { return 0; } 85 | size_t PutEnd(Ch*) { return 0; } 86 | 87 | MemoryStream& is_; 88 | 89 | private: 90 | EncodedInputStream(const EncodedInputStream&); 91 | EncodedInputStream& operator=(const EncodedInputStream&); 92 | }; 93 | 94 | //! Output byte stream wrapper with statically bound encoding. 95 | /*! 96 | \tparam Encoding The interpretation of encoding of the stream. Either UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE. 97 | \tparam OutputByteStream Type of input byte stream. For example, FileWriteStream. 98 | */ 99 | template 100 | class EncodedOutputStream { 101 | RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); 102 | public: 103 | typedef typename Encoding::Ch Ch; 104 | 105 | EncodedOutputStream(OutputByteStream& os, bool putBOM = true) : os_(os) { 106 | if (putBOM) 107 | Encoding::PutBOM(os_); 108 | } 109 | 110 | void Put(Ch c) { Encoding::Put(os_, c); } 111 | void Flush() { os_.Flush(); } 112 | 113 | // Not implemented 114 | Ch Peek() const { RAPIDJSON_ASSERT(false); return 0;} 115 | Ch Take() { RAPIDJSON_ASSERT(false); return 0;} 116 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 117 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 118 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 119 | 120 | private: 121 | EncodedOutputStream(const EncodedOutputStream&); 122 | EncodedOutputStream& operator=(const EncodedOutputStream&); 123 | 124 | OutputByteStream& os_; 125 | }; 126 | 127 | #define RAPIDJSON_ENCODINGS_FUNC(x) UTF8::x, UTF16LE::x, UTF16BE::x, UTF32LE::x, UTF32BE::x 128 | 129 | //! Input stream wrapper with dynamically bound encoding and automatic encoding detection. 130 | /*! 131 | \tparam CharType Type of character for reading. 132 | \tparam InputByteStream type of input byte stream to be wrapped. 133 | */ 134 | template 135 | class AutoUTFInputStream { 136 | RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1); 137 | public: 138 | typedef CharType Ch; 139 | 140 | //! Constructor. 141 | /*! 142 | \param is input stream to be wrapped. 143 | \param type UTF encoding type if it is not detected from the stream. 144 | */ 145 | AutoUTFInputStream(InputByteStream& is, UTFType type = kUTF8) : is_(&is), type_(type), hasBOM_(false) { 146 | RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE); 147 | DetectType(); 148 | static const TakeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Take) }; 149 | takeFunc_ = f[type_]; 150 | current_ = takeFunc_(*is_); 151 | } 152 | 153 | UTFType GetType() const { return type_; } 154 | bool HasBOM() const { return hasBOM_; } 155 | 156 | Ch Peek() const { return current_; } 157 | Ch Take() { Ch c = current_; current_ = takeFunc_(*is_); return c; } 158 | size_t Tell() const { return is_->Tell(); } 159 | 160 | // Not implemented 161 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 162 | void Flush() { RAPIDJSON_ASSERT(false); } 163 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 164 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 165 | 166 | private: 167 | AutoUTFInputStream(const AutoUTFInputStream&); 168 | AutoUTFInputStream& operator=(const AutoUTFInputStream&); 169 | 170 | // Detect encoding type with BOM or RFC 4627 171 | void DetectType() { 172 | // BOM (Byte Order Mark): 173 | // 00 00 FE FF UTF-32BE 174 | // FF FE 00 00 UTF-32LE 175 | // FE FF UTF-16BE 176 | // FF FE UTF-16LE 177 | // EF BB BF UTF-8 178 | 179 | const unsigned char* c = reinterpret_cast(is_->Peek4()); 180 | if (!c) 181 | return; 182 | 183 | unsigned bom = static_cast(c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24)); 184 | hasBOM_ = false; 185 | if (bom == 0xFFFE0000) { type_ = kUTF32BE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); } 186 | else if (bom == 0x0000FEFF) { type_ = kUTF32LE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); } 187 | else if ((bom & 0xFFFF) == 0xFFFE) { type_ = kUTF16BE; hasBOM_ = true; is_->Take(); is_->Take(); } 188 | else if ((bom & 0xFFFF) == 0xFEFF) { type_ = kUTF16LE; hasBOM_ = true; is_->Take(); is_->Take(); } 189 | else if ((bom & 0xFFFFFF) == 0xBFBBEF) { type_ = kUTF8; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); } 190 | 191 | // RFC 4627: Section 3 192 | // "Since the first two characters of a JSON text will always be ASCII 193 | // characters [RFC0020], it is possible to determine whether an octet 194 | // stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking 195 | // at the pattern of nulls in the first four octets." 196 | // 00 00 00 xx UTF-32BE 197 | // 00 xx 00 xx UTF-16BE 198 | // xx 00 00 00 UTF-32LE 199 | // xx 00 xx 00 UTF-16LE 200 | // xx xx xx xx UTF-8 201 | 202 | if (!hasBOM_) { 203 | int pattern = (c[0] ? 1 : 0) | (c[1] ? 2 : 0) | (c[2] ? 4 : 0) | (c[3] ? 8 : 0); 204 | switch (pattern) { 205 | case 0x08: type_ = kUTF32BE; break; 206 | case 0x0A: type_ = kUTF16BE; break; 207 | case 0x01: type_ = kUTF32LE; break; 208 | case 0x05: type_ = kUTF16LE; break; 209 | case 0x0F: type_ = kUTF8; break; 210 | default: break; // Use type defined by user. 211 | } 212 | } 213 | 214 | // Runtime check whether the size of character type is sufficient. It only perform checks with assertion. 215 | if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2); 216 | if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4); 217 | } 218 | 219 | typedef Ch (*TakeFunc)(InputByteStream& is); 220 | InputByteStream* is_; 221 | UTFType type_; 222 | Ch current_; 223 | TakeFunc takeFunc_; 224 | bool hasBOM_; 225 | }; 226 | 227 | //! Output stream wrapper with dynamically bound encoding and automatic encoding detection. 228 | /*! 229 | \tparam CharType Type of character for writing. 230 | \tparam OutputByteStream type of output byte stream to be wrapped. 231 | */ 232 | template 233 | class AutoUTFOutputStream { 234 | RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); 235 | public: 236 | typedef CharType Ch; 237 | 238 | //! Constructor. 239 | /*! 240 | \param os output stream to be wrapped. 241 | \param type UTF encoding type. 242 | \param putBOM Whether to write BOM at the beginning of the stream. 243 | */ 244 | AutoUTFOutputStream(OutputByteStream& os, UTFType type, bool putBOM) : os_(&os), type_(type) { 245 | RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE); 246 | 247 | // Runtime check whether the size of character type is sufficient. It only perform checks with assertion. 248 | if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2); 249 | if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4); 250 | 251 | static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) }; 252 | putFunc_ = f[type_]; 253 | 254 | if (putBOM) 255 | PutBOM(); 256 | } 257 | 258 | UTFType GetType() const { return type_; } 259 | 260 | void Put(Ch c) { putFunc_(*os_, c); } 261 | void Flush() { os_->Flush(); } 262 | 263 | // Not implemented 264 | Ch Peek() const { RAPIDJSON_ASSERT(false); return 0;} 265 | Ch Take() { RAPIDJSON_ASSERT(false); return 0;} 266 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 267 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 268 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 269 | 270 | private: 271 | AutoUTFOutputStream(const AutoUTFOutputStream&); 272 | AutoUTFOutputStream& operator=(const AutoUTFOutputStream&); 273 | 274 | void PutBOM() { 275 | typedef void (*PutBOMFunc)(OutputByteStream&); 276 | static const PutBOMFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(PutBOM) }; 277 | f[type_](*os_); 278 | } 279 | 280 | typedef void (*PutFunc)(OutputByteStream&, Ch); 281 | 282 | OutputByteStream* os_; 283 | UTFType type_; 284 | PutFunc putFunc_; 285 | }; 286 | 287 | #undef RAPIDJSON_ENCODINGS_FUNC 288 | 289 | RAPIDJSON_NAMESPACE_END 290 | 291 | #ifdef __clang__ 292 | RAPIDJSON_DIAG_POP 293 | #endif 294 | 295 | #ifdef __GNUC__ 296 | RAPIDJSON_DIAG_POP 297 | #endif 298 | 299 | #endif // RAPIDJSON_FILESTREAM_H_ 300 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/error/en.h: -------------------------------------------------------------------------------- 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_ERROR_EN_H_ 16 | #define RAPIDJSON_ERROR_EN_H_ 17 | 18 | #include "error.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(switch-enum) 23 | RAPIDJSON_DIAG_OFF(covered-switch-default) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Maps error code of parsing into error message. 29 | /*! 30 | \ingroup RAPIDJSON_ERRORS 31 | \param parseErrorCode Error code obtained in parsing. 32 | \return the error message. 33 | \note User can make a copy of this function for localization. 34 | Using switch-case is safer for future modification of error codes. 35 | */ 36 | inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) { 37 | switch (parseErrorCode) { 38 | case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error."); 39 | 40 | case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty."); 41 | case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values."); 42 | 43 | case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value."); 44 | 45 | case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member."); 46 | case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member."); 47 | case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member."); 48 | 49 | case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element."); 50 | 51 | case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string."); 52 | case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid."); 53 | case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string."); 54 | case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string."); 55 | case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string."); 56 | 57 | case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double."); 58 | case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number."); 59 | case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number."); 60 | 61 | case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error."); 62 | case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error."); 63 | 64 | default: return RAPIDJSON_ERROR_STRING("Unknown error."); 65 | } 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #ifdef __clang__ 71 | RAPIDJSON_DIAG_POP 72 | #endif 73 | 74 | #endif // RAPIDJSON_ERROR_EN_H_ 75 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/error/error.h: -------------------------------------------------------------------------------- 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_ERROR_ERROR_H_ 16 | #define RAPIDJSON_ERROR_ERROR_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(padded) 23 | #endif 24 | 25 | /*! \file error.h */ 26 | 27 | /*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // RAPIDJSON_ERROR_CHARTYPE 31 | 32 | //! Character type of error messages. 33 | /*! \ingroup RAPIDJSON_ERRORS 34 | The default character type is \c char. 35 | On Windows, user can define this macro as \c TCHAR for supporting both 36 | unicode/non-unicode settings. 37 | */ 38 | #ifndef RAPIDJSON_ERROR_CHARTYPE 39 | #define RAPIDJSON_ERROR_CHARTYPE char 40 | #endif 41 | 42 | /////////////////////////////////////////////////////////////////////////////// 43 | // RAPIDJSON_ERROR_STRING 44 | 45 | //! Macro for converting string literial to \ref RAPIDJSON_ERROR_CHARTYPE[]. 46 | /*! \ingroup RAPIDJSON_ERRORS 47 | By default this conversion macro does nothing. 48 | On Windows, user can define this macro as \c _T(x) for supporting both 49 | unicode/non-unicode settings. 50 | */ 51 | #ifndef RAPIDJSON_ERROR_STRING 52 | #define RAPIDJSON_ERROR_STRING(x) x 53 | #endif 54 | 55 | RAPIDJSON_NAMESPACE_BEGIN 56 | 57 | /////////////////////////////////////////////////////////////////////////////// 58 | // ParseErrorCode 59 | 60 | //! Error code of parsing. 61 | /*! \ingroup RAPIDJSON_ERRORS 62 | \see GenericReader::Parse, GenericReader::GetParseErrorCode 63 | */ 64 | enum ParseErrorCode { 65 | kParseErrorNone = 0, //!< No error. 66 | 67 | kParseErrorDocumentEmpty, //!< The document is empty. 68 | kParseErrorDocumentRootNotSingular, //!< The document root must not follow by other values. 69 | 70 | kParseErrorValueInvalid, //!< Invalid value. 71 | 72 | kParseErrorObjectMissName, //!< Missing a name for object member. 73 | kParseErrorObjectMissColon, //!< Missing a colon after a name of object member. 74 | kParseErrorObjectMissCommaOrCurlyBracket, //!< Missing a comma or '}' after an object member. 75 | 76 | kParseErrorArrayMissCommaOrSquareBracket, //!< Missing a comma or ']' after an array element. 77 | 78 | kParseErrorStringUnicodeEscapeInvalidHex, //!< Incorrect hex digit after \\u escape in string. 79 | kParseErrorStringUnicodeSurrogateInvalid, //!< The surrogate pair in string is invalid. 80 | kParseErrorStringEscapeInvalid, //!< Invalid escape character in string. 81 | kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string. 82 | kParseErrorStringInvalidEncoding, //!< Invalid encoding in string. 83 | 84 | kParseErrorNumberTooBig, //!< Number too big to be stored in double. 85 | kParseErrorNumberMissFraction, //!< Miss fraction part in number. 86 | kParseErrorNumberMissExponent, //!< Miss exponent in number. 87 | 88 | kParseErrorTermination, //!< Parsing was terminated. 89 | kParseErrorUnspecificSyntaxError //!< Unspecific syntax error. 90 | }; 91 | 92 | //! Result of parsing (wraps ParseErrorCode) 93 | /*! 94 | \ingroup RAPIDJSON_ERRORS 95 | \code 96 | Document doc; 97 | ParseResult ok = doc.Parse("[42]"); 98 | if (!ok) { 99 | fprintf(stderr, "JSON parse error: %s (%u)", 100 | GetParseError_En(ok.Code()), ok.Offset()); 101 | exit(EXIT_FAILURE); 102 | } 103 | \endcode 104 | \see GenericReader::Parse, GenericDocument::Parse 105 | */ 106 | struct ParseResult { 107 | //!! Unspecified boolean type 108 | typedef bool (ParseResult::*BooleanType)() const; 109 | public: 110 | //! Default constructor, no error. 111 | ParseResult() : code_(kParseErrorNone), offset_(0) {} 112 | //! Constructor to set an error. 113 | ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {} 114 | 115 | //! Get the error code. 116 | ParseErrorCode Code() const { return code_; } 117 | //! Get the error offset, if \ref IsError(), 0 otherwise. 118 | size_t Offset() const { return offset_; } 119 | 120 | //! Explicit conversion to \c bool, returns \c true, iff !\ref IsError(). 121 | operator BooleanType() const { return !IsError() ? &ParseResult::IsError : NULL; } 122 | //! Whether the result is an error. 123 | bool IsError() const { return code_ != kParseErrorNone; } 124 | 125 | bool operator==(const ParseResult& that) const { return code_ == that.code_; } 126 | bool operator==(ParseErrorCode code) const { return code_ == code; } 127 | friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; } 128 | 129 | bool operator!=(const ParseResult& that) const { return !(*this == that); } 130 | bool operator!=(ParseErrorCode code) const { return !(*this == code); } 131 | friend bool operator!=(ParseErrorCode code, const ParseResult & err) { return err != code; } 132 | 133 | //! Reset error code. 134 | void Clear() { Set(kParseErrorNone); } 135 | //! Update error code and offset. 136 | void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; } 137 | 138 | private: 139 | ParseErrorCode code_; 140 | size_t offset_; 141 | }; 142 | 143 | //! Function pointer type of GetParseError(). 144 | /*! \ingroup RAPIDJSON_ERRORS 145 | 146 | This is the prototype for \c GetParseError_X(), where \c X is a locale. 147 | User can dynamically change locale in runtime, e.g.: 148 | \code 149 | GetParseErrorFunc GetParseError = GetParseError_En; // or whatever 150 | const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode()); 151 | \endcode 152 | */ 153 | typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode); 154 | 155 | RAPIDJSON_NAMESPACE_END 156 | 157 | #ifdef __clang__ 158 | RAPIDJSON_DIAG_POP 159 | #endif 160 | 161 | #endif // RAPIDJSON_ERROR_ERROR_H_ 162 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/filereadstream.h: -------------------------------------------------------------------------------- 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_FILEREADSTREAM_H_ 16 | #define RAPIDJSON_FILEREADSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | RAPIDJSON_DIAG_OFF(unreachable-code) 25 | RAPIDJSON_DIAG_OFF(missing-noreturn) 26 | #endif 27 | 28 | RAPIDJSON_NAMESPACE_BEGIN 29 | 30 | //! File byte stream for input using fread(). 31 | /*! 32 | \note implements Stream concept 33 | */ 34 | class FileReadStream { 35 | public: 36 | typedef char Ch; //!< Character type (byte). 37 | 38 | //! Constructor. 39 | /*! 40 | \param fp File pointer opened for read. 41 | \param buffer user-supplied buffer. 42 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 43 | */ 44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 45 | RAPIDJSON_ASSERT(fp_ != 0); 46 | RAPIDJSON_ASSERT(bufferSize >= 4); 47 | Read(); 48 | } 49 | 50 | Ch Peek() const { return *current_; } 51 | Ch Take() { Ch c = *current_; Read(); return c; } 52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 53 | 54 | // Not implemented 55 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 56 | void Flush() { RAPIDJSON_ASSERT(false); } 57 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 58 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 59 | 60 | // For encoding detection only. 61 | const Ch* Peek4() const { 62 | return (current_ + 4 <= bufferLast_) ? current_ : 0; 63 | } 64 | 65 | private: 66 | void Read() { 67 | if (current_ < bufferLast_) 68 | ++current_; 69 | else if (!eof_) { 70 | count_ += readCount_; 71 | readCount_ = std::fread(buffer_, 1, bufferSize_, fp_); 72 | bufferLast_ = buffer_ + readCount_ - 1; 73 | current_ = buffer_; 74 | 75 | if (readCount_ < bufferSize_) { 76 | buffer_[readCount_] = '\0'; 77 | ++bufferLast_; 78 | eof_ = true; 79 | } 80 | } 81 | } 82 | 83 | std::FILE* fp_; 84 | Ch *buffer_; 85 | size_t bufferSize_; 86 | Ch *bufferLast_; 87 | Ch *current_; 88 | size_t readCount_; 89 | size_t count_; //!< Number of characters read 90 | bool eof_; 91 | }; 92 | 93 | RAPIDJSON_NAMESPACE_END 94 | 95 | #ifdef __clang__ 96 | RAPIDJSON_DIAG_POP 97 | #endif 98 | 99 | #endif // RAPIDJSON_FILESTREAM_H_ 100 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/filewritestream.h: -------------------------------------------------------------------------------- 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_FILEWRITESTREAM_H_ 16 | #define RAPIDJSON_FILEWRITESTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(unreachable-code) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of C file stream for output using fwrite(). 29 | /*! 30 | \note implements Stream concept 31 | */ 32 | class FileWriteStream { 33 | public: 34 | typedef char Ch; //!< Character type. Only support char. 35 | 36 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { 37 | RAPIDJSON_ASSERT(fp_ != 0); 38 | } 39 | 40 | void Put(char c) { 41 | if (current_ >= bufferEnd_) 42 | Flush(); 43 | 44 | *current_++ = c; 45 | } 46 | 47 | void PutN(char c, size_t n) { 48 | size_t avail = static_cast(bufferEnd_ - current_); 49 | while (n > avail) { 50 | std::memset(current_, c, avail); 51 | current_ += avail; 52 | Flush(); 53 | n -= avail; 54 | avail = static_cast(bufferEnd_ - current_); 55 | } 56 | 57 | if (n > 0) { 58 | std::memset(current_, c, n); 59 | current_ += n; 60 | } 61 | } 62 | 63 | void Flush() { 64 | if (current_ != buffer_) { 65 | size_t result = std::fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_); 66 | if (result < static_cast(current_ - buffer_)) { 67 | // failure deliberately ignored at this time 68 | // added to avoid warn_unused_result build errors 69 | } 70 | current_ = buffer_; 71 | } 72 | } 73 | 74 | // Not implemented 75 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 76 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 77 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 78 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 79 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 80 | 81 | private: 82 | // Prohibit copy constructor & assignment operator. 83 | FileWriteStream(const FileWriteStream&); 84 | FileWriteStream& operator=(const FileWriteStream&); 85 | 86 | std::FILE* fp_; 87 | char *buffer_; 88 | char *bufferEnd_; 89 | char *current_; 90 | }; 91 | 92 | //! Implement specialized version of PutN() with memset() for better performance. 93 | template<> 94 | inline void PutN(FileWriteStream& stream, char c, size_t n) { 95 | stream.PutN(c, n); 96 | } 97 | 98 | RAPIDJSON_NAMESPACE_END 99 | 100 | #ifdef __clang__ 101 | RAPIDJSON_DIAG_POP 102 | #endif 103 | 104 | #endif // RAPIDJSON_FILESTREAM_H_ 105 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/fwd.h: -------------------------------------------------------------------------------- 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_FWD_H_ 16 | #define RAPIDJSON_FWD_H_ 17 | 18 | #include "rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | 22 | // encodings.h 23 | 24 | template struct UTF8; 25 | template struct UTF16; 26 | template struct UTF16BE; 27 | template struct UTF16LE; 28 | template struct UTF32; 29 | template struct UTF32BE; 30 | template struct UTF32LE; 31 | template struct ASCII; 32 | template struct AutoUTF; 33 | 34 | template 35 | struct Transcoder; 36 | 37 | // allocators.h 38 | 39 | class CrtAllocator; 40 | 41 | template 42 | class MemoryPoolAllocator; 43 | 44 | // stream.h 45 | 46 | template 47 | struct GenericStringStream; 48 | 49 | typedef GenericStringStream > StringStream; 50 | 51 | template 52 | struct GenericInsituStringStream; 53 | 54 | typedef GenericInsituStringStream > InsituStringStream; 55 | 56 | // stringbuffer.h 57 | 58 | template 59 | class GenericStringBuffer; 60 | 61 | typedef GenericStringBuffer, CrtAllocator> StringBuffer; 62 | 63 | // filereadstream.h 64 | 65 | class FileReadStream; 66 | 67 | // filewritestream.h 68 | 69 | class FileWriteStream; 70 | 71 | // memorybuffer.h 72 | 73 | template 74 | struct GenericMemoryBuffer; 75 | 76 | typedef GenericMemoryBuffer MemoryBuffer; 77 | 78 | // memorystream.h 79 | 80 | struct MemoryStream; 81 | 82 | // reader.h 83 | 84 | template 85 | struct BaseReaderHandler; 86 | 87 | template 88 | class GenericReader; 89 | 90 | typedef GenericReader, UTF8, CrtAllocator> Reader; 91 | 92 | // writer.h 93 | 94 | template 95 | class Writer; 96 | 97 | // prettywriter.h 98 | 99 | template 100 | class PrettyWriter; 101 | 102 | // document.h 103 | 104 | template 105 | struct GenericMember; 106 | 107 | template 108 | class GenericMemberIterator; 109 | 110 | template 111 | struct GenericStringRef; 112 | 113 | template 114 | class GenericValue; 115 | 116 | typedef GenericValue, MemoryPoolAllocator > Value; 117 | 118 | template 119 | class GenericDocument; 120 | 121 | typedef GenericDocument, MemoryPoolAllocator, CrtAllocator> Document; 122 | 123 | // pointer.h 124 | 125 | template 126 | class GenericPointer; 127 | 128 | typedef GenericPointer Pointer; 129 | 130 | // schema.h 131 | 132 | template 133 | class IGenericRemoteSchemaDocumentProvider; 134 | 135 | template 136 | class GenericSchemaDocument; 137 | 138 | typedef GenericSchemaDocument SchemaDocument; 139 | typedef IGenericRemoteSchemaDocumentProvider IRemoteSchemaDocumentProvider; 140 | 141 | template < 142 | typename SchemaDocumentType, 143 | typename OutputHandler, 144 | typename StateAllocator> 145 | class GenericSchemaValidator; 146 | 147 | typedef GenericSchemaValidator, void>, CrtAllocator> SchemaValidator; 148 | 149 | RAPIDJSON_NAMESPACE_END 150 | 151 | #endif // RAPIDJSON_RAPIDJSONFWD_H_ 152 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/biginteger.h: -------------------------------------------------------------------------------- 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_BIGINTEGER_H_ 16 | #define RAPIDJSON_BIGINTEGER_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(_MSC_VER) && !__INTEL_COMPILER && defined(_M_AMD64) 21 | #include // for _umul128 22 | #pragma intrinsic(_umul128) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | class BigInteger { 29 | public: 30 | typedef uint64_t Type; 31 | 32 | BigInteger(const BigInteger& rhs) : count_(rhs.count_) { 33 | std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); 34 | } 35 | 36 | explicit BigInteger(uint64_t u) : count_(1) { 37 | digits_[0] = u; 38 | } 39 | 40 | BigInteger(const char* decimals, size_t length) : count_(1) { 41 | RAPIDJSON_ASSERT(length > 0); 42 | digits_[0] = 0; 43 | size_t i = 0; 44 | const size_t kMaxDigitPerIteration = 19; // 2^64 = 18446744073709551616 > 10^19 45 | while (length >= kMaxDigitPerIteration) { 46 | AppendDecimal64(decimals + i, decimals + i + kMaxDigitPerIteration); 47 | length -= kMaxDigitPerIteration; 48 | i += kMaxDigitPerIteration; 49 | } 50 | 51 | if (length > 0) 52 | AppendDecimal64(decimals + i, decimals + i + length); 53 | } 54 | 55 | BigInteger& operator=(const BigInteger &rhs) 56 | { 57 | if (this != &rhs) { 58 | count_ = rhs.count_; 59 | std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); 60 | } 61 | return *this; 62 | } 63 | 64 | BigInteger& operator=(uint64_t u) { 65 | digits_[0] = u; 66 | count_ = 1; 67 | return *this; 68 | } 69 | 70 | BigInteger& operator+=(uint64_t u) { 71 | Type backup = digits_[0]; 72 | digits_[0] += u; 73 | for (size_t i = 0; i < count_ - 1; i++) { 74 | if (digits_[i] >= backup) 75 | return *this; // no carry 76 | backup = digits_[i + 1]; 77 | digits_[i + 1] += 1; 78 | } 79 | 80 | // Last carry 81 | if (digits_[count_ - 1] < backup) 82 | PushBack(1); 83 | 84 | return *this; 85 | } 86 | 87 | BigInteger& operator*=(uint64_t u) { 88 | if (u == 0) return *this = 0; 89 | if (u == 1) return *this; 90 | if (*this == 1) return *this = u; 91 | 92 | uint64_t k = 0; 93 | for (size_t i = 0; i < count_; i++) { 94 | uint64_t hi; 95 | digits_[i] = MulAdd64(digits_[i], u, k, &hi); 96 | k = hi; 97 | } 98 | 99 | if (k > 0) 100 | PushBack(k); 101 | 102 | return *this; 103 | } 104 | 105 | BigInteger& operator*=(uint32_t u) { 106 | if (u == 0) return *this = 0; 107 | if (u == 1) return *this; 108 | if (*this == 1) return *this = u; 109 | 110 | uint64_t k = 0; 111 | for (size_t i = 0; i < count_; i++) { 112 | const uint64_t c = digits_[i] >> 32; 113 | const uint64_t d = digits_[i] & 0xFFFFFFFF; 114 | const uint64_t uc = u * c; 115 | const uint64_t ud = u * d; 116 | const uint64_t p0 = ud + k; 117 | const uint64_t p1 = uc + (p0 >> 32); 118 | digits_[i] = (p0 & 0xFFFFFFFF) | (p1 << 32); 119 | k = p1 >> 32; 120 | } 121 | 122 | if (k > 0) 123 | PushBack(k); 124 | 125 | return *this; 126 | } 127 | 128 | BigInteger& operator<<=(size_t shift) { 129 | if (IsZero() || shift == 0) return *this; 130 | 131 | size_t offset = shift / kTypeBit; 132 | size_t interShift = shift % kTypeBit; 133 | RAPIDJSON_ASSERT(count_ + offset <= kCapacity); 134 | 135 | if (interShift == 0) { 136 | std::memmove(digits_ + offset, digits_, count_ * sizeof(Type)); 137 | count_ += offset; 138 | } 139 | else { 140 | digits_[count_] = 0; 141 | for (size_t i = count_; i > 0; i--) 142 | digits_[i + offset] = (digits_[i] << interShift) | (digits_[i - 1] >> (kTypeBit - interShift)); 143 | digits_[offset] = digits_[0] << interShift; 144 | count_ += offset; 145 | if (digits_[count_]) 146 | count_++; 147 | } 148 | 149 | std::memset(digits_, 0, offset * sizeof(Type)); 150 | 151 | return *this; 152 | } 153 | 154 | bool operator==(const BigInteger& rhs) const { 155 | return count_ == rhs.count_ && std::memcmp(digits_, rhs.digits_, count_ * sizeof(Type)) == 0; 156 | } 157 | 158 | bool operator==(const Type rhs) const { 159 | return count_ == 1 && digits_[0] == rhs; 160 | } 161 | 162 | BigInteger& MultiplyPow5(unsigned exp) { 163 | static const uint32_t kPow5[12] = { 164 | 5, 165 | 5 * 5, 166 | 5 * 5 * 5, 167 | 5 * 5 * 5 * 5, 168 | 5 * 5 * 5 * 5 * 5, 169 | 5 * 5 * 5 * 5 * 5 * 5, 170 | 5 * 5 * 5 * 5 * 5 * 5 * 5, 171 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 172 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 173 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 174 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 175 | 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5 176 | }; 177 | if (exp == 0) return *this; 178 | for (; exp >= 27; exp -= 27) *this *= RAPIDJSON_UINT64_C2(0X6765C793, 0XFA10079D); // 5^27 179 | for (; exp >= 13; exp -= 13) *this *= static_cast(1220703125u); // 5^13 180 | if (exp > 0) *this *= kPow5[exp - 1]; 181 | return *this; 182 | } 183 | 184 | // Compute absolute difference of this and rhs. 185 | // Assume this != rhs 186 | bool Difference(const BigInteger& rhs, BigInteger* out) const { 187 | int cmp = Compare(rhs); 188 | RAPIDJSON_ASSERT(cmp != 0); 189 | const BigInteger *a, *b; // Makes a > b 190 | bool ret; 191 | if (cmp < 0) { a = &rhs; b = this; ret = true; } 192 | else { a = this; b = &rhs; ret = false; } 193 | 194 | Type borrow = 0; 195 | for (size_t i = 0; i < a->count_; i++) { 196 | Type d = a->digits_[i] - borrow; 197 | if (i < b->count_) 198 | d -= b->digits_[i]; 199 | borrow = (d > a->digits_[i]) ? 1 : 0; 200 | out->digits_[i] = d; 201 | if (d != 0) 202 | out->count_ = i + 1; 203 | } 204 | 205 | return ret; 206 | } 207 | 208 | int Compare(const BigInteger& rhs) const { 209 | if (count_ != rhs.count_) 210 | return count_ < rhs.count_ ? -1 : 1; 211 | 212 | for (size_t i = count_; i-- > 0;) 213 | if (digits_[i] != rhs.digits_[i]) 214 | return digits_[i] < rhs.digits_[i] ? -1 : 1; 215 | 216 | return 0; 217 | } 218 | 219 | size_t GetCount() const { return count_; } 220 | Type GetDigit(size_t index) const { RAPIDJSON_ASSERT(index < count_); return digits_[index]; } 221 | bool IsZero() const { return count_ == 1 && digits_[0] == 0; } 222 | 223 | private: 224 | void AppendDecimal64(const char* begin, const char* end) { 225 | uint64_t u = ParseUint64(begin, end); 226 | if (IsZero()) 227 | *this = u; 228 | else { 229 | unsigned exp = static_cast(end - begin); 230 | (MultiplyPow5(exp) <<= exp) += u; // *this = *this * 10^exp + u 231 | } 232 | } 233 | 234 | void PushBack(Type digit) { 235 | RAPIDJSON_ASSERT(count_ < kCapacity); 236 | digits_[count_++] = digit; 237 | } 238 | 239 | static uint64_t ParseUint64(const char* begin, const char* end) { 240 | uint64_t r = 0; 241 | for (const char* p = begin; p != end; ++p) { 242 | RAPIDJSON_ASSERT(*p >= '0' && *p <= '9'); 243 | r = r * 10u + static_cast(*p - '0'); 244 | } 245 | return r; 246 | } 247 | 248 | // Assume a * b + k < 2^128 249 | static uint64_t MulAdd64(uint64_t a, uint64_t b, uint64_t k, uint64_t* outHigh) { 250 | #if defined(_MSC_VER) && defined(_M_AMD64) 251 | uint64_t low = _umul128(a, b, outHigh) + k; 252 | if (low < k) 253 | (*outHigh)++; 254 | return low; 255 | #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) 256 | __extension__ typedef unsigned __int128 uint128; 257 | uint128 p = static_cast(a) * static_cast(b); 258 | p += k; 259 | *outHigh = static_cast(p >> 64); 260 | return static_cast(p); 261 | #else 262 | const uint64_t a0 = a & 0xFFFFFFFF, a1 = a >> 32, b0 = b & 0xFFFFFFFF, b1 = b >> 32; 263 | uint64_t x0 = a0 * b0, x1 = a0 * b1, x2 = a1 * b0, x3 = a1 * b1; 264 | x1 += (x0 >> 32); // can't give carry 265 | x1 += x2; 266 | if (x1 < x2) 267 | x3 += (static_cast(1) << 32); 268 | uint64_t lo = (x1 << 32) + (x0 & 0xFFFFFFFF); 269 | uint64_t hi = x3 + (x1 >> 32); 270 | 271 | lo += k; 272 | if (lo < k) 273 | hi++; 274 | *outHigh = hi; 275 | return lo; 276 | #endif 277 | } 278 | 279 | static const size_t kBitCount = 3328; // 64bit * 54 > 10^1000 280 | static const size_t kCapacity = kBitCount / sizeof(Type); 281 | static const size_t kTypeBit = sizeof(Type) * 8; 282 | 283 | Type digits_[kCapacity]; 284 | size_t count_; 285 | }; 286 | 287 | } // namespace internal 288 | RAPIDJSON_NAMESPACE_END 289 | 290 | #endif // RAPIDJSON_BIGINTEGER_H_ 291 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/diyfp.h: -------------------------------------------------------------------------------- 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 | // This is a C++ header-only implementation of Grisu2 algorithm from the publication: 16 | // Loitsch, Florian. "Printing floating-point numbers quickly and accurately with 17 | // integers." ACM Sigplan Notices 45.6 (2010): 233-243. 18 | 19 | #ifndef RAPIDJSON_DIYFP_H_ 20 | #define RAPIDJSON_DIYFP_H_ 21 | 22 | #include "../rapidjson.h" 23 | #include 24 | 25 | #if defined(_MSC_VER) && defined(_M_AMD64) && !defined(__INTEL_COMPILER) 26 | #include 27 | #pragma intrinsic(_BitScanReverse64) 28 | #pragma intrinsic(_umul128) 29 | #endif 30 | 31 | RAPIDJSON_NAMESPACE_BEGIN 32 | namespace internal { 33 | 34 | #ifdef __GNUC__ 35 | RAPIDJSON_DIAG_PUSH 36 | RAPIDJSON_DIAG_OFF(effc++) 37 | #endif 38 | 39 | #ifdef __clang__ 40 | RAPIDJSON_DIAG_PUSH 41 | RAPIDJSON_DIAG_OFF(padded) 42 | #endif 43 | 44 | struct DiyFp { 45 | DiyFp() : f(), e() {} 46 | 47 | DiyFp(uint64_t fp, int exp) : f(fp), e(exp) {} 48 | 49 | explicit DiyFp(double d) { 50 | union { 51 | double d; 52 | uint64_t u64; 53 | } u = { d }; 54 | 55 | int biased_e = static_cast((u.u64 & kDpExponentMask) >> kDpSignificandSize); 56 | uint64_t significand = (u.u64 & kDpSignificandMask); 57 | if (biased_e != 0) { 58 | f = significand + kDpHiddenBit; 59 | e = biased_e - kDpExponentBias; 60 | } 61 | else { 62 | f = significand; 63 | e = kDpMinExponent + 1; 64 | } 65 | } 66 | 67 | DiyFp operator-(const DiyFp& rhs) const { 68 | return DiyFp(f - rhs.f, e); 69 | } 70 | 71 | DiyFp operator*(const DiyFp& rhs) const { 72 | #if defined(_MSC_VER) && defined(_M_AMD64) 73 | uint64_t h; 74 | uint64_t l = _umul128(f, rhs.f, &h); 75 | if (l & (uint64_t(1) << 63)) // rounding 76 | h++; 77 | return DiyFp(h, e + rhs.e + 64); 78 | #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__) 79 | __extension__ typedef unsigned __int128 uint128; 80 | uint128 p = static_cast(f) * static_cast(rhs.f); 81 | uint64_t h = static_cast(p >> 64); 82 | uint64_t l = static_cast(p); 83 | if (l & (uint64_t(1) << 63)) // rounding 84 | h++; 85 | return DiyFp(h, e + rhs.e + 64); 86 | #else 87 | const uint64_t M32 = 0xFFFFFFFF; 88 | const uint64_t a = f >> 32; 89 | const uint64_t b = f & M32; 90 | const uint64_t c = rhs.f >> 32; 91 | const uint64_t d = rhs.f & M32; 92 | const uint64_t ac = a * c; 93 | const uint64_t bc = b * c; 94 | const uint64_t ad = a * d; 95 | const uint64_t bd = b * d; 96 | uint64_t tmp = (bd >> 32) + (ad & M32) + (bc & M32); 97 | tmp += 1U << 31; /// mult_round 98 | return DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs.e + 64); 99 | #endif 100 | } 101 | 102 | DiyFp Normalize() const { 103 | RAPIDJSON_ASSERT(f != 0); // https://stackoverflow.com/a/26809183/291737 104 | #if defined(_MSC_VER) && defined(_M_AMD64) 105 | unsigned long index; 106 | _BitScanReverse64(&index, f); 107 | return DiyFp(f << (63 - index), e - (63 - index)); 108 | #elif defined(__GNUC__) && __GNUC__ >= 4 109 | int s = __builtin_clzll(f); 110 | return DiyFp(f << s, e - s); 111 | #else 112 | DiyFp res = *this; 113 | while (!(res.f & (static_cast(1) << 63))) { 114 | res.f <<= 1; 115 | res.e--; 116 | } 117 | return res; 118 | #endif 119 | } 120 | 121 | DiyFp NormalizeBoundary() const { 122 | DiyFp res = *this; 123 | while (!(res.f & (kDpHiddenBit << 1))) { 124 | res.f <<= 1; 125 | res.e--; 126 | } 127 | res.f <<= (kDiySignificandSize - kDpSignificandSize - 2); 128 | res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2); 129 | return res; 130 | } 131 | 132 | void NormalizedBoundaries(DiyFp* minus, DiyFp* plus) const { 133 | DiyFp pl = DiyFp((f << 1) + 1, e - 1).NormalizeBoundary(); 134 | DiyFp mi = (f == kDpHiddenBit) ? DiyFp((f << 2) - 1, e - 2) : DiyFp((f << 1) - 1, e - 1); 135 | mi.f <<= mi.e - pl.e; 136 | mi.e = pl.e; 137 | *plus = pl; 138 | *minus = mi; 139 | } 140 | 141 | double ToDouble() const { 142 | union { 143 | double d; 144 | uint64_t u64; 145 | }u; 146 | RAPIDJSON_ASSERT(f <= kDpHiddenBit + kDpSignificandMask); 147 | if (e < kDpDenormalExponent) { 148 | // Underflow. 149 | return 0.0; 150 | } 151 | if (e >= kDpMaxExponent) { 152 | // Overflow. 153 | return std::numeric_limits::infinity(); 154 | } 155 | const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 : 156 | static_cast(e + kDpExponentBias); 157 | u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize); 158 | return u.d; 159 | } 160 | 161 | static const int kDiySignificandSize = 64; 162 | static const int kDpSignificandSize = 52; 163 | static const int kDpExponentBias = 0x3FF + kDpSignificandSize; 164 | static const int kDpMaxExponent = 0x7FF - kDpExponentBias; 165 | static const int kDpMinExponent = -kDpExponentBias; 166 | static const int kDpDenormalExponent = -kDpExponentBias + 1; 167 | static const uint64_t kDpExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 168 | static const uint64_t kDpSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 169 | static const uint64_t kDpHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 170 | 171 | uint64_t f; 172 | int e; 173 | }; 174 | 175 | inline DiyFp GetCachedPowerByIndex(size_t index) { 176 | // 10^-348, 10^-340, ..., 10^340 177 | static const uint64_t kCachedPowers_F[] = { 178 | RAPIDJSON_UINT64_C2(0xfa8fd5a0, 0x081c0288), RAPIDJSON_UINT64_C2(0xbaaee17f, 0xa23ebf76), 179 | RAPIDJSON_UINT64_C2(0x8b16fb20, 0x3055ac76), RAPIDJSON_UINT64_C2(0xcf42894a, 0x5dce35ea), 180 | RAPIDJSON_UINT64_C2(0x9a6bb0aa, 0x55653b2d), RAPIDJSON_UINT64_C2(0xe61acf03, 0x3d1a45df), 181 | RAPIDJSON_UINT64_C2(0xab70fe17, 0xc79ac6ca), RAPIDJSON_UINT64_C2(0xff77b1fc, 0xbebcdc4f), 182 | RAPIDJSON_UINT64_C2(0xbe5691ef, 0x416bd60c), RAPIDJSON_UINT64_C2(0x8dd01fad, 0x907ffc3c), 183 | RAPIDJSON_UINT64_C2(0xd3515c28, 0x31559a83), RAPIDJSON_UINT64_C2(0x9d71ac8f, 0xada6c9b5), 184 | RAPIDJSON_UINT64_C2(0xea9c2277, 0x23ee8bcb), RAPIDJSON_UINT64_C2(0xaecc4991, 0x4078536d), 185 | RAPIDJSON_UINT64_C2(0x823c1279, 0x5db6ce57), RAPIDJSON_UINT64_C2(0xc2109436, 0x4dfb5637), 186 | RAPIDJSON_UINT64_C2(0x9096ea6f, 0x3848984f), RAPIDJSON_UINT64_C2(0xd77485cb, 0x25823ac7), 187 | RAPIDJSON_UINT64_C2(0xa086cfcd, 0x97bf97f4), RAPIDJSON_UINT64_C2(0xef340a98, 0x172aace5), 188 | RAPIDJSON_UINT64_C2(0xb23867fb, 0x2a35b28e), RAPIDJSON_UINT64_C2(0x84c8d4df, 0xd2c63f3b), 189 | RAPIDJSON_UINT64_C2(0xc5dd4427, 0x1ad3cdba), RAPIDJSON_UINT64_C2(0x936b9fce, 0xbb25c996), 190 | RAPIDJSON_UINT64_C2(0xdbac6c24, 0x7d62a584), RAPIDJSON_UINT64_C2(0xa3ab6658, 0x0d5fdaf6), 191 | RAPIDJSON_UINT64_C2(0xf3e2f893, 0xdec3f126), RAPIDJSON_UINT64_C2(0xb5b5ada8, 0xaaff80b8), 192 | RAPIDJSON_UINT64_C2(0x87625f05, 0x6c7c4a8b), RAPIDJSON_UINT64_C2(0xc9bcff60, 0x34c13053), 193 | RAPIDJSON_UINT64_C2(0x964e858c, 0x91ba2655), RAPIDJSON_UINT64_C2(0xdff97724, 0x70297ebd), 194 | RAPIDJSON_UINT64_C2(0xa6dfbd9f, 0xb8e5b88f), RAPIDJSON_UINT64_C2(0xf8a95fcf, 0x88747d94), 195 | RAPIDJSON_UINT64_C2(0xb9447093, 0x8fa89bcf), RAPIDJSON_UINT64_C2(0x8a08f0f8, 0xbf0f156b), 196 | RAPIDJSON_UINT64_C2(0xcdb02555, 0x653131b6), RAPIDJSON_UINT64_C2(0x993fe2c6, 0xd07b7fac), 197 | RAPIDJSON_UINT64_C2(0xe45c10c4, 0x2a2b3b06), RAPIDJSON_UINT64_C2(0xaa242499, 0x697392d3), 198 | RAPIDJSON_UINT64_C2(0xfd87b5f2, 0x8300ca0e), RAPIDJSON_UINT64_C2(0xbce50864, 0x92111aeb), 199 | RAPIDJSON_UINT64_C2(0x8cbccc09, 0x6f5088cc), RAPIDJSON_UINT64_C2(0xd1b71758, 0xe219652c), 200 | RAPIDJSON_UINT64_C2(0x9c400000, 0x00000000), RAPIDJSON_UINT64_C2(0xe8d4a510, 0x00000000), 201 | RAPIDJSON_UINT64_C2(0xad78ebc5, 0xac620000), RAPIDJSON_UINT64_C2(0x813f3978, 0xf8940984), 202 | RAPIDJSON_UINT64_C2(0xc097ce7b, 0xc90715b3), RAPIDJSON_UINT64_C2(0x8f7e32ce, 0x7bea5c70), 203 | RAPIDJSON_UINT64_C2(0xd5d238a4, 0xabe98068), RAPIDJSON_UINT64_C2(0x9f4f2726, 0x179a2245), 204 | RAPIDJSON_UINT64_C2(0xed63a231, 0xd4c4fb27), RAPIDJSON_UINT64_C2(0xb0de6538, 0x8cc8ada8), 205 | RAPIDJSON_UINT64_C2(0x83c7088e, 0x1aab65db), RAPIDJSON_UINT64_C2(0xc45d1df9, 0x42711d9a), 206 | RAPIDJSON_UINT64_C2(0x924d692c, 0xa61be758), RAPIDJSON_UINT64_C2(0xda01ee64, 0x1a708dea), 207 | RAPIDJSON_UINT64_C2(0xa26da399, 0x9aef774a), RAPIDJSON_UINT64_C2(0xf209787b, 0xb47d6b85), 208 | RAPIDJSON_UINT64_C2(0xb454e4a1, 0x79dd1877), RAPIDJSON_UINT64_C2(0x865b8692, 0x5b9bc5c2), 209 | RAPIDJSON_UINT64_C2(0xc83553c5, 0xc8965d3d), RAPIDJSON_UINT64_C2(0x952ab45c, 0xfa97a0b3), 210 | RAPIDJSON_UINT64_C2(0xde469fbd, 0x99a05fe3), RAPIDJSON_UINT64_C2(0xa59bc234, 0xdb398c25), 211 | RAPIDJSON_UINT64_C2(0xf6c69a72, 0xa3989f5c), RAPIDJSON_UINT64_C2(0xb7dcbf53, 0x54e9bece), 212 | RAPIDJSON_UINT64_C2(0x88fcf317, 0xf22241e2), RAPIDJSON_UINT64_C2(0xcc20ce9b, 0xd35c78a5), 213 | RAPIDJSON_UINT64_C2(0x98165af3, 0x7b2153df), RAPIDJSON_UINT64_C2(0xe2a0b5dc, 0x971f303a), 214 | RAPIDJSON_UINT64_C2(0xa8d9d153, 0x5ce3b396), RAPIDJSON_UINT64_C2(0xfb9b7cd9, 0xa4a7443c), 215 | RAPIDJSON_UINT64_C2(0xbb764c4c, 0xa7a44410), RAPIDJSON_UINT64_C2(0x8bab8eef, 0xb6409c1a), 216 | RAPIDJSON_UINT64_C2(0xd01fef10, 0xa657842c), RAPIDJSON_UINT64_C2(0x9b10a4e5, 0xe9913129), 217 | RAPIDJSON_UINT64_C2(0xe7109bfb, 0xa19c0c9d), RAPIDJSON_UINT64_C2(0xac2820d9, 0x623bf429), 218 | RAPIDJSON_UINT64_C2(0x80444b5e, 0x7aa7cf85), RAPIDJSON_UINT64_C2(0xbf21e440, 0x03acdd2d), 219 | RAPIDJSON_UINT64_C2(0x8e679c2f, 0x5e44ff8f), RAPIDJSON_UINT64_C2(0xd433179d, 0x9c8cb841), 220 | RAPIDJSON_UINT64_C2(0x9e19db92, 0xb4e31ba9), RAPIDJSON_UINT64_C2(0xeb96bf6e, 0xbadf77d9), 221 | RAPIDJSON_UINT64_C2(0xaf87023b, 0x9bf0ee6b) 222 | }; 223 | static const int16_t kCachedPowers_E[] = { 224 | -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980, 225 | -954, -927, -901, -874, -847, -821, -794, -768, -741, -715, 226 | -688, -661, -635, -608, -582, -555, -529, -502, -475, -449, 227 | -422, -396, -369, -343, -316, -289, -263, -236, -210, -183, 228 | -157, -130, -103, -77, -50, -24, 3, 30, 56, 83, 229 | 109, 136, 162, 189, 216, 242, 269, 295, 322, 348, 230 | 375, 402, 428, 455, 481, 508, 534, 561, 588, 614, 231 | 641, 667, 694, 720, 747, 774, 800, 827, 853, 880, 232 | 907, 933, 960, 986, 1013, 1039, 1066 233 | }; 234 | RAPIDJSON_ASSERT(index < 87); 235 | return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]); 236 | } 237 | 238 | inline DiyFp GetCachedPower(int e, int* K) { 239 | 240 | //int k = static_cast(ceil((-61 - e) * 0.30102999566398114)) + 374; 241 | double dk = (-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive 242 | int k = static_cast(dk); 243 | if (dk - k > 0.0) 244 | k++; 245 | 246 | unsigned index = static_cast((k >> 3) + 1); 247 | *K = -(-348 + static_cast(index << 3)); // decimal exponent no need lookup table 248 | 249 | return GetCachedPowerByIndex(index); 250 | } 251 | 252 | inline DiyFp GetCachedPower10(int exp, int *outExp) { 253 | RAPIDJSON_ASSERT(exp >= -348); 254 | unsigned index = static_cast(exp + 348) / 8u; 255 | *outExp = -348 + static_cast(index) * 8; 256 | return GetCachedPowerByIndex(index); 257 | } 258 | 259 | #ifdef __GNUC__ 260 | RAPIDJSON_DIAG_POP 261 | #endif 262 | 263 | #ifdef __clang__ 264 | RAPIDJSON_DIAG_POP 265 | RAPIDJSON_DIAG_OFF(padded) 266 | #endif 267 | 268 | } // namespace internal 269 | RAPIDJSON_NAMESPACE_END 270 | 271 | #endif // RAPIDJSON_DIYFP_H_ 272 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/dtoa.h: -------------------------------------------------------------------------------- 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 | // This is a C++ header-only implementation of Grisu2 algorithm from the publication: 16 | // Loitsch, Florian. "Printing floating-point numbers quickly and accurately with 17 | // integers." ACM Sigplan Notices 45.6 (2010): 233-243. 18 | 19 | #ifndef RAPIDJSON_DTOA_ 20 | #define RAPIDJSON_DTOA_ 21 | 22 | #include "itoa.h" // GetDigitsLut() 23 | #include "diyfp.h" 24 | #include "ieee754.h" 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | namespace internal { 28 | 29 | #ifdef __GNUC__ 30 | RAPIDJSON_DIAG_PUSH 31 | RAPIDJSON_DIAG_OFF(effc++) 32 | RAPIDJSON_DIAG_OFF(array-bounds) // some gcc versions generate wrong warnings https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124 33 | #endif 34 | 35 | inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) { 36 | while (rest < wp_w && delta - rest >= ten_kappa && 37 | (rest + ten_kappa < wp_w || /// closer 38 | wp_w - rest > rest + ten_kappa - wp_w)) { 39 | buffer[len - 1]--; 40 | rest += ten_kappa; 41 | } 42 | } 43 | 44 | inline int CountDecimalDigit32(uint32_t n) { 45 | // Simple pure C++ implementation was faster than __builtin_clz version in this situation. 46 | if (n < 10) return 1; 47 | if (n < 100) return 2; 48 | if (n < 1000) return 3; 49 | if (n < 10000) return 4; 50 | if (n < 100000) return 5; 51 | if (n < 1000000) return 6; 52 | if (n < 10000000) return 7; 53 | if (n < 100000000) return 8; 54 | // Will not reach 10 digits in DigitGen() 55 | //if (n < 1000000000) return 9; 56 | //return 10; 57 | return 9; 58 | } 59 | 60 | inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) { 61 | static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; 62 | const DiyFp one(uint64_t(1) << -Mp.e, Mp.e); 63 | const DiyFp wp_w = Mp - W; 64 | uint32_t p1 = static_cast(Mp.f >> -one.e); 65 | uint64_t p2 = Mp.f & (one.f - 1); 66 | int kappa = CountDecimalDigit32(p1); // kappa in [0, 9] 67 | *len = 0; 68 | 69 | while (kappa > 0) { 70 | uint32_t d = 0; 71 | switch (kappa) { 72 | case 9: d = p1 / 100000000; p1 %= 100000000; break; 73 | case 8: d = p1 / 10000000; p1 %= 10000000; break; 74 | case 7: d = p1 / 1000000; p1 %= 1000000; break; 75 | case 6: d = p1 / 100000; p1 %= 100000; break; 76 | case 5: d = p1 / 10000; p1 %= 10000; break; 77 | case 4: d = p1 / 1000; p1 %= 1000; break; 78 | case 3: d = p1 / 100; p1 %= 100; break; 79 | case 2: d = p1 / 10; p1 %= 10; break; 80 | case 1: d = p1; p1 = 0; break; 81 | default:; 82 | } 83 | if (d || *len) 84 | buffer[(*len)++] = static_cast('0' + static_cast(d)); 85 | kappa--; 86 | uint64_t tmp = (static_cast(p1) << -one.e) + p2; 87 | if (tmp <= delta) { 88 | *K += kappa; 89 | GrisuRound(buffer, *len, delta, tmp, static_cast(kPow10[kappa]) << -one.e, wp_w.f); 90 | return; 91 | } 92 | } 93 | 94 | // kappa = 0 95 | for (;;) { 96 | p2 *= 10; 97 | delta *= 10; 98 | char d = static_cast(p2 >> -one.e); 99 | if (d || *len) 100 | buffer[(*len)++] = static_cast('0' + d); 101 | p2 &= one.f - 1; 102 | kappa--; 103 | if (p2 < delta) { 104 | *K += kappa; 105 | int index = -kappa; 106 | GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 9 ? kPow10[index] : 0)); 107 | return; 108 | } 109 | } 110 | } 111 | 112 | inline void Grisu2(double value, char* buffer, int* length, int* K) { 113 | const DiyFp v(value); 114 | DiyFp w_m, w_p; 115 | v.NormalizedBoundaries(&w_m, &w_p); 116 | 117 | const DiyFp c_mk = GetCachedPower(w_p.e, K); 118 | const DiyFp W = v.Normalize() * c_mk; 119 | DiyFp Wp = w_p * c_mk; 120 | DiyFp Wm = w_m * c_mk; 121 | Wm.f++; 122 | Wp.f--; 123 | DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K); 124 | } 125 | 126 | inline char* WriteExponent(int K, char* buffer) { 127 | if (K < 0) { 128 | *buffer++ = '-'; 129 | K = -K; 130 | } 131 | 132 | if (K >= 100) { 133 | *buffer++ = static_cast('0' + static_cast(K / 100)); 134 | K %= 100; 135 | const char* d = GetDigitsLut() + K * 2; 136 | *buffer++ = d[0]; 137 | *buffer++ = d[1]; 138 | } 139 | else if (K >= 10) { 140 | const char* d = GetDigitsLut() + K * 2; 141 | *buffer++ = d[0]; 142 | *buffer++ = d[1]; 143 | } 144 | else 145 | *buffer++ = static_cast('0' + static_cast(K)); 146 | 147 | return buffer; 148 | } 149 | 150 | inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) { 151 | const int kk = length + k; // 10^(kk-1) <= v < 10^kk 152 | 153 | if (0 <= k && kk <= 21) { 154 | // 1234e7 -> 12340000000 155 | for (int i = length; i < kk; i++) 156 | buffer[i] = '0'; 157 | buffer[kk] = '.'; 158 | buffer[kk + 1] = '0'; 159 | return &buffer[kk + 2]; 160 | } 161 | else if (0 < kk && kk <= 21) { 162 | // 1234e-2 -> 12.34 163 | std::memmove(&buffer[kk + 1], &buffer[kk], static_cast(length - kk)); 164 | buffer[kk] = '.'; 165 | if (0 > k + maxDecimalPlaces) { 166 | // When maxDecimalPlaces = 2, 1.2345 -> 1.23, 1.102 -> 1.1 167 | // Remove extra trailing zeros (at least one) after truncation. 168 | for (int i = kk + maxDecimalPlaces; i > kk + 1; i--) 169 | if (buffer[i] != '0') 170 | return &buffer[i + 1]; 171 | return &buffer[kk + 2]; // Reserve one zero 172 | } 173 | else 174 | return &buffer[length + 1]; 175 | } 176 | else if (-6 < kk && kk <= 0) { 177 | // 1234e-6 -> 0.001234 178 | const int offset = 2 - kk; 179 | std::memmove(&buffer[offset], &buffer[0], static_cast(length)); 180 | buffer[0] = '0'; 181 | buffer[1] = '.'; 182 | for (int i = 2; i < offset; i++) 183 | buffer[i] = '0'; 184 | if (length - kk > maxDecimalPlaces) { 185 | // When maxDecimalPlaces = 2, 0.123 -> 0.12, 0.102 -> 0.1 186 | // Remove extra trailing zeros (at least one) after truncation. 187 | for (int i = maxDecimalPlaces + 1; i > 2; i--) 188 | if (buffer[i] != '0') 189 | return &buffer[i + 1]; 190 | return &buffer[3]; // Reserve one zero 191 | } 192 | else 193 | return &buffer[length + offset]; 194 | } 195 | else if (kk < -maxDecimalPlaces) { 196 | // Truncate to zero 197 | buffer[0] = '0'; 198 | buffer[1] = '.'; 199 | buffer[2] = '0'; 200 | return &buffer[3]; 201 | } 202 | else if (length == 1) { 203 | // 1e30 204 | buffer[1] = 'e'; 205 | return WriteExponent(kk - 1, &buffer[2]); 206 | } 207 | else { 208 | // 1234e30 -> 1.234e33 209 | std::memmove(&buffer[2], &buffer[1], static_cast(length - 1)); 210 | buffer[1] = '.'; 211 | buffer[length + 1] = 'e'; 212 | return WriteExponent(kk - 1, &buffer[0 + length + 2]); 213 | } 214 | } 215 | 216 | inline char* dtoa(double value, char* buffer, int maxDecimalPlaces = 324) { 217 | RAPIDJSON_ASSERT(maxDecimalPlaces >= 1); 218 | Double d(value); 219 | if (d.IsZero()) { 220 | if (d.Sign()) 221 | *buffer++ = '-'; // -0.0, Issue #289 222 | buffer[0] = '0'; 223 | buffer[1] = '.'; 224 | buffer[2] = '0'; 225 | return &buffer[3]; 226 | } 227 | else { 228 | if (value < 0) { 229 | *buffer++ = '-'; 230 | value = -value; 231 | } 232 | int length, K; 233 | Grisu2(value, buffer, &length, &K); 234 | return Prettify(buffer, length, K, maxDecimalPlaces); 235 | } 236 | } 237 | 238 | #ifdef __GNUC__ 239 | RAPIDJSON_DIAG_POP 240 | #endif 241 | 242 | } // namespace internal 243 | RAPIDJSON_NAMESPACE_END 244 | 245 | #endif // RAPIDJSON_DTOA_ 246 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/ieee754.h: -------------------------------------------------------------------------------- 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_IEEE754_ 16 | #define RAPIDJSON_IEEE754_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | class Double { 24 | public: 25 | Double() {} 26 | Double(double d) : d_(d) {} 27 | Double(uint64_t u) : u_(u) {} 28 | 29 | double Value() const { return d_; } 30 | uint64_t Uint64Value() const { return u_; } 31 | 32 | double NextPositiveDouble() const { 33 | RAPIDJSON_ASSERT(!Sign()); 34 | return Double(u_ + 1).Value(); 35 | } 36 | 37 | bool Sign() const { return (u_ & kSignMask) != 0; } 38 | uint64_t Significand() const { return u_ & kSignificandMask; } 39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } 40 | 41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } 42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } 43 | bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } 44 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } 45 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } 46 | 47 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } 48 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } 49 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } 50 | 51 | static int EffectiveSignificandSize(int order) { 52 | if (order >= -1021) 53 | return 53; 54 | else if (order <= -1074) 55 | return 0; 56 | else 57 | return order + 1074; 58 | } 59 | 60 | private: 61 | static const int kSignificandSize = 52; 62 | static const int kExponentBias = 0x3FF; 63 | static const int kDenormalExponent = 1 - kExponentBias; 64 | static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); 65 | static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 66 | static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 67 | static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 68 | 69 | union { 70 | double d_; 71 | uint64_t u_; 72 | }; 73 | }; 74 | 75 | } // namespace internal 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_IEEE754_ 79 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/itoa.h: -------------------------------------------------------------------------------- 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_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('0' + static_cast(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(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(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(value / kTen8); 180 | const uint32_t v1 = static_cast(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(value / kTen16); // 1 to 1844 227 | value %= kTen16; 228 | 229 | if (a < 10) 230 | *buffer++ = static_cast('0' + static_cast(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('0' + static_cast(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(value / kTen8); 253 | const uint32_t v1 = static_cast(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(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_ 309 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/meta.h: -------------------------------------------------------------------------------- 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_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 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 struct Void { typedef void Type; }; 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | // BoolType, TrueType, FalseType 43 | // 44 | template struct BoolType { 45 | static const bool Value = Cond; 46 | typedef BoolType Type; 47 | }; 48 | typedef BoolType TrueType; 49 | typedef BoolType FalseType; 50 | 51 | 52 | /////////////////////////////////////////////////////////////////////////////// 53 | // SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr 54 | // 55 | 56 | template struct SelectIfImpl { template struct Apply { typedef T1 Type; }; }; 57 | template <> struct SelectIfImpl { template struct Apply { typedef T2 Type; }; }; 58 | template struct SelectIfCond : SelectIfImpl::template Apply {}; 59 | template struct SelectIf : SelectIfCond {}; 60 | 61 | template struct AndExprCond : FalseType {}; 62 | template <> struct AndExprCond : TrueType {}; 63 | template struct OrExprCond : TrueType {}; 64 | template <> struct OrExprCond : FalseType {}; 65 | 66 | template struct BoolExpr : SelectIf::Type {}; 67 | template struct NotExpr : SelectIf::Type {}; 68 | template struct AndExpr : AndExprCond::Type {}; 69 | template struct OrExpr : OrExprCond::Type {}; 70 | 71 | 72 | /////////////////////////////////////////////////////////////////////////////// 73 | // AddConst, MaybeAddConst, RemoveConst 74 | template struct AddConst { typedef const T Type; }; 75 | template struct MaybeAddConst : SelectIfCond {}; 76 | template struct RemoveConst { typedef T Type; }; 77 | template struct RemoveConst { typedef T Type; }; 78 | 79 | 80 | /////////////////////////////////////////////////////////////////////////////// 81 | // IsSame, IsConst, IsMoreConst, IsPointer 82 | // 83 | template struct IsSame : FalseType {}; 84 | template struct IsSame : TrueType {}; 85 | 86 | template struct IsConst : FalseType {}; 87 | template struct IsConst : TrueType {}; 88 | 89 | template 90 | struct IsMoreConst 91 | : AndExpr::Type, typename RemoveConst::Type>, 92 | BoolType::Value >= IsConst::Value> >::Type {}; 93 | 94 | template struct IsPointer : FalseType {}; 95 | template struct IsPointer : TrueType {}; 96 | 97 | /////////////////////////////////////////////////////////////////////////////// 98 | // IsBaseOf 99 | // 100 | #if RAPIDJSON_HAS_CXX11_TYPETRAITS 101 | 102 | template struct IsBaseOf 103 | : BoolType< ::std::is_base_of::value> {}; 104 | 105 | #else // simplified version adopted from Boost 106 | 107 | template 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 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 struct IsBaseOf 127 | : OrExpr, BoolExpr > >::Type {}; 128 | 129 | #endif // RAPIDJSON_HAS_CXX11_TYPETRAITS 130 | 131 | 132 | ////////////////////////////////////////////////////////////////////////// 133 | // EnableIf / DisableIf 134 | // 135 | template struct EnableIfCond { typedef T Type; }; 136 | template struct EnableIfCond { /* empty */ }; 137 | 138 | template struct DisableIfCond { typedef T Type; }; 139 | template struct DisableIfCond { /* empty */ }; 140 | 141 | template 142 | struct EnableIf : EnableIfCond {}; 143 | 144 | template 145 | struct DisableIf : DisableIfCond {}; 146 | 147 | // SFINAE helpers 148 | struct SfinaeTag {}; 149 | template struct RemoveSfinaeTag; 150 | template struct RemoveSfinaeTag { 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 | ::Type * = NULL 159 | 160 | #define RAPIDJSON_DISABLEIF(cond) \ 161 | typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ 162 | ::Type * = NULL 163 | 164 | #define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \ 165 | typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ 166 | ::Type 168 | 169 | #define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \ 170 | typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ 171 | ::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_ 187 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/pow10.h: -------------------------------------------------------------------------------- 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_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_ 56 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/stack.h: -------------------------------------------------------------------------------- 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_INTERNAL_STACK_H_ 16 | #define RAPIDJSON_INTERNAL_STACK_H_ 17 | 18 | #include "../allocators.h" 19 | #include "swap.h" 20 | 21 | #if defined(__clang__) 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(c++98-compat) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | namespace internal { 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // Stack 31 | 32 | //! A type-unsafe stack for storing different types of data. 33 | /*! \tparam Allocator Allocator for allocating stack memory. 34 | */ 35 | template 36 | class Stack { 37 | public: 38 | // Optimization note: Do not allocate memory for stack_ in constructor. 39 | // Do it lazily when first Push() -> Expand() -> Resize(). 40 | Stack(Allocator* allocator, size_t stackCapacity) : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) { 41 | } 42 | 43 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 44 | Stack(Stack&& rhs) 45 | : allocator_(rhs.allocator_), 46 | ownAllocator_(rhs.ownAllocator_), 47 | stack_(rhs.stack_), 48 | stackTop_(rhs.stackTop_), 49 | stackEnd_(rhs.stackEnd_), 50 | initialCapacity_(rhs.initialCapacity_) 51 | { 52 | rhs.allocator_ = 0; 53 | rhs.ownAllocator_ = 0; 54 | rhs.stack_ = 0; 55 | rhs.stackTop_ = 0; 56 | rhs.stackEnd_ = 0; 57 | rhs.initialCapacity_ = 0; 58 | } 59 | #endif 60 | 61 | ~Stack() { 62 | Destroy(); 63 | } 64 | 65 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 66 | Stack& operator=(Stack&& rhs) { 67 | if (&rhs != this) 68 | { 69 | Destroy(); 70 | 71 | allocator_ = rhs.allocator_; 72 | ownAllocator_ = rhs.ownAllocator_; 73 | stack_ = rhs.stack_; 74 | stackTop_ = rhs.stackTop_; 75 | stackEnd_ = rhs.stackEnd_; 76 | initialCapacity_ = rhs.initialCapacity_; 77 | 78 | rhs.allocator_ = 0; 79 | rhs.ownAllocator_ = 0; 80 | rhs.stack_ = 0; 81 | rhs.stackTop_ = 0; 82 | rhs.stackEnd_ = 0; 83 | rhs.initialCapacity_ = 0; 84 | } 85 | return *this; 86 | } 87 | #endif 88 | 89 | void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT { 90 | internal::Swap(allocator_, rhs.allocator_); 91 | internal::Swap(ownAllocator_, rhs.ownAllocator_); 92 | internal::Swap(stack_, rhs.stack_); 93 | internal::Swap(stackTop_, rhs.stackTop_); 94 | internal::Swap(stackEnd_, rhs.stackEnd_); 95 | internal::Swap(initialCapacity_, rhs.initialCapacity_); 96 | } 97 | 98 | void Clear() { stackTop_ = stack_; } 99 | 100 | void ShrinkToFit() { 101 | if (Empty()) { 102 | // If the stack is empty, completely deallocate the memory. 103 | Allocator::Free(stack_); // NOLINT (+clang-analyzer-unix.Malloc) 104 | stack_ = 0; 105 | stackTop_ = 0; 106 | stackEnd_ = 0; 107 | } 108 | else 109 | Resize(GetSize()); 110 | } 111 | 112 | // Optimization note: try to minimize the size of this function for force inline. 113 | // Expansion is run very infrequently, so it is moved to another (probably non-inline) function. 114 | template 115 | RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) { 116 | // Expand the stack if needed 117 | if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count > stackEnd_)) 118 | Expand(count); 119 | } 120 | 121 | template 122 | RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) { 123 | Reserve(count); 124 | return PushUnsafe(count); 125 | } 126 | 127 | template 128 | RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) { 129 | RAPIDJSON_ASSERT(stackTop_); 130 | RAPIDJSON_ASSERT(stackTop_ + sizeof(T) * count <= stackEnd_); 131 | T* ret = reinterpret_cast(stackTop_); 132 | stackTop_ += sizeof(T) * count; 133 | return ret; 134 | } 135 | 136 | template 137 | T* Pop(size_t count) { 138 | RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T)); 139 | stackTop_ -= count * sizeof(T); 140 | return reinterpret_cast(stackTop_); 141 | } 142 | 143 | template 144 | T* Top() { 145 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 146 | return reinterpret_cast(stackTop_ - sizeof(T)); 147 | } 148 | 149 | template 150 | const T* Top() const { 151 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 152 | return reinterpret_cast(stackTop_ - sizeof(T)); 153 | } 154 | 155 | template 156 | T* End() { return reinterpret_cast(stackTop_); } 157 | 158 | template 159 | const T* End() const { return reinterpret_cast(stackTop_); } 160 | 161 | template 162 | T* Bottom() { return reinterpret_cast(stack_); } 163 | 164 | template 165 | const T* Bottom() const { return reinterpret_cast(stack_); } 166 | 167 | bool HasAllocator() const { 168 | return allocator_ != 0; 169 | } 170 | 171 | Allocator& GetAllocator() { 172 | RAPIDJSON_ASSERT(allocator_); 173 | return *allocator_; 174 | } 175 | 176 | bool Empty() const { return stackTop_ == stack_; } 177 | size_t GetSize() const { return static_cast(stackTop_ - stack_); } 178 | size_t GetCapacity() const { return static_cast(stackEnd_ - stack_); } 179 | 180 | private: 181 | template 182 | void Expand(size_t count) { 183 | // Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity. 184 | size_t newCapacity; 185 | if (stack_ == 0) { 186 | if (!allocator_) 187 | ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); 188 | newCapacity = initialCapacity_; 189 | } else { 190 | newCapacity = GetCapacity(); 191 | newCapacity += (newCapacity + 1) / 2; 192 | } 193 | size_t newSize = GetSize() + sizeof(T) * count; 194 | if (newCapacity < newSize) 195 | newCapacity = newSize; 196 | 197 | Resize(newCapacity); 198 | } 199 | 200 | void Resize(size_t newCapacity) { 201 | const size_t size = GetSize(); // Backup the current size 202 | stack_ = static_cast(allocator_->Realloc(stack_, GetCapacity(), newCapacity)); 203 | stackTop_ = stack_ + size; 204 | stackEnd_ = stack_ + newCapacity; 205 | } 206 | 207 | void Destroy() { 208 | Allocator::Free(stack_); 209 | RAPIDJSON_DELETE(ownAllocator_); // Only delete if it is owned by the stack 210 | } 211 | 212 | // Prohibit copy constructor & assignment operator. 213 | Stack(const Stack&); 214 | Stack& operator=(const Stack&); 215 | 216 | Allocator* allocator_; 217 | Allocator* ownAllocator_; 218 | char *stack_; 219 | char *stackTop_; 220 | char *stackEnd_; 221 | size_t initialCapacity_; 222 | }; 223 | 224 | } // namespace internal 225 | RAPIDJSON_NAMESPACE_END 226 | 227 | #if defined(__clang__) 228 | RAPIDJSON_DIAG_POP 229 | #endif 230 | 231 | #endif // RAPIDJSON_STACK_H_ 232 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 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_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | #include 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | namespace internal { 23 | 24 | //! Custom strlen() which works on different character types. 25 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 26 | \param s Null-terminated input string. 27 | \return Number of characters in the string. 28 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 29 | */ 30 | template 31 | inline SizeType StrLen(const Ch* s) { 32 | RAPIDJSON_ASSERT(s != 0); 33 | const Ch* p = s; 34 | while (*p) ++p; 35 | return SizeType(p - s); 36 | } 37 | 38 | template <> 39 | inline SizeType StrLen(const char* s) { 40 | return SizeType(std::strlen(s)); 41 | } 42 | 43 | template <> 44 | inline SizeType StrLen(const wchar_t* s) { 45 | return SizeType(std::wcslen(s)); 46 | } 47 | 48 | //! Returns number of code points in a encoded string. 49 | template 50 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 51 | RAPIDJSON_ASSERT(s != 0); 52 | RAPIDJSON_ASSERT(outCount != 0); 53 | GenericStringStream is(s); 54 | const typename Encoding::Ch* end = s + length; 55 | SizeType count = 0; 56 | while (is.src_ < end) { 57 | unsigned codepoint; 58 | if (!Encoding::Decode(is, &codepoint)) 59 | return false; 60 | count++; 61 | } 62 | *outCount = count; 63 | return true; 64 | } 65 | 66 | } // namespace internal 67 | RAPIDJSON_NAMESPACE_END 68 | 69 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 70 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/strtod.h: -------------------------------------------------------------------------------- 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_STRTOD_ 16 | #define RAPIDJSON_STRTOD_ 17 | 18 | #include "ieee754.h" 19 | #include "biginteger.h" 20 | #include "diyfp.h" 21 | #include "pow10.h" 22 | #include 23 | #include 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | inline double FastPath(double significand, int exp) { 29 | if (exp < -308) 30 | return 0.0; 31 | else if (exp >= 0) 32 | return significand * internal::Pow10(exp); 33 | else 34 | return significand / internal::Pow10(-exp); 35 | } 36 | 37 | inline double StrtodNormalPrecision(double d, int p) { 38 | if (p < -308) { 39 | // Prevent expSum < -308, making Pow10(p) = 0 40 | d = FastPath(d, -308); 41 | d = FastPath(d, p + 308); 42 | } 43 | else 44 | d = FastPath(d, p); 45 | return d; 46 | } 47 | 48 | template 49 | inline T Min3(T a, T b, T c) { 50 | T m = a; 51 | if (m > b) m = b; 52 | if (m > c) m = c; 53 | return m; 54 | } 55 | 56 | inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) { 57 | const Double db(b); 58 | const uint64_t bInt = db.IntegerSignificand(); 59 | const int bExp = db.IntegerExponent(); 60 | const int hExp = bExp - 1; 61 | 62 | int dS_Exp2 = 0, dS_Exp5 = 0, bS_Exp2 = 0, bS_Exp5 = 0, hS_Exp2 = 0, hS_Exp5 = 0; 63 | 64 | // Adjust for decimal exponent 65 | if (dExp >= 0) { 66 | dS_Exp2 += dExp; 67 | dS_Exp5 += dExp; 68 | } 69 | else { 70 | bS_Exp2 -= dExp; 71 | bS_Exp5 -= dExp; 72 | hS_Exp2 -= dExp; 73 | hS_Exp5 -= dExp; 74 | } 75 | 76 | // Adjust for binary exponent 77 | if (bExp >= 0) 78 | bS_Exp2 += bExp; 79 | else { 80 | dS_Exp2 -= bExp; 81 | hS_Exp2 -= bExp; 82 | } 83 | 84 | // Adjust for half ulp exponent 85 | if (hExp >= 0) 86 | hS_Exp2 += hExp; 87 | else { 88 | dS_Exp2 -= hExp; 89 | bS_Exp2 -= hExp; 90 | } 91 | 92 | // Remove common power of two factor from all three scaled values 93 | int common_Exp2 = Min3(dS_Exp2, bS_Exp2, hS_Exp2); 94 | dS_Exp2 -= common_Exp2; 95 | bS_Exp2 -= common_Exp2; 96 | hS_Exp2 -= common_Exp2; 97 | 98 | BigInteger dS = d; 99 | dS.MultiplyPow5(static_cast(dS_Exp5)) <<= static_cast(dS_Exp2); 100 | 101 | BigInteger bS(bInt); 102 | bS.MultiplyPow5(static_cast(bS_Exp5)) <<= static_cast(bS_Exp2); 103 | 104 | BigInteger hS(1); 105 | hS.MultiplyPow5(static_cast(hS_Exp5)) <<= static_cast(hS_Exp2); 106 | 107 | BigInteger delta(0); 108 | dS.Difference(bS, &delta); 109 | 110 | return delta.Compare(hS); 111 | } 112 | 113 | inline bool StrtodFast(double d, int p, double* result) { 114 | // Use fast path for string-to-double conversion if possible 115 | // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/ 116 | if (p > 22 && p < 22 + 16) { 117 | // Fast Path Cases In Disguise 118 | d *= internal::Pow10(p - 22); 119 | p = 22; 120 | } 121 | 122 | if (p >= -22 && p <= 22 && d <= 9007199254740991.0) { // 2^53 - 1 123 | *result = FastPath(d, p); 124 | return true; 125 | } 126 | else 127 | return false; 128 | } 129 | 130 | // Compute an approximation and see if it is within 1/2 ULP 131 | inline bool StrtodDiyFp(const char* decimals, int dLen, int dExp, double* result) { 132 | uint64_t significand = 0; 133 | int i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999 134 | for (; i < dLen; i++) { 135 | if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || 136 | (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > '5')) 137 | break; 138 | significand = significand * 10u + static_cast(decimals[i] - '0'); 139 | } 140 | 141 | if (i < dLen && decimals[i] >= '5') // Rounding 142 | significand++; 143 | 144 | int remaining = dLen - i; 145 | const int kUlpShift = 3; 146 | const int kUlp = 1 << kUlpShift; 147 | int64_t error = (remaining == 0) ? 0 : kUlp / 2; 148 | 149 | DiyFp v(significand, 0); 150 | v = v.Normalize(); 151 | error <<= -v.e; 152 | 153 | dExp += remaining; 154 | 155 | int actualExp; 156 | DiyFp cachedPower = GetCachedPower10(dExp, &actualExp); 157 | if (actualExp != dExp) { 158 | static const DiyFp kPow10[] = { 159 | DiyFp(RAPIDJSON_UINT64_C2(0xa0000000, 0x00000000), -60), // 10^1 160 | DiyFp(RAPIDJSON_UINT64_C2(0xc8000000, 0x00000000), -57), // 10^2 161 | DiyFp(RAPIDJSON_UINT64_C2(0xfa000000, 0x00000000), -54), // 10^3 162 | DiyFp(RAPIDJSON_UINT64_C2(0x9c400000, 0x00000000), -50), // 10^4 163 | DiyFp(RAPIDJSON_UINT64_C2(0xc3500000, 0x00000000), -47), // 10^5 164 | DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 0x00000000), -44), // 10^6 165 | DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 0x00000000), -40) // 10^7 166 | }; 167 | int adjustment = dExp - actualExp; 168 | RAPIDJSON_ASSERT(adjustment >= 1 && adjustment < 8); 169 | v = v * kPow10[adjustment - 1]; 170 | if (dLen + adjustment > 19) // has more digits than decimal digits in 64-bit 171 | error += kUlp / 2; 172 | } 173 | 174 | v = v * cachedPower; 175 | 176 | error += kUlp + (error == 0 ? 0 : 1); 177 | 178 | const int oldExp = v.e; 179 | v = v.Normalize(); 180 | error <<= oldExp - v.e; 181 | 182 | const int effectiveSignificandSize = Double::EffectiveSignificandSize(64 + v.e); 183 | int precisionSize = 64 - effectiveSignificandSize; 184 | if (precisionSize + kUlpShift >= 64) { 185 | int scaleExp = (precisionSize + kUlpShift) - 63; 186 | v.f >>= scaleExp; 187 | v.e += scaleExp; 188 | error = (error >> scaleExp) + 1 + kUlp; 189 | precisionSize -= scaleExp; 190 | } 191 | 192 | DiyFp rounded(v.f >> precisionSize, v.e + precisionSize); 193 | const uint64_t precisionBits = (v.f & ((uint64_t(1) << precisionSize) - 1)) * kUlp; 194 | const uint64_t halfWay = (uint64_t(1) << (precisionSize - 1)) * kUlp; 195 | if (precisionBits >= halfWay + static_cast(error)) { 196 | rounded.f++; 197 | if (rounded.f & (DiyFp::kDpHiddenBit << 1)) { // rounding overflows mantissa (issue #340) 198 | rounded.f >>= 1; 199 | rounded.e++; 200 | } 201 | } 202 | 203 | *result = rounded.ToDouble(); 204 | 205 | return halfWay - static_cast(error) >= precisionBits || precisionBits >= halfWay + static_cast(error); 206 | } 207 | 208 | inline double StrtodBigInteger(double approx, const char* decimals, int dLen, int dExp) { 209 | RAPIDJSON_ASSERT(dLen >= 0); 210 | const BigInteger dInt(decimals, static_cast(dLen)); 211 | Double a(approx); 212 | int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp); 213 | if (cmp < 0) 214 | return a.Value(); // within half ULP 215 | else if (cmp == 0) { 216 | // Round towards even 217 | if (a.Significand() & 1) 218 | return a.NextPositiveDouble(); 219 | else 220 | return a.Value(); 221 | } 222 | else // adjustment 223 | return a.NextPositiveDouble(); 224 | } 225 | 226 | inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) { 227 | RAPIDJSON_ASSERT(d >= 0.0); 228 | RAPIDJSON_ASSERT(length >= 1); 229 | 230 | double result = 0.0; 231 | if (StrtodFast(d, p, &result)) 232 | return result; 233 | 234 | RAPIDJSON_ASSERT(length <= INT_MAX); 235 | int dLen = static_cast(length); 236 | 237 | RAPIDJSON_ASSERT(length >= decimalPosition); 238 | RAPIDJSON_ASSERT(length - decimalPosition <= INT_MAX); 239 | int dExpAdjust = static_cast(length - decimalPosition); 240 | 241 | RAPIDJSON_ASSERT(exp >= INT_MIN + dExpAdjust); 242 | int dExp = exp - dExpAdjust; 243 | 244 | // Make sure length+dExp does not overflow 245 | RAPIDJSON_ASSERT(dExp <= INT_MAX - dLen); 246 | 247 | // Trim leading zeros 248 | while (dLen > 0 && *decimals == '0') { 249 | dLen--; 250 | decimals++; 251 | } 252 | 253 | // Trim trailing zeros 254 | while (dLen > 0 && decimals[dLen - 1] == '0') { 255 | dLen--; 256 | dExp++; 257 | } 258 | 259 | if (dLen == 0) { // Buffer only contains zeros. 260 | return 0.0; 261 | } 262 | 263 | // Trim right-most digits 264 | const int kMaxDecimalDigit = 767 + 1; 265 | if (dLen > kMaxDecimalDigit) { 266 | dExp += dLen - kMaxDecimalDigit; 267 | dLen = kMaxDecimalDigit; 268 | } 269 | 270 | // If too small, underflow to zero. 271 | // Any x <= 10^-324 is interpreted as zero. 272 | if (dLen + dExp <= -324) 273 | return 0.0; 274 | 275 | // If too large, overflow to infinity. 276 | // Any x >= 10^309 is interpreted as +infinity. 277 | if (dLen + dExp > 309) 278 | return std::numeric_limits::infinity(); 279 | 280 | if (StrtodDiyFp(decimals, dLen, dExp, &result)) 281 | return result; 282 | 283 | // Use approximation from StrtodDiyFp and make adjustment with BigInteger comparison 284 | return StrtodBigInteger(result, decimals, dLen, dExp); 285 | } 286 | 287 | } // namespace internal 288 | RAPIDJSON_NAMESPACE_END 289 | 290 | #endif // RAPIDJSON_STRTOD_ 291 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 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_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/istreamwrapper.h: -------------------------------------------------------------------------------- 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_ISTREAMWRAPPER_H_ 16 | #define RAPIDJSON_ISTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #elif defined(_MSC_VER) 25 | RAPIDJSON_DIAG_PUSH 26 | RAPIDJSON_DIAG_OFF(4351) // new behavior: elements of array 'array' will be default initialized 27 | #endif 28 | 29 | RAPIDJSON_NAMESPACE_BEGIN 30 | 31 | //! Wrapper of \c std::basic_istream into RapidJSON's Stream concept. 32 | /*! 33 | The classes can be wrapped including but not limited to: 34 | 35 | - \c std::istringstream 36 | - \c std::stringstream 37 | - \c std::wistringstream 38 | - \c std::wstringstream 39 | - \c std::ifstream 40 | - \c std::fstream 41 | - \c std::wifstream 42 | - \c std::wfstream 43 | 44 | \tparam StreamType Class derived from \c std::basic_istream. 45 | */ 46 | 47 | template 48 | class BasicIStreamWrapper { 49 | public: 50 | typedef typename StreamType::char_type Ch; 51 | BasicIStreamWrapper(StreamType& stream) : stream_(stream), count_(), peekBuffer_() {} 52 | 53 | Ch Peek() const { 54 | typename StreamType::int_type c = stream_.peek(); 55 | return RAPIDJSON_LIKELY(c != StreamType::traits_type::eof()) ? static_cast(c) : static_cast('\0'); 56 | } 57 | 58 | Ch Take() { 59 | typename StreamType::int_type c = stream_.get(); 60 | if (RAPIDJSON_LIKELY(c != StreamType::traits_type::eof())) { 61 | count_++; 62 | return static_cast(c); 63 | } 64 | else 65 | return '\0'; 66 | } 67 | 68 | // tellg() may return -1 when failed. So we count by ourself. 69 | size_t Tell() const { return count_; } 70 | 71 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 72 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 73 | void Flush() { RAPIDJSON_ASSERT(false); } 74 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 75 | 76 | // For encoding detection only. 77 | const Ch* Peek4() const { 78 | RAPIDJSON_ASSERT(sizeof(Ch) == 1); // Only usable for byte stream. 79 | int i; 80 | bool hasError = false; 81 | for (i = 0; i < 4; ++i) { 82 | typename StreamType::int_type c = stream_.get(); 83 | if (c == StreamType::traits_type::eof()) { 84 | hasError = true; 85 | stream_.clear(); 86 | break; 87 | } 88 | peekBuffer_[i] = static_cast(c); 89 | } 90 | for (--i; i >= 0; --i) 91 | stream_.putback(peekBuffer_[i]); 92 | return !hasError ? peekBuffer_ : 0; 93 | } 94 | 95 | private: 96 | BasicIStreamWrapper(const BasicIStreamWrapper&); 97 | BasicIStreamWrapper& operator=(const BasicIStreamWrapper&); 98 | 99 | StreamType& stream_; 100 | size_t count_; //!< Number of characters read. Note: 101 | mutable Ch peekBuffer_[4]; 102 | }; 103 | 104 | typedef BasicIStreamWrapper IStreamWrapper; 105 | typedef BasicIStreamWrapper WIStreamWrapper; 106 | 107 | #if defined(__clang__) || defined(_MSC_VER) 108 | RAPIDJSON_DIAG_POP 109 | #endif 110 | 111 | RAPIDJSON_NAMESPACE_END 112 | 113 | #endif // RAPIDJSON_ISTREAMWRAPPER_H_ 114 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 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_MEMORYBUFFER_H_ 16 | #define RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 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_MEMORYSTREAM_H_ 16 | #define RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(unreachable-code) 23 | RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Represents an in-memory input byte stream. 29 | /*! 30 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 31 | 32 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 33 | 34 | Differences between MemoryStream and StringStream: 35 | 1. StringStream has encoding but MemoryStream is a byte stream. 36 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 37 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 38 | \note implements Stream concept 39 | */ 40 | struct MemoryStream { 41 | typedef char Ch; // byte 42 | 43 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 44 | 45 | Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 46 | Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 47 | size_t Tell() const { return static_cast(src_ - begin_); } 48 | 49 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 50 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 51 | void Flush() { RAPIDJSON_ASSERT(false); } 52 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 53 | 54 | // For encoding detection only. 55 | const Ch* Peek4() const { 56 | return Tell() + 4 <= size_ ? src_ : 0; 57 | } 58 | 59 | const Ch* src_; //!< Current read position. 60 | const Ch* begin_; //!< Original head of the string. 61 | const Ch* end_; //!< End of stream. 62 | size_t size_; //!< Size of the stream. 63 | }; 64 | 65 | RAPIDJSON_NAMESPACE_END 66 | 67 | #ifdef __clang__ 68 | RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 72 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/msinttypes/inttypes.h: -------------------------------------------------------------------------------- 1 | // ISO C9x compliant inttypes.h for Microsoft Visual Studio 2 | // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3 | // 4 | // Copyright (c) 2006-2013 Alexander Chemeris 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright 13 | // notice, this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // 3. Neither the name of the product nor the names of its contributors may 17 | // be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 23 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | // 31 | /////////////////////////////////////////////////////////////////////////////// 32 | 33 | // The above software in this distribution may have been modified by 34 | // THL A29 Limited ("Tencent Modifications"). 35 | // All Tencent Modifications are Copyright (C) 2015 THL A29 Limited. 36 | 37 | #ifndef _MSC_VER // [ 38 | #error "Use this header only with Microsoft Visual C++ compilers!" 39 | #endif // _MSC_VER ] 40 | 41 | #ifndef _MSC_INTTYPES_H_ // [ 42 | #define _MSC_INTTYPES_H_ 43 | 44 | #if _MSC_VER > 1000 45 | #pragma once 46 | #endif 47 | 48 | #include "stdint.h" 49 | 50 | // miloyip: VC supports inttypes.h since VC2013 51 | #if _MSC_VER >= 1800 52 | #include 53 | #else 54 | 55 | // 7.8 Format conversion of integer types 56 | 57 | typedef struct { 58 | intmax_t quot; 59 | intmax_t rem; 60 | } imaxdiv_t; 61 | 62 | // 7.8.1 Macros for format specifiers 63 | 64 | #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 65 | 66 | // The fprintf macros for signed integers are: 67 | #define PRId8 "d" 68 | #define PRIi8 "i" 69 | #define PRIdLEAST8 "d" 70 | #define PRIiLEAST8 "i" 71 | #define PRIdFAST8 "d" 72 | #define PRIiFAST8 "i" 73 | 74 | #define PRId16 "hd" 75 | #define PRIi16 "hi" 76 | #define PRIdLEAST16 "hd" 77 | #define PRIiLEAST16 "hi" 78 | #define PRIdFAST16 "hd" 79 | #define PRIiFAST16 "hi" 80 | 81 | #define PRId32 "I32d" 82 | #define PRIi32 "I32i" 83 | #define PRIdLEAST32 "I32d" 84 | #define PRIiLEAST32 "I32i" 85 | #define PRIdFAST32 "I32d" 86 | #define PRIiFAST32 "I32i" 87 | 88 | #define PRId64 "I64d" 89 | #define PRIi64 "I64i" 90 | #define PRIdLEAST64 "I64d" 91 | #define PRIiLEAST64 "I64i" 92 | #define PRIdFAST64 "I64d" 93 | #define PRIiFAST64 "I64i" 94 | 95 | #define PRIdMAX "I64d" 96 | #define PRIiMAX "I64i" 97 | 98 | #define PRIdPTR "Id" 99 | #define PRIiPTR "Ii" 100 | 101 | // The fprintf macros for unsigned integers are: 102 | #define PRIo8 "o" 103 | #define PRIu8 "u" 104 | #define PRIx8 "x" 105 | #define PRIX8 "X" 106 | #define PRIoLEAST8 "o" 107 | #define PRIuLEAST8 "u" 108 | #define PRIxLEAST8 "x" 109 | #define PRIXLEAST8 "X" 110 | #define PRIoFAST8 "o" 111 | #define PRIuFAST8 "u" 112 | #define PRIxFAST8 "x" 113 | #define PRIXFAST8 "X" 114 | 115 | #define PRIo16 "ho" 116 | #define PRIu16 "hu" 117 | #define PRIx16 "hx" 118 | #define PRIX16 "hX" 119 | #define PRIoLEAST16 "ho" 120 | #define PRIuLEAST16 "hu" 121 | #define PRIxLEAST16 "hx" 122 | #define PRIXLEAST16 "hX" 123 | #define PRIoFAST16 "ho" 124 | #define PRIuFAST16 "hu" 125 | #define PRIxFAST16 "hx" 126 | #define PRIXFAST16 "hX" 127 | 128 | #define PRIo32 "I32o" 129 | #define PRIu32 "I32u" 130 | #define PRIx32 "I32x" 131 | #define PRIX32 "I32X" 132 | #define PRIoLEAST32 "I32o" 133 | #define PRIuLEAST32 "I32u" 134 | #define PRIxLEAST32 "I32x" 135 | #define PRIXLEAST32 "I32X" 136 | #define PRIoFAST32 "I32o" 137 | #define PRIuFAST32 "I32u" 138 | #define PRIxFAST32 "I32x" 139 | #define PRIXFAST32 "I32X" 140 | 141 | #define PRIo64 "I64o" 142 | #define PRIu64 "I64u" 143 | #define PRIx64 "I64x" 144 | #define PRIX64 "I64X" 145 | #define PRIoLEAST64 "I64o" 146 | #define PRIuLEAST64 "I64u" 147 | #define PRIxLEAST64 "I64x" 148 | #define PRIXLEAST64 "I64X" 149 | #define PRIoFAST64 "I64o" 150 | #define PRIuFAST64 "I64u" 151 | #define PRIxFAST64 "I64x" 152 | #define PRIXFAST64 "I64X" 153 | 154 | #define PRIoMAX "I64o" 155 | #define PRIuMAX "I64u" 156 | #define PRIxMAX "I64x" 157 | #define PRIXMAX "I64X" 158 | 159 | #define PRIoPTR "Io" 160 | #define PRIuPTR "Iu" 161 | #define PRIxPTR "Ix" 162 | #define PRIXPTR "IX" 163 | 164 | // The fscanf macros for signed integers are: 165 | #define SCNd8 "d" 166 | #define SCNi8 "i" 167 | #define SCNdLEAST8 "d" 168 | #define SCNiLEAST8 "i" 169 | #define SCNdFAST8 "d" 170 | #define SCNiFAST8 "i" 171 | 172 | #define SCNd16 "hd" 173 | #define SCNi16 "hi" 174 | #define SCNdLEAST16 "hd" 175 | #define SCNiLEAST16 "hi" 176 | #define SCNdFAST16 "hd" 177 | #define SCNiFAST16 "hi" 178 | 179 | #define SCNd32 "ld" 180 | #define SCNi32 "li" 181 | #define SCNdLEAST32 "ld" 182 | #define SCNiLEAST32 "li" 183 | #define SCNdFAST32 "ld" 184 | #define SCNiFAST32 "li" 185 | 186 | #define SCNd64 "I64d" 187 | #define SCNi64 "I64i" 188 | #define SCNdLEAST64 "I64d" 189 | #define SCNiLEAST64 "I64i" 190 | #define SCNdFAST64 "I64d" 191 | #define SCNiFAST64 "I64i" 192 | 193 | #define SCNdMAX "I64d" 194 | #define SCNiMAX "I64i" 195 | 196 | #ifdef _WIN64 // [ 197 | # define SCNdPTR "I64d" 198 | # define SCNiPTR "I64i" 199 | #else // _WIN64 ][ 200 | # define SCNdPTR "ld" 201 | # define SCNiPTR "li" 202 | #endif // _WIN64 ] 203 | 204 | // The fscanf macros for unsigned integers are: 205 | #define SCNo8 "o" 206 | #define SCNu8 "u" 207 | #define SCNx8 "x" 208 | #define SCNX8 "X" 209 | #define SCNoLEAST8 "o" 210 | #define SCNuLEAST8 "u" 211 | #define SCNxLEAST8 "x" 212 | #define SCNXLEAST8 "X" 213 | #define SCNoFAST8 "o" 214 | #define SCNuFAST8 "u" 215 | #define SCNxFAST8 "x" 216 | #define SCNXFAST8 "X" 217 | 218 | #define SCNo16 "ho" 219 | #define SCNu16 "hu" 220 | #define SCNx16 "hx" 221 | #define SCNX16 "hX" 222 | #define SCNoLEAST16 "ho" 223 | #define SCNuLEAST16 "hu" 224 | #define SCNxLEAST16 "hx" 225 | #define SCNXLEAST16 "hX" 226 | #define SCNoFAST16 "ho" 227 | #define SCNuFAST16 "hu" 228 | #define SCNxFAST16 "hx" 229 | #define SCNXFAST16 "hX" 230 | 231 | #define SCNo32 "lo" 232 | #define SCNu32 "lu" 233 | #define SCNx32 "lx" 234 | #define SCNX32 "lX" 235 | #define SCNoLEAST32 "lo" 236 | #define SCNuLEAST32 "lu" 237 | #define SCNxLEAST32 "lx" 238 | #define SCNXLEAST32 "lX" 239 | #define SCNoFAST32 "lo" 240 | #define SCNuFAST32 "lu" 241 | #define SCNxFAST32 "lx" 242 | #define SCNXFAST32 "lX" 243 | 244 | #define SCNo64 "I64o" 245 | #define SCNu64 "I64u" 246 | #define SCNx64 "I64x" 247 | #define SCNX64 "I64X" 248 | #define SCNoLEAST64 "I64o" 249 | #define SCNuLEAST64 "I64u" 250 | #define SCNxLEAST64 "I64x" 251 | #define SCNXLEAST64 "I64X" 252 | #define SCNoFAST64 "I64o" 253 | #define SCNuFAST64 "I64u" 254 | #define SCNxFAST64 "I64x" 255 | #define SCNXFAST64 "I64X" 256 | 257 | #define SCNoMAX "I64o" 258 | #define SCNuMAX "I64u" 259 | #define SCNxMAX "I64x" 260 | #define SCNXMAX "I64X" 261 | 262 | #ifdef _WIN64 // [ 263 | # define SCNoPTR "I64o" 264 | # define SCNuPTR "I64u" 265 | # define SCNxPTR "I64x" 266 | # define SCNXPTR "I64X" 267 | #else // _WIN64 ][ 268 | # define SCNoPTR "lo" 269 | # define SCNuPTR "lu" 270 | # define SCNxPTR "lx" 271 | # define SCNXPTR "lX" 272 | #endif // _WIN64 ] 273 | 274 | #endif // __STDC_FORMAT_MACROS ] 275 | 276 | // 7.8.2 Functions for greatest-width integer types 277 | 278 | // 7.8.2.1 The imaxabs function 279 | #define imaxabs _abs64 280 | 281 | // 7.8.2.2 The imaxdiv function 282 | 283 | // This is modified version of div() function from Microsoft's div.c found 284 | // in %MSVC.NET%\crt\src\div.c 285 | #ifdef STATIC_IMAXDIV // [ 286 | static 287 | #else // STATIC_IMAXDIV ][ 288 | _inline 289 | #endif // STATIC_IMAXDIV ] 290 | imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) 291 | { 292 | imaxdiv_t result; 293 | 294 | result.quot = numer / denom; 295 | result.rem = numer % denom; 296 | 297 | if (numer < 0 && result.rem > 0) { 298 | // did division wrong; must fix up 299 | ++result.quot; 300 | result.rem -= denom; 301 | } 302 | 303 | return result; 304 | } 305 | 306 | // 7.8.2.3 The strtoimax and strtoumax functions 307 | #define strtoimax _strtoi64 308 | #define strtoumax _strtoui64 309 | 310 | // 7.8.2.4 The wcstoimax and wcstoumax functions 311 | #define wcstoimax _wcstoi64 312 | #define wcstoumax _wcstoui64 313 | 314 | #endif // _MSC_VER >= 1800 315 | 316 | #endif // _MSC_INTTYPES_H_ ] 317 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/msinttypes/stdint.h: -------------------------------------------------------------------------------- 1 | // ISO C9x compliant stdint.h for Microsoft Visual Studio 2 | // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3 | // 4 | // Copyright (c) 2006-2013 Alexander Chemeris 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright 13 | // notice, this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // 3. Neither the name of the product nor the names of its contributors may 17 | // be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 23 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | // 31 | /////////////////////////////////////////////////////////////////////////////// 32 | 33 | // The above software in this distribution may have been modified by 34 | // THL A29 Limited ("Tencent Modifications"). 35 | // All Tencent Modifications are Copyright (C) 2015 THL A29 Limited. 36 | 37 | #ifndef _MSC_VER // [ 38 | #error "Use this header only with Microsoft Visual C++ compilers!" 39 | #endif // _MSC_VER ] 40 | 41 | #ifndef _MSC_STDINT_H_ // [ 42 | #define _MSC_STDINT_H_ 43 | 44 | #if _MSC_VER > 1000 45 | #pragma once 46 | #endif 47 | 48 | // miloyip: Originally Visual Studio 2010 uses its own stdint.h. However it generates warning with INT64_C(), so change to use this file for vs2010. 49 | #if _MSC_VER >= 1600 // [ 50 | #include 51 | 52 | #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 53 | 54 | #undef INT8_C 55 | #undef INT16_C 56 | #undef INT32_C 57 | #undef INT64_C 58 | #undef UINT8_C 59 | #undef UINT16_C 60 | #undef UINT32_C 61 | #undef UINT64_C 62 | 63 | // 7.18.4.1 Macros for minimum-width integer constants 64 | 65 | #define INT8_C(val) val##i8 66 | #define INT16_C(val) val##i16 67 | #define INT32_C(val) val##i32 68 | #define INT64_C(val) val##i64 69 | 70 | #define UINT8_C(val) val##ui8 71 | #define UINT16_C(val) val##ui16 72 | #define UINT32_C(val) val##ui32 73 | #define UINT64_C(val) val##ui64 74 | 75 | // 7.18.4.2 Macros for greatest-width integer constants 76 | // These #ifndef's are needed to prevent collisions with . 77 | // Check out Issue 9 for the details. 78 | #ifndef INTMAX_C // [ 79 | # define INTMAX_C INT64_C 80 | #endif // INTMAX_C ] 81 | #ifndef UINTMAX_C // [ 82 | # define UINTMAX_C UINT64_C 83 | #endif // UINTMAX_C ] 84 | 85 | #endif // __STDC_CONSTANT_MACROS ] 86 | 87 | #else // ] _MSC_VER >= 1700 [ 88 | 89 | #include 90 | 91 | // For Visual Studio 6 in C++ mode and for many Visual Studio versions when 92 | // compiling for ARM we have to wrap include with 'extern "C++" {}' 93 | // or compiler would give many errors like this: 94 | // error C2733: second C linkage of overloaded function 'wmemchr' not allowed 95 | #if defined(__cplusplus) && !defined(_M_ARM) 96 | extern "C" { 97 | #endif 98 | # include 99 | #if defined(__cplusplus) && !defined(_M_ARM) 100 | } 101 | #endif 102 | 103 | // Define _W64 macros to mark types changing their size, like intptr_t. 104 | #ifndef _W64 105 | # if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 106 | # define _W64 __w64 107 | # else 108 | # define _W64 109 | # endif 110 | #endif 111 | 112 | 113 | // 7.18.1 Integer types 114 | 115 | // 7.18.1.1 Exact-width integer types 116 | 117 | // Visual Studio 6 and Embedded Visual C++ 4 doesn't 118 | // realize that, e.g. char has the same size as __int8 119 | // so we give up on __intX for them. 120 | #if (_MSC_VER < 1300) 121 | typedef signed char int8_t; 122 | typedef signed short int16_t; 123 | typedef signed int int32_t; 124 | typedef unsigned char uint8_t; 125 | typedef unsigned short uint16_t; 126 | typedef unsigned int uint32_t; 127 | #else 128 | typedef signed __int8 int8_t; 129 | typedef signed __int16 int16_t; 130 | typedef signed __int32 int32_t; 131 | typedef unsigned __int8 uint8_t; 132 | typedef unsigned __int16 uint16_t; 133 | typedef unsigned __int32 uint32_t; 134 | #endif 135 | typedef signed __int64 int64_t; 136 | typedef unsigned __int64 uint64_t; 137 | 138 | 139 | // 7.18.1.2 Minimum-width integer types 140 | typedef int8_t int_least8_t; 141 | typedef int16_t int_least16_t; 142 | typedef int32_t int_least32_t; 143 | typedef int64_t int_least64_t; 144 | typedef uint8_t uint_least8_t; 145 | typedef uint16_t uint_least16_t; 146 | typedef uint32_t uint_least32_t; 147 | typedef uint64_t uint_least64_t; 148 | 149 | // 7.18.1.3 Fastest minimum-width integer types 150 | typedef int8_t int_fast8_t; 151 | typedef int16_t int_fast16_t; 152 | typedef int32_t int_fast32_t; 153 | typedef int64_t int_fast64_t; 154 | typedef uint8_t uint_fast8_t; 155 | typedef uint16_t uint_fast16_t; 156 | typedef uint32_t uint_fast32_t; 157 | typedef uint64_t uint_fast64_t; 158 | 159 | // 7.18.1.4 Integer types capable of holding object pointers 160 | #ifdef _WIN64 // [ 161 | typedef signed __int64 intptr_t; 162 | typedef unsigned __int64 uintptr_t; 163 | #else // _WIN64 ][ 164 | typedef _W64 signed int intptr_t; 165 | typedef _W64 unsigned int uintptr_t; 166 | #endif // _WIN64 ] 167 | 168 | // 7.18.1.5 Greatest-width integer types 169 | typedef int64_t intmax_t; 170 | typedef uint64_t uintmax_t; 171 | 172 | 173 | // 7.18.2 Limits of specified-width integer types 174 | 175 | #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 176 | 177 | // 7.18.2.1 Limits of exact-width integer types 178 | #define INT8_MIN ((int8_t)_I8_MIN) 179 | #define INT8_MAX _I8_MAX 180 | #define INT16_MIN ((int16_t)_I16_MIN) 181 | #define INT16_MAX _I16_MAX 182 | #define INT32_MIN ((int32_t)_I32_MIN) 183 | #define INT32_MAX _I32_MAX 184 | #define INT64_MIN ((int64_t)_I64_MIN) 185 | #define INT64_MAX _I64_MAX 186 | #define UINT8_MAX _UI8_MAX 187 | #define UINT16_MAX _UI16_MAX 188 | #define UINT32_MAX _UI32_MAX 189 | #define UINT64_MAX _UI64_MAX 190 | 191 | // 7.18.2.2 Limits of minimum-width integer types 192 | #define INT_LEAST8_MIN INT8_MIN 193 | #define INT_LEAST8_MAX INT8_MAX 194 | #define INT_LEAST16_MIN INT16_MIN 195 | #define INT_LEAST16_MAX INT16_MAX 196 | #define INT_LEAST32_MIN INT32_MIN 197 | #define INT_LEAST32_MAX INT32_MAX 198 | #define INT_LEAST64_MIN INT64_MIN 199 | #define INT_LEAST64_MAX INT64_MAX 200 | #define UINT_LEAST8_MAX UINT8_MAX 201 | #define UINT_LEAST16_MAX UINT16_MAX 202 | #define UINT_LEAST32_MAX UINT32_MAX 203 | #define UINT_LEAST64_MAX UINT64_MAX 204 | 205 | // 7.18.2.3 Limits of fastest minimum-width integer types 206 | #define INT_FAST8_MIN INT8_MIN 207 | #define INT_FAST8_MAX INT8_MAX 208 | #define INT_FAST16_MIN INT16_MIN 209 | #define INT_FAST16_MAX INT16_MAX 210 | #define INT_FAST32_MIN INT32_MIN 211 | #define INT_FAST32_MAX INT32_MAX 212 | #define INT_FAST64_MIN INT64_MIN 213 | #define INT_FAST64_MAX INT64_MAX 214 | #define UINT_FAST8_MAX UINT8_MAX 215 | #define UINT_FAST16_MAX UINT16_MAX 216 | #define UINT_FAST32_MAX UINT32_MAX 217 | #define UINT_FAST64_MAX UINT64_MAX 218 | 219 | // 7.18.2.4 Limits of integer types capable of holding object pointers 220 | #ifdef _WIN64 // [ 221 | # define INTPTR_MIN INT64_MIN 222 | # define INTPTR_MAX INT64_MAX 223 | # define UINTPTR_MAX UINT64_MAX 224 | #else // _WIN64 ][ 225 | # define INTPTR_MIN INT32_MIN 226 | # define INTPTR_MAX INT32_MAX 227 | # define UINTPTR_MAX UINT32_MAX 228 | #endif // _WIN64 ] 229 | 230 | // 7.18.2.5 Limits of greatest-width integer types 231 | #define INTMAX_MIN INT64_MIN 232 | #define INTMAX_MAX INT64_MAX 233 | #define UINTMAX_MAX UINT64_MAX 234 | 235 | // 7.18.3 Limits of other integer types 236 | 237 | #ifdef _WIN64 // [ 238 | # define PTRDIFF_MIN _I64_MIN 239 | # define PTRDIFF_MAX _I64_MAX 240 | #else // _WIN64 ][ 241 | # define PTRDIFF_MIN _I32_MIN 242 | # define PTRDIFF_MAX _I32_MAX 243 | #endif // _WIN64 ] 244 | 245 | #define SIG_ATOMIC_MIN INT_MIN 246 | #define SIG_ATOMIC_MAX INT_MAX 247 | 248 | #ifndef SIZE_MAX // [ 249 | # ifdef _WIN64 // [ 250 | # define SIZE_MAX _UI64_MAX 251 | # else // _WIN64 ][ 252 | # define SIZE_MAX _UI32_MAX 253 | # endif // _WIN64 ] 254 | #endif // SIZE_MAX ] 255 | 256 | // WCHAR_MIN and WCHAR_MAX are also defined in 257 | #ifndef WCHAR_MIN // [ 258 | # define WCHAR_MIN 0 259 | #endif // WCHAR_MIN ] 260 | #ifndef WCHAR_MAX // [ 261 | # define WCHAR_MAX _UI16_MAX 262 | #endif // WCHAR_MAX ] 263 | 264 | #define WINT_MIN 0 265 | #define WINT_MAX _UI16_MAX 266 | 267 | #endif // __STDC_LIMIT_MACROS ] 268 | 269 | 270 | // 7.18.4 Limits of other integer types 271 | 272 | #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 273 | 274 | // 7.18.4.1 Macros for minimum-width integer constants 275 | 276 | #define INT8_C(val) val##i8 277 | #define INT16_C(val) val##i16 278 | #define INT32_C(val) val##i32 279 | #define INT64_C(val) val##i64 280 | 281 | #define UINT8_C(val) val##ui8 282 | #define UINT16_C(val) val##ui16 283 | #define UINT32_C(val) val##ui32 284 | #define UINT64_C(val) val##ui64 285 | 286 | // 7.18.4.2 Macros for greatest-width integer constants 287 | // These #ifndef's are needed to prevent collisions with . 288 | // Check out Issue 9 for the details. 289 | #ifndef INTMAX_C // [ 290 | # define INTMAX_C INT64_C 291 | #endif // INTMAX_C ] 292 | #ifndef UINTMAX_C // [ 293 | # define UINTMAX_C UINT64_C 294 | #endif // UINTMAX_C ] 295 | 296 | #endif // __STDC_CONSTANT_MACROS ] 297 | 298 | #endif // _MSC_VER >= 1600 ] 299 | 300 | #endif // _MSC_STDINT_H_ ] 301 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 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_OSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/prettywriter.h: -------------------------------------------------------------------------------- 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_PRETTYWRITER_H_ 16 | #define RAPIDJSON_PRETTYWRITER_H_ 17 | 18 | #include "writer.h" 19 | 20 | #ifdef __GNUC__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | 25 | #if defined(__clang__) 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(c++98-compat) 28 | #endif 29 | 30 | RAPIDJSON_NAMESPACE_BEGIN 31 | 32 | //! Combination of PrettyWriter format flags. 33 | /*! \see PrettyWriter::SetFormatOptions 34 | */ 35 | enum PrettyFormatOptions { 36 | kFormatDefault = 0, //!< Default pretty formatting. 37 | kFormatSingleLineArray = 1 //!< Format arrays on a single line. 38 | }; 39 | 40 | //! Writer with indentation and spacing. 41 | /*! 42 | \tparam OutputStream Type of output os. 43 | \tparam SourceEncoding Encoding of source string. 44 | \tparam TargetEncoding Encoding of output stream. 45 | \tparam StackAllocator Type of allocator for allocating memory of stack. 46 | */ 47 | template, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags> 48 | class PrettyWriter : public Writer { 49 | public: 50 | typedef Writer Base; 51 | typedef typename Base::Ch Ch; 52 | 53 | //! Constructor 54 | /*! \param os Output stream. 55 | \param allocator User supplied allocator. If it is null, it will create a private one. 56 | \param levelDepth Initial capacity of stack. 57 | */ 58 | explicit PrettyWriter(OutputStream& os, StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) : 59 | Base(os, allocator, levelDepth), indentChar_(' '), indentCharCount_(4), formatOptions_(kFormatDefault) {} 60 | 61 | 62 | explicit PrettyWriter(StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) : 63 | Base(allocator, levelDepth), indentChar_(' '), indentCharCount_(4) {} 64 | 65 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 66 | PrettyWriter(PrettyWriter&& rhs) : 67 | Base(std::forward(rhs)), indentChar_(rhs.indentChar_), indentCharCount_(rhs.indentCharCount_), formatOptions_(rhs.formatOptions_) {} 68 | #endif 69 | 70 | //! Set custom indentation. 71 | /*! \param indentChar Character for indentation. Must be whitespace character (' ', '\\t', '\\n', '\\r'). 72 | \param indentCharCount Number of indent characters for each indentation level. 73 | \note The default indentation is 4 spaces. 74 | */ 75 | PrettyWriter& SetIndent(Ch indentChar, unsigned indentCharCount) { 76 | RAPIDJSON_ASSERT(indentChar == ' ' || indentChar == '\t' || indentChar == '\n' || indentChar == '\r'); 77 | indentChar_ = indentChar; 78 | indentCharCount_ = indentCharCount; 79 | return *this; 80 | } 81 | 82 | //! Set pretty writer formatting options. 83 | /*! \param options Formatting options. 84 | */ 85 | PrettyWriter& SetFormatOptions(PrettyFormatOptions options) { 86 | formatOptions_ = options; 87 | return *this; 88 | } 89 | 90 | /*! @name Implementation of Handler 91 | \see Handler 92 | */ 93 | //@{ 94 | 95 | bool Null() { PrettyPrefix(kNullType); return Base::EndValue(Base::WriteNull()); } 96 | bool Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); return Base::EndValue(Base::WriteBool(b)); } 97 | bool Int(int i) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteInt(i)); } 98 | bool Uint(unsigned u) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteUint(u)); } 99 | bool Int64(int64_t i64) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteInt64(i64)); } 100 | bool Uint64(uint64_t u64) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteUint64(u64)); } 101 | bool Double(double d) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteDouble(d)); } 102 | 103 | bool RawNumber(const Ch* str, SizeType length, bool copy = false) { 104 | RAPIDJSON_ASSERT(str != 0); 105 | (void)copy; 106 | PrettyPrefix(kNumberType); 107 | return Base::EndValue(Base::WriteString(str, length)); 108 | } 109 | 110 | bool String(const Ch* str, SizeType length, bool copy = false) { 111 | RAPIDJSON_ASSERT(str != 0); 112 | (void)copy; 113 | PrettyPrefix(kStringType); 114 | return Base::EndValue(Base::WriteString(str, length)); 115 | } 116 | 117 | #if RAPIDJSON_HAS_STDSTRING 118 | bool String(const std::basic_string& str) { 119 | return String(str.data(), SizeType(str.size())); 120 | } 121 | #endif 122 | 123 | bool StartObject() { 124 | PrettyPrefix(kObjectType); 125 | new (Base::level_stack_.template Push()) typename Base::Level(false); 126 | return Base::WriteStartObject(); 127 | } 128 | 129 | bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); } 130 | 131 | #if RAPIDJSON_HAS_STDSTRING 132 | bool Key(const std::basic_string& str) { 133 | return Key(str.data(), SizeType(str.size())); 134 | } 135 | #endif 136 | 137 | bool EndObject(SizeType memberCount = 0) { 138 | (void)memberCount; 139 | RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); // not inside an Object 140 | RAPIDJSON_ASSERT(!Base::level_stack_.template Top()->inArray); // currently inside an Array, not Object 141 | RAPIDJSON_ASSERT(0 == Base::level_stack_.template Top()->valueCount % 2); // Object has a Key without a Value 142 | 143 | bool empty = Base::level_stack_.template Pop(1)->valueCount == 0; 144 | 145 | if (!empty) { 146 | Base::os_->Put('\n'); 147 | WriteIndent(); 148 | } 149 | bool ret = Base::EndValue(Base::WriteEndObject()); 150 | (void)ret; 151 | RAPIDJSON_ASSERT(ret == true); 152 | if (Base::level_stack_.Empty()) // end of json text 153 | Base::Flush(); 154 | return true; 155 | } 156 | 157 | bool StartArray() { 158 | PrettyPrefix(kArrayType); 159 | new (Base::level_stack_.template Push()) typename Base::Level(true); 160 | return Base::WriteStartArray(); 161 | } 162 | 163 | bool EndArray(SizeType memberCount = 0) { 164 | (void)memberCount; 165 | RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); 166 | RAPIDJSON_ASSERT(Base::level_stack_.template Top()->inArray); 167 | bool empty = Base::level_stack_.template Pop(1)->valueCount == 0; 168 | 169 | if (!empty && !(formatOptions_ & kFormatSingleLineArray)) { 170 | Base::os_->Put('\n'); 171 | WriteIndent(); 172 | } 173 | bool ret = Base::EndValue(Base::WriteEndArray()); 174 | (void)ret; 175 | RAPIDJSON_ASSERT(ret == true); 176 | if (Base::level_stack_.Empty()) // end of json text 177 | Base::Flush(); 178 | return true; 179 | } 180 | 181 | //@} 182 | 183 | /*! @name Convenience extensions */ 184 | //@{ 185 | 186 | //! Simpler but slower overload. 187 | bool String(const Ch* str) { return String(str, internal::StrLen(str)); } 188 | bool Key(const Ch* str) { return Key(str, internal::StrLen(str)); } 189 | 190 | //@} 191 | 192 | //! Write a raw JSON value. 193 | /*! 194 | For user to write a stringified JSON as a value. 195 | 196 | \param json A well-formed JSON value. It should not contain null character within [0, length - 1] range. 197 | \param length Length of the json. 198 | \param type Type of the root of json. 199 | \note When using PrettyWriter::RawValue(), the result json may not be indented correctly. 200 | */ 201 | bool RawValue(const Ch* json, size_t length, Type type) { 202 | RAPIDJSON_ASSERT(json != 0); 203 | PrettyPrefix(type); 204 | return Base::EndValue(Base::WriteRawValue(json, length)); 205 | } 206 | 207 | protected: 208 | void PrettyPrefix(Type type) { 209 | (void)type; 210 | if (Base::level_stack_.GetSize() != 0) { // this value is not at root 211 | typename Base::Level* level = Base::level_stack_.template Top(); 212 | 213 | if (level->inArray) { 214 | if (level->valueCount > 0) { 215 | Base::os_->Put(','); // add comma if it is not the first element in array 216 | if (formatOptions_ & kFormatSingleLineArray) 217 | Base::os_->Put(' '); 218 | } 219 | 220 | if (!(formatOptions_ & kFormatSingleLineArray)) { 221 | Base::os_->Put('\n'); 222 | WriteIndent(); 223 | } 224 | } 225 | else { // in object 226 | if (level->valueCount > 0) { 227 | if (level->valueCount % 2 == 0) { 228 | Base::os_->Put(','); 229 | Base::os_->Put('\n'); 230 | } 231 | else { 232 | Base::os_->Put(':'); 233 | Base::os_->Put(' '); 234 | } 235 | } 236 | else 237 | Base::os_->Put('\n'); 238 | 239 | if (level->valueCount % 2 == 0) 240 | WriteIndent(); 241 | } 242 | if (!level->inArray && level->valueCount % 2 == 0) 243 | RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name 244 | level->valueCount++; 245 | } 246 | else { 247 | RAPIDJSON_ASSERT(!Base::hasRoot_); // Should only has one and only one root. 248 | Base::hasRoot_ = true; 249 | } 250 | } 251 | 252 | void WriteIndent() { 253 | size_t count = (Base::level_stack_.GetSize() / sizeof(typename Base::Level)) * indentCharCount_; 254 | PutN(*Base::os_, static_cast(indentChar_), count); 255 | } 256 | 257 | Ch indentChar_; 258 | unsigned indentCharCount_; 259 | PrettyFormatOptions formatOptions_; 260 | 261 | private: 262 | // Prohibit copy constructor & assignment operator. 263 | PrettyWriter(const PrettyWriter&); 264 | PrettyWriter& operator=(const PrettyWriter&); 265 | }; 266 | 267 | RAPIDJSON_NAMESPACE_END 268 | 269 | #if defined(__clang__) 270 | RAPIDJSON_DIAG_POP 271 | #endif 272 | 273 | #ifdef __GNUC__ 274 | RAPIDJSON_DIAG_POP 275 | #endif 276 | 277 | #endif // RAPIDJSON_RAPIDJSON_H_ 278 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/stream.h: -------------------------------------------------------------------------------- 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 | #include "rapidjson.h" 16 | 17 | #ifndef RAPIDJSON_STREAM_H_ 18 | #define RAPIDJSON_STREAM_H_ 19 | 20 | #include "encodings.h" 21 | 22 | RAPIDJSON_NAMESPACE_BEGIN 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // Stream 26 | 27 | /*! \class rapidjson::Stream 28 | \brief Concept for reading and writing characters. 29 | 30 | For read-only stream, no need to implement PutBegin(), Put(), Flush() and PutEnd(). 31 | 32 | For write-only stream, only need to implement Put() and Flush(). 33 | 34 | \code 35 | concept Stream { 36 | typename Ch; //!< Character type of the stream. 37 | 38 | //! Read the current character from stream without moving the read cursor. 39 | Ch Peek() const; 40 | 41 | //! Read the current character from stream and moving the read cursor to next character. 42 | Ch Take(); 43 | 44 | //! Get the current read cursor. 45 | //! \return Number of characters read from start. 46 | size_t Tell(); 47 | 48 | //! Begin writing operation at the current read pointer. 49 | //! \return The begin writer pointer. 50 | Ch* PutBegin(); 51 | 52 | //! Write a character. 53 | void Put(Ch c); 54 | 55 | //! Flush the buffer. 56 | void Flush(); 57 | 58 | //! End the writing operation. 59 | //! \param begin The begin write pointer returned by PutBegin(). 60 | //! \return Number of characters written. 61 | size_t PutEnd(Ch* begin); 62 | } 63 | \endcode 64 | */ 65 | 66 | //! Provides additional information for stream. 67 | /*! 68 | By using traits pattern, this type provides a default configuration for stream. 69 | For custom stream, this type can be specialized for other configuration. 70 | See TEST(Reader, CustomStringStream) in readertest.cpp for example. 71 | */ 72 | template 73 | struct StreamTraits { 74 | //! Whether to make local copy of stream for optimization during parsing. 75 | /*! 76 | By default, for safety, streams do not use local copy optimization. 77 | Stream that can be copied fast should specialize this, like StreamTraits. 78 | */ 79 | enum { copyOptimization = 0 }; 80 | }; 81 | 82 | //! Reserve n characters for writing to a stream. 83 | template 84 | inline void PutReserve(Stream& stream, size_t count) { 85 | (void)stream; 86 | (void)count; 87 | } 88 | 89 | //! Write character to a stream, presuming buffer is reserved. 90 | template 91 | inline void PutUnsafe(Stream& stream, typename Stream::Ch c) { 92 | stream.Put(c); 93 | } 94 | 95 | //! Put N copies of a character to a stream. 96 | template 97 | inline void PutN(Stream& stream, Ch c, size_t n) { 98 | PutReserve(stream, n); 99 | for (size_t i = 0; i < n; i++) 100 | PutUnsafe(stream, c); 101 | } 102 | 103 | /////////////////////////////////////////////////////////////////////////////// 104 | // GenericStreamWrapper 105 | 106 | //! A Stream Wrapper 107 | /*! \tThis string stream is a wrapper for any stream by just forwarding any 108 | \treceived message to the origin stream. 109 | \note implements Stream concept 110 | */ 111 | 112 | #if defined(_MSC_VER) && _MSC_VER <= 1800 113 | RAPIDJSON_DIAG_PUSH 114 | RAPIDJSON_DIAG_OFF(4702) // unreachable code 115 | RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 116 | #endif 117 | 118 | template > 119 | class GenericStreamWrapper { 120 | public: 121 | typedef typename Encoding::Ch Ch; 122 | GenericStreamWrapper(InputStream& is): is_(is) {} 123 | 124 | Ch Peek() const { return is_.Peek(); } 125 | Ch Take() { return is_.Take(); } 126 | size_t Tell() { return is_.Tell(); } 127 | Ch* PutBegin() { return is_.PutBegin(); } 128 | void Put(Ch ch) { is_.Put(ch); } 129 | void Flush() { is_.Flush(); } 130 | size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); } 131 | 132 | // wrapper for MemoryStream 133 | const Ch* Peek4() const { return is_.Peek4(); } 134 | 135 | // wrapper for AutoUTFInputStream 136 | UTFType GetType() const { return is_.GetType(); } 137 | bool HasBOM() const { return is_.HasBOM(); } 138 | 139 | protected: 140 | InputStream& is_; 141 | }; 142 | 143 | #if defined(_MSC_VER) && _MSC_VER <= 1800 144 | RAPIDJSON_DIAG_POP 145 | #endif 146 | 147 | /////////////////////////////////////////////////////////////////////////////// 148 | // StringStream 149 | 150 | //! Read-only string stream. 151 | /*! \note implements Stream concept 152 | */ 153 | template 154 | struct GenericStringStream { 155 | typedef typename Encoding::Ch Ch; 156 | 157 | GenericStringStream(const Ch *src) : src_(src), head_(src) {} 158 | 159 | Ch Peek() const { return *src_; } 160 | Ch Take() { return *src_++; } 161 | size_t Tell() const { return static_cast(src_ - head_); } 162 | 163 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 164 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 165 | void Flush() { RAPIDJSON_ASSERT(false); } 166 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 167 | 168 | const Ch* src_; //!< Current read position. 169 | const Ch* head_; //!< Original head of the string. 170 | }; 171 | 172 | template 173 | struct StreamTraits > { 174 | enum { copyOptimization = 1 }; 175 | }; 176 | 177 | //! String stream with UTF8 encoding. 178 | typedef GenericStringStream > StringStream; 179 | 180 | /////////////////////////////////////////////////////////////////////////////// 181 | // InsituStringStream 182 | 183 | //! A read-write string stream. 184 | /*! This string stream is particularly designed for in-situ parsing. 185 | \note implements Stream concept 186 | */ 187 | template 188 | struct GenericInsituStringStream { 189 | typedef typename Encoding::Ch Ch; 190 | 191 | GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {} 192 | 193 | // Read 194 | Ch Peek() { return *src_; } 195 | Ch Take() { return *src_++; } 196 | size_t Tell() { return static_cast(src_ - head_); } 197 | 198 | // Write 199 | void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; } 200 | 201 | Ch* PutBegin() { return dst_ = src_; } 202 | size_t PutEnd(Ch* begin) { return static_cast(dst_ - begin); } 203 | void Flush() {} 204 | 205 | Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; } 206 | void Pop(size_t count) { dst_ -= count; } 207 | 208 | Ch* src_; 209 | Ch* dst_; 210 | Ch* head_; 211 | }; 212 | 213 | template 214 | struct StreamTraits > { 215 | enum { copyOptimization = 1 }; 216 | }; 217 | 218 | //! Insitu string stream with UTF8 encoding. 219 | typedef GenericInsituStringStream > InsituStringStream; 220 | 221 | RAPIDJSON_NAMESPACE_END 222 | 223 | #endif // RAPIDJSON_STREAM_H_ 224 | -------------------------------------------------------------------------------- /libs/rapidjson/include/rapidjson/stringbuffer.h: -------------------------------------------------------------------------------- 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_STRINGBUFFER_H_ 16 | #define RAPIDJSON_STRINGBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 22 | #include // std::move 23 | #endif 24 | 25 | #include "internal/stack.h" 26 | 27 | #if defined(__clang__) 28 | RAPIDJSON_DIAG_PUSH 29 | RAPIDJSON_DIAG_OFF(c++98-compat) 30 | #endif 31 | 32 | RAPIDJSON_NAMESPACE_BEGIN 33 | 34 | //! Represents an in-memory output stream. 35 | /*! 36 | \tparam Encoding Encoding of the stream. 37 | \tparam Allocator type for allocating memory buffer. 38 | \note implements Stream concept 39 | */ 40 | template 41 | class GenericStringBuffer { 42 | public: 43 | typedef typename Encoding::Ch Ch; 44 | 45 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 46 | 47 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 48 | GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {} 49 | GenericStringBuffer& operator=(GenericStringBuffer&& rhs) { 50 | if (&rhs != this) 51 | stack_ = std::move(rhs.stack_); 52 | return *this; 53 | } 54 | #endif 55 | 56 | void Put(Ch c) { *stack_.template Push() = c; } 57 | void PutUnsafe(Ch c) { *stack_.template PushUnsafe() = c; } 58 | void Flush() {} 59 | 60 | void Clear() { stack_.Clear(); } 61 | void ShrinkToFit() { 62 | // Push and pop a null terminator. This is safe. 63 | *stack_.template Push() = '\0'; 64 | stack_.ShrinkToFit(); 65 | stack_.template Pop(1); 66 | } 67 | 68 | void Reserve(size_t count) { stack_.template Reserve(count); } 69 | Ch* Push(size_t count) { return stack_.template Push(count); } 70 | Ch* PushUnsafe(size_t count) { return stack_.template PushUnsafe(count); } 71 | void Pop(size_t count) { stack_.template Pop(count); } 72 | 73 | const Ch* GetString() const { 74 | // Push and pop a null terminator. This is safe. 75 | *stack_.template Push() = '\0'; 76 | stack_.template Pop(1); 77 | 78 | return stack_.template Bottom(); 79 | } 80 | 81 | //! Get the size of string in bytes in the string buffer. 82 | size_t GetSize() const { return stack_.GetSize(); } 83 | 84 | //! Get the length of string in Ch in the string buffer. 85 | size_t GetLength() const { return stack_.GetSize() / sizeof(Ch); } 86 | 87 | static const size_t kDefaultCapacity = 256; 88 | mutable internal::Stack stack_; 89 | 90 | private: 91 | // Prohibit copy constructor & assignment operator. 92 | GenericStringBuffer(const GenericStringBuffer&); 93 | GenericStringBuffer& operator=(const GenericStringBuffer&); 94 | }; 95 | 96 | //! String buffer with UTF8 encoding 97 | typedef GenericStringBuffer > StringBuffer; 98 | 99 | template 100 | inline void PutReserve(GenericStringBuffer& stream, size_t count) { 101 | stream.Reserve(count); 102 | } 103 | 104 | template 105 | inline void PutUnsafe(GenericStringBuffer& stream, typename Encoding::Ch c) { 106 | stream.PutUnsafe(c); 107 | } 108 | 109 | //! Implement specialized version of PutN() with memset() for better performance. 110 | template<> 111 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 112 | std::memset(stream.stack_.Push(n), c, n * sizeof(c)); 113 | } 114 | 115 | RAPIDJSON_NAMESPACE_END 116 | 117 | #if defined(__clang__) 118 | RAPIDJSON_DIAG_POP 119 | #endif 120 | 121 | #endif // RAPIDJSON_STRINGBUFFER_H_ 122 | -------------------------------------------------------------------------------- /libs/rapidjson/license.txt: -------------------------------------------------------------------------------- 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 | If you have downloaded a copy of the RapidJSON binary from Tencent, please note that the RapidJSON binary is licensed under the MIT License. 6 | If you have downloaded a copy of the RapidJSON source code from Tencent, please note that RapidJSON source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms. Your integration of RapidJSON into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within RapidJSON. To avoid the problematic JSON license in your own projects, it's sufficient to exclude the bin/jsonchecker/ directory, as it's the only code under the JSON license. 7 | A copy of the MIT License is included in this file. 8 | 9 | Other dependencies and licenses: 10 | 11 | Open Source Software Licensed Under the BSD License: 12 | -------------------------------------------------------------------- 13 | 14 | The msinttypes r29 15 | Copyright (c) 2006-2013 Alexander Chemeris 16 | All rights reserved. 17 | 18 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 19 | 20 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 21 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 22 | * Neither the name of copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | Open Source Software Licensed Under the JSON License: 27 | -------------------------------------------------------------------- 28 | 29 | json.org 30 | Copyright (c) 2002 JSON.org 31 | All Rights Reserved. 32 | 33 | JSON_checker 34 | Copyright (c) 2002 JSON.org 35 | All Rights Reserved. 36 | 37 | 38 | Terms of the JSON License: 39 | --------------------------------------------------- 40 | 41 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 44 | 45 | The Software shall be used for Good, not Evil. 46 | 47 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 48 | 49 | 50 | Terms of the MIT License: 51 | -------------------------------------------------------------------- 52 | 53 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 54 | 55 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 56 | 57 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 58 | -------------------------------------------------------------------------------- /src/formatter.cpp: -------------------------------------------------------------------------------- 1 | #include "formatter.h" 2 | #include "logger.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | bool Formatter::LoadFormat(const char* fmt) 9 | { 10 | if (!strcmp(fmt, "json")) { 11 | return true; 12 | } 13 | 14 | m_bJson = false; 15 | 16 | libconfig::Config cfg; 17 | try { 18 | cfg.readFile("formats.cfg"); 19 | } catch (const libconfig::FileIOException& fioex) { 20 | Logger::Error("Failed to open file: \"formats.cfg\""); 21 | return false; 22 | } catch (const libconfig::ParseException& pex) { 23 | Logger::Error("Parse exception: {}\nFile: {}:{}\n", 24 | pex.getError(), "formats.cfg", pex.getLine()); 25 | return false; 26 | } 27 | 28 | try { 29 | libconfig::Setting& formats = cfg.lookup("formats"); 30 | libconfig::Setting& entry = formats.lookup(fmt); 31 | 32 | if (!entry.lookupValue("table_begin", m_fmtTableBegin)) { 33 | return false; 34 | } 35 | 36 | if (!entry.lookupValue("table_end", m_fmtTableEnd)) { 37 | return false; 38 | } 39 | 40 | if (!entry.lookupValue("offset", m_fmtOffset)) { 41 | return false; 42 | } 43 | 44 | entry.lookupValue("strip_table_prefix", m_fmtRemovePrefix); 45 | entry.lookupValue("header", m_fmtHeader); 46 | entry.lookupValue("footer", m_fmtFooter); 47 | entry.lookupValue("timestamp", m_fmtTimestamp); 48 | entry.lookupValue("indent", m_fmtIndent); 49 | entry.lookupValue("default_depth", m_depth); 50 | if (entry.exists("replace_chars")) { 51 | for (const libconfig::Setting& pair : entry.lookup("replace_chars")) { 52 | const char* before = pair[0]; 53 | if (pair.getLength() == 2) { 54 | const char* after = pair[1]; 55 | m_fmtReplaceChars.push_back({before[0], after[0]}); 56 | } else { 57 | m_fmtReplaceChars.push_back({before[0], 0}); 58 | } 59 | } 60 | } 61 | } catch (const libconfig::SettingNotFoundException& snfex) { 62 | Logger::Error("{}: {}", snfex.what(), snfex.getPath()); 63 | return false; 64 | } 65 | return true; 66 | } 67 | 68 | void Formatter::Indent() 69 | { 70 | for (int depth = 0; depth < m_depth; ++depth) { 71 | fmt::print(stdout, m_fmtIndent); 72 | } 73 | } 74 | 75 | void Formatter::PrintRecursive(rapidjson::Value::ConstMemberIterator object) 76 | { 77 | std::string scope = object->name.GetString(); 78 | 79 | 80 | if (object->value.IsObject()) { 81 | if (!scope.compare(0, 3, "DT_")) { 82 | scope.erase(0, 3); 83 | } 84 | Indent(); 85 | fmt::print(stdout, m_fmtTableBegin, scope); 86 | m_depth++; 87 | for (auto it = object->value.MemberBegin(); it != object->value.MemberEnd(); ++it) { 88 | PrintRecursive(it); 89 | } 90 | m_depth--; 91 | Indent(); 92 | fmt::print(stdout, m_fmtTableEnd, scope); 93 | } else if (object->value.IsInt()) { 94 | for (const std::pair& replacements : m_fmtReplaceChars) { 95 | size_t pos = scope.find(replacements.first); 96 | while (pos != std::string::npos) { 97 | if (!replacements.second) { 98 | scope.erase(pos, 1); 99 | pos = scope.find(replacements.first, pos); 100 | } else { 101 | scope[pos] = replacements.second; 102 | pos = scope.find(replacements.first, pos + 1); 103 | } 104 | 105 | } 106 | } 107 | Indent(); 108 | fmt::print(stdout, m_fmtOffset, scope, object->value.GetUint()); 109 | } 110 | } 111 | 112 | void Formatter::Print(const std::string& json, const std::string& label) 113 | { 114 | if (m_bJson) { 115 | puts(json.c_str()); 116 | return; 117 | } 118 | 119 | try { 120 | fmt::print(stdout, m_fmtHeader, label); 121 | } catch(const fmt::v5::format_error& fex) { 122 | Logger::Warn("Header didn't supply {{0}}. Writing without input."); 123 | fmt::print(stdout, m_fmtHeader); 124 | } 125 | 126 | Indent(); 127 | try { 128 | std::time_t t = std::time(nullptr); 129 | fmt::print(stdout, m_fmtTimestamp, *std::localtime(&t), "checkers"); 130 | } catch (const fmt::format_error& fex) { 131 | Logger::Warn("Timestamp format missing or invalid. Skipping."); 132 | } 133 | 134 | rapidjson::Document doc; 135 | doc.Parse(json.c_str()); 136 | for (auto it = doc.MemberBegin(); it != doc.MemberEnd(); ++it) { 137 | PrintRecursive(it); 138 | } 139 | 140 | try { 141 | fmt::print(stdout, m_fmtFooter, label); 142 | } catch(const fmt::v5::format_error& fex) { 143 | Logger::Warn("Footer didn't supply {{0}}. Writing without input."); 144 | fmt::print(stdout, m_fmtFooter); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/formatter.h: -------------------------------------------------------------------------------- 1 | #ifndef __TUXDUMP_FORMATTER_H__ 2 | #define __TUXDUMP_FORMATTER_H__ 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | class Formatter { 9 | public: 10 | bool LoadFormat(const char* fmt); 11 | void Print(const std::string& json, const std::string& label); 12 | private: 13 | void Indent(); 14 | void PrintRecursive(rapidjson::Value::ConstMemberIterator object); 15 | private: 16 | bool m_bJson = true; 17 | int m_depth = 0; 18 | std::string m_fmtTableBegin; 19 | std::string m_fmtTableEnd; 20 | std::string m_fmtIndent; 21 | std::string m_fmtOffset; 22 | std::string m_fmtHeader; 23 | std::string m_fmtFooter; 24 | std::string m_fmtTimestamp; 25 | std::vector> m_fmtReplaceChars; 26 | bool m_fmtRemovePrefix; 27 | }; 28 | 29 | #endif //__TUXDUMP_FORMATTER_H__ 30 | -------------------------------------------------------------------------------- /src/globals.h: -------------------------------------------------------------------------------- 1 | #ifndef __TUXDUMP_GLOBALS_H__ 2 | #define __TUXDUMP_GLOBALS_H__ 3 | #include 4 | #include 5 | 6 | extern TuxProc::Process g_process; 7 | extern libconfig::Config g_cfg; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/logger.h: -------------------------------------------------------------------------------- 1 | #ifndef __TUXDUMP_LOGGER_H__ 2 | #define __TUXDUMP_LOGGER_H__ 3 | #include 4 | 5 | class Logger { 6 | public: 7 | Logger() = delete; 8 | template 9 | static inline void Error(const char* fmt, Targs... args); 10 | template 11 | static inline void Log(const char* fmt, Targs... args); 12 | template 13 | static inline void Print(const char* fmt, Targs... args); 14 | template 15 | static inline void Warn(const char* fmt, Targs... args); 16 | static inline void EOL(); 17 | }; 18 | 19 | template 20 | inline void Logger::Error(const char* fmt, Targs... args) 21 | { 22 | fmt::print(stderr, "[ERR] "); 23 | fmt::print(stderr, fmt, args...); 24 | fmt::print(stderr, "\n"); 25 | } 26 | 27 | template 28 | inline void Logger::Log(const char* fmt, Targs... args) 29 | { 30 | fmt::print(stderr, fmt, args...); 31 | fmt::print(stderr, "\n"); 32 | } 33 | 34 | template 35 | inline void Logger::Print(const char* fmt, Targs... args) 36 | { 37 | fmt::print(stdout, fmt, args...); 38 | } 39 | 40 | template 41 | inline void Logger::Warn(const char* fmt, Targs... args) 42 | { 43 | fmt::print(stderr, "[WARN] "); 44 | fmt::print(stderr, fmt, args...); 45 | fmt::print(stderr, "\n"); 46 | } 47 | 48 | inline void Logger::EOL() 49 | { 50 | fmt::print(stderr, "\n"); 51 | } 52 | 53 | #endif //__TUXDUMP_LOGGER_H__ 54 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "tools/tools.h" 2 | #include "formatter.h" 3 | #include "globals.h" 4 | #include "logger.h" 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | TuxProc::Process g_process; 13 | libconfig::Config g_cfg; 14 | 15 | constexpr const char validTools[][20] = { 16 | "classids", 17 | "netvars", 18 | "signatures" 19 | }; 20 | 21 | static bool ReadSignatureConfig(const char* configFile) 22 | { 23 | try { 24 | g_cfg.readFile(configFile); 25 | } catch (const libconfig::FileIOException& fioex) { 26 | return false; 27 | } catch (const libconfig::ParseException& pex) { 28 | Logger::Error("Parse exception: {}\nFile: {}:{}\n", 29 | pex.getError(), configFile, pex.getLine()); 30 | return false; 31 | } 32 | // Validate config structure 33 | try { 34 | libconfig::Setting& signatures = g_cfg.lookup("signatures"); 35 | for (libconfig::Setting& entry : signatures) { 36 | entry.lookup("pattern"); 37 | entry.lookup("region"); 38 | entry.lookup("offset"); 39 | entry.lookup("extra"); 40 | entry.lookup("relative"); 41 | } 42 | signatures.lookup("dwGetAllClasses"); 43 | signatures.lookup("dwGetAllClasses.offset"); 44 | signatures.lookup("dwGetAllClasses.pattern"); 45 | } catch (const libconfig::SettingNotFoundException& snfex) { 46 | Logger::Error("{}: {}", snfex.what(), snfex.getPath()); 47 | return false; 48 | } 49 | return true; 50 | } 51 | 52 | static void RunTool(const char* cmdTool, Formatter& fmt) 53 | { 54 | if (!strcasecmp(cmdTool, "classids")) { 55 | //run tool classids 56 | } else if (!strcasecmp(cmdTool, "netvars")) { 57 | Tools::DumpNetvars(fmt); 58 | } else if (!strcasecmp(cmdTool, "signatures")) { 59 | Tools::DumpSignatures(fmt); 60 | } 61 | } 62 | 63 | static bool CheckTool(const char* cmdTool) 64 | { 65 | for (size_t i = 0; i < sizeof(validTools)/sizeof(validTools[0]); ++i) { 66 | if (!strcasecmp(validTools[i], cmdTool)) { 67 | return true; 68 | } 69 | } 70 | return false; 71 | } 72 | 73 | static void PrintOption(const char* name, const char* desc = nullptr) 74 | { 75 | if (desc) { 76 | Logger::Log(" {:<15} {:<15}", name, desc); 77 | } else { 78 | Logger::Log(" {:<15}", name); 79 | } 80 | } 81 | 82 | static void PrintHelpFormats() 83 | { 84 | Logger::Log("Available Formats:"); 85 | libconfig::Config cfg; 86 | PrintOption("json"); 87 | 88 | try { 89 | cfg.readFile("formats.cfg"); 90 | } catch (const libconfig::FileIOException& fioex) { 91 | Logger::Error("Failed to open file \"formats.cfg\""); 92 | return; 93 | } catch (const libconfig::ParseException& pex) { 94 | Logger::Error("Parse exception: {}\nFile: {}:{}\n", 95 | pex.getError(), "formats.cfg", pex.getLine()); 96 | return; 97 | } 98 | 99 | try { 100 | libconfig::Setting& formats = cfg.lookup("formats"); 101 | for (const libconfig::Setting& entry : formats) { 102 | PrintOption(entry.getName()); 103 | } 104 | } catch (const libconfig::SettingNotFoundException& snfex) { 105 | Logger::Error("formats.cfg missing formats group"); 106 | } 107 | Logger::EOL(); 108 | } 109 | 110 | static void PrintHelpTools() 111 | { 112 | Logger::Log("Available Tools:"); 113 | PrintOption("classids", "enumerated list of classids"); 114 | PrintOption("netvars", "netvar offsets"); 115 | PrintOption("signatures", "memory addresses defined in config"); 116 | Logger::EOL(); 117 | } 118 | 119 | static void PrintHelpOptions() 120 | { 121 | Logger::Log("Options:"); 122 | PrintOption("-c[filename]", "config file to use"); 123 | PrintOption("-f[format]", "language formatting"); 124 | PrintOption("-h", "this message"); 125 | PrintOption("-p[process]", "name of process to attach"); 126 | Logger::EOL(); 127 | } 128 | 129 | static void PrintHelpAll() 130 | { 131 | Logger::Log("Usage: {} [options] ", PROJECT_NAME); 132 | Logger::Log("{} dumps offsets for the specified executable into different", PROJECT_NAME); 133 | Logger::Log("language formats for use in memory manipulation.\n"); 134 | Logger::Log("Examples:"); 135 | Logger::Log(" {} -fraw -pcsgo_linux64 -ccsgo.cfg signatures (Default)", PROJECT_NAME); 136 | Logger::Log(" {} -fcpp signatures", PROJECT_NAME); 137 | Logger::Log(" {} -fjava netvars\n", PROJECT_NAME); 138 | PrintHelpOptions(); 139 | PrintHelpFormats(); 140 | PrintHelpTools(); 141 | } 142 | 143 | int main(int argc, char* argv[]) 144 | { 145 | if (getuid() != 0) { 146 | Logger::Error("This software requires root privileges to run."); 147 | return 1; 148 | } 149 | const char* cmdConfig = "csgo.cfg"; 150 | const char* cmdFormat = "json"; 151 | const char* cmdProcess = "csgo_linux64"; 152 | const char* cmdTool = "signatures"; 153 | 154 | int c; 155 | opterr = 0; 156 | while ((c = getopt(argc, argv, "c:f:hp:")) != -1) { 157 | switch (c) { 158 | case 'c': 159 | cmdConfig = optarg; 160 | break; 161 | case 'f': 162 | cmdFormat = optarg; 163 | break; 164 | case 'h': 165 | PrintHelpAll(); 166 | exit(0); 167 | case 'p': 168 | cmdProcess = optarg; 169 | break; 170 | case '?': 171 | if (optopt == 'c' || optopt == 'f') { 172 | Logger::Warn("Option -{} requires an argument.", optopt); 173 | } else { 174 | Logger::Warn("Unknown option '-{}'", optopt); 175 | } 176 | break; 177 | default: 178 | abort(); 179 | } 180 | } 181 | 182 | if (argc - optind == 1) { 183 | cmdTool = argv[optind]; 184 | } else if (optind != argc) { 185 | Logger::Error("Extra arguments"); 186 | return 2; 187 | } 188 | 189 | if (!ReadSignatureConfig(cmdConfig)) { 190 | Logger::Error("Failed to read signatures config file \"{}\"", cmdConfig); 191 | return 3; 192 | } 193 | 194 | if (!CheckTool(cmdTool)) { 195 | Logger::Error("Unknown tool \"{}\"", cmdTool); 196 | PrintHelpTools(); 197 | return 5; 198 | } 199 | 200 | if (!g_process.Attach(cmdProcess)) { 201 | Logger::Error("Failed to find process \"{}\"", cmdProcess); 202 | Logger::Error("Please ensure the process is running"); 203 | return 6; 204 | } 205 | 206 | if (!g_process.ParseMaps()) { 207 | Logger::Error("Failed to parse maps file"); 208 | return 7; 209 | } 210 | 211 | Formatter fmt; 212 | 213 | if (!fmt.LoadFormat(cmdFormat)) { 214 | Logger::Error("Failed to load format \"{}\"", cmdFormat); 215 | return 8; 216 | } 217 | 218 | Logger::Log("Options:"); 219 | PrintOption("Config:", cmdConfig); 220 | PrintOption("Format:", cmdFormat); 221 | PrintOption("Process:", cmdProcess); 222 | PrintOption("Tool:", cmdTool); 223 | 224 | RunTool(cmdTool, fmt); 225 | 226 | return 0; 227 | } 228 | -------------------------------------------------------------------------------- /src/tools/netvars.cpp: -------------------------------------------------------------------------------- 1 | #include "tools.h" 2 | #include "../globals.h" 3 | 4 | #include 5 | #include 6 | 7 | class ClientClass { 8 | public: 9 | uintptr_t m_pCreateFn; 10 | uintptr_t m_pCreateEventF; 11 | uintptr_t m_pNetworkName; 12 | uintptr_t m_pRecvTable; 13 | uintptr_t m_pNext; 14 | int m_ClassID; 15 | }; 16 | 17 | enum class SendPropType : int { 18 | DPT_Int = 0, 19 | DPT_Float, 20 | DPT_Vector, 21 | DPT_VectorXY, 22 | DPT_String, 23 | DPT_Array, 24 | DPT_DataTable, 25 | DPT_Int64, 26 | DPT_NUMSendPropTypes 27 | }; 28 | 29 | class RecvProp { 30 | public: 31 | uintptr_t m_pVarName; // const char* 32 | SendPropType m_RecvType; 33 | int m_Flags; 34 | int m_StringBufferSize; 35 | bool m_bInsideArray; 36 | private: 37 | uint8_t pad0[3]; 38 | public: 39 | uintptr_t m_pExtraData; 40 | uintptr_t m_pArrayProp; 41 | uintptr_t m_ArrayLengthProxy; 42 | uintptr_t m_ProxyFn; 43 | uintptr_t m_DataTableProxyFn; 44 | uintptr_t m_pDataTable; 45 | unsigned int m_Offset; 46 | int m_ElementStride; 47 | unsigned int m_nElements; 48 | private: 49 | uint8_t pad1[4]; 50 | public: 51 | uintptr_t m_pParentArrayPropName; 52 | }; 53 | 54 | class RecvTable { 55 | public: 56 | uintptr_t m_pProps; 57 | unsigned int m_nProps; 58 | private: 59 | uint8_t pad0[4]; 60 | public: 61 | uintptr_t m_pDecoder; 62 | uintptr_t m_pNetTableName; 63 | bool m_bInitialized; 64 | }; 65 | 66 | static uintptr_t GetClassHead() 67 | { 68 | libconfig::Setting& entry = g_cfg.lookup("signatures.dwGetAllClasses"); 69 | const char* region = entry.lookup("region"); 70 | const char* pattern = entry.lookup("pattern"); 71 | libconfig::Setting& offset = entry.lookup("offset"); 72 | uintptr_t addr = g_process.FindPattern(region, pattern, offset[0]); 73 | addr = g_process.GetCallAddress(addr); 74 | for (int i = 1; i < offset.getLength(); ++i) { 75 | addr = g_process.Read(addr + static_cast(offset[i])); 76 | } 77 | return addr; 78 | } 79 | 80 | static void DumpNetvarTable(RecvTable table, const char* tableName, int depth, 81 | rapidjson::PrettyWriter& writer) 82 | { 83 | RecvProp props[1024]; 84 | char propName[64]; 85 | if (g_process.ReadMemory(table.m_pProps, props, sizeof(RecvProp) * table.m_nProps) < 1) { 86 | return; 87 | } 88 | 89 | // Skip empty classes 90 | g_process.ReadMemory(props[0].m_pVarName, propName, sizeof(propName)); 91 | if (table.m_nProps == 1) { 92 | if (!strcmp(propName, "baseclass")) { 93 | return; 94 | } 95 | } 96 | 97 | if (isdigit(propName[0])) { 98 | return; 99 | } 100 | 101 | writer.Key(tableName); 102 | writer.StartObject(); 103 | for (size_t i = 0; i < table.m_nProps; ++i) { 104 | RecvProp& prop = props[i]; 105 | if (g_process.ReadMemory(prop.m_pVarName, propName, sizeof(propName)) < 1) { 106 | continue; 107 | } 108 | 109 | if (!strcmp(propName, "baseclass")) { 110 | continue; 111 | } 112 | 113 | if (isdigit(propName[0]) || prop.m_RecvType == SendPropType::DPT_Array) { 114 | continue; 115 | } 116 | 117 | if (prop.m_RecvType == SendPropType::DPT_DataTable && prop.m_pDataTable) { 118 | if (prop.m_Offset > 0) { 119 | writer.Key(propName); 120 | writer.Uint(prop.m_Offset); 121 | } 122 | auto nextTable = g_process.Read(prop.m_pDataTable); 123 | char nextTableName[64]; 124 | if (g_process.ReadMemory(nextTable.m_pNetTableName, nextTableName, sizeof(nextTableName)) < 1) { 125 | continue; 126 | } 127 | DumpNetvarTable(nextTable, nextTableName, depth + 1, writer); 128 | } else { 129 | writer.Key(propName); 130 | writer.Uint(prop.m_Offset); 131 | } 132 | } 133 | writer.EndObject(); 134 | } 135 | 136 | void Tools::DumpNetvars(Formatter& fmt) 137 | { 138 | rapidjson::StringBuffer data; 139 | rapidjson::PrettyWriter writer(data); 140 | writer.StartObject(); 141 | 142 | char tableName[64]; 143 | ClientClass cc; 144 | cc.m_pNext = GetClassHead(); 145 | do { 146 | cc = g_process.Read(cc.m_pNext); 147 | if (cc.m_pRecvTable) { 148 | auto table = g_process.Read(cc.m_pRecvTable); 149 | g_process.ReadMemory(cc.m_pNetworkName, tableName, sizeof(tableName)); 150 | DumpNetvarTable(table, tableName, 1, writer); 151 | } 152 | } while (cc.m_pNext); 153 | writer.EndObject(); 154 | 155 | fmt.Print(data.GetString(), "netvars"); 156 | } 157 | 158 | -------------------------------------------------------------------------------- /src/tools/signatures.cpp: -------------------------------------------------------------------------------- 1 | #include "tools.h" 2 | #include "../globals.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | void Tools::DumpSignatures(Formatter& fmt) 9 | { 10 | rapidjson::StringBuffer data; 11 | rapidjson::PrettyWriter writer(data); 12 | writer.StartObject(); 13 | 14 | libconfig::Setting& signatures = g_cfg.lookup("signatures"); 15 | for (const libconfig::Setting& entry : signatures) { 16 | const char *region = entry.lookup("region"); 17 | const char *pattern = entry.lookup("pattern"); 18 | int extra = entry.lookup("extra"); 19 | int relative = entry.lookup("relative"); 20 | libconfig::Setting& offset = entry.lookup("offset"); 21 | 22 | TuxProc::Region* currentRegion = g_process.GetRegion(region); 23 | if (region) { 24 | uintptr_t addr = g_process.FindPattern(currentRegion, pattern, offset[0]); 25 | uintptr_t startAddr = 0; 26 | if (relative) { 27 | startAddr = currentRegion->GetStartAddress(); 28 | addr = g_process.GetCallAddress(addr); 29 | for (int i = 1; i < offset.getLength(); ++i) { 30 | addr = g_process.Read(addr + static_cast(offset[i])); 31 | } 32 | } else { 33 | addr = g_process.Read(addr); 34 | } 35 | writer.Key(entry.getName()); 36 | writer.Uint(addr ? addr + extra - startAddr : 0); 37 | } 38 | } 39 | writer.EndObject(); 40 | fmt.Print(data.GetString(), "signatures"); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/tools/tools.cpp: -------------------------------------------------------------------------------- 1 | #include "tools.h" 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/tools/tools.h: -------------------------------------------------------------------------------- 1 | #ifndef __TUXDUMP_TOOLS_H__ 2 | #define __TUXDUMP_TOOLS_H__ 3 | #include "../formatter.h" 4 | 5 | namespace Tools { 6 | void DumpNetvars(Formatter& fmt); 7 | void DumpSignatures(Formatter& fmt); 8 | } 9 | 10 | #endif //__TUXDUMP_TOOLS_H__ 11 | --------------------------------------------------------------------------------