Public API

RapidJSON error handling

RAPIDJSON_ERROR_CHARTYPE char

Character type of error messages.

The default character type is char. On Windows, user can define this macro as TCHAR for supporting both unicode/non-unicode settings.

RAPIDJSON_ERROR_STRING(x)
x

Macro for converting string literial to RAPIDJSON_ERROR_CHARTYPE[].

By default this conversion macro does nothing. On Windows, user can define this macro as _T(x) for supporting both unicode/non-unicode settings.

RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode,offset)
RAPIDJSON_MULTILINEMACRO_BEGIN
RAPIDJSON_ASSERT(!HasParseError()); /* Error can only be assigned once */
SetParseError(parseErrorCode, offset);
RAPIDJSON_MULTILINEMACRO_END

Macro to indicate a parse error.

Parameters

parseErrorCode - rapidjson::ParseErrorCode of the error

offset - position of the error in JSON input (size_t)

This macros can be used as a customization point for the internal error handling mechanism of RapidJSON.

A common usage model is to throw an exception instead of requiring the caller to explicitly check the rapidjson::GenericReader::Parse's return value:

#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode,offset) 
throw ParseException(parseErrorCode, #parseErrorCode, offset) #include <stdexcept> // std::runtime_error #include "rapidjson/error/error.h" // rapidjson::ParseResult struct ParseException : std::runtime_error, rapidjson::ParseResult { ParseException(rapidjson::ParseErrorCode code, const char* msg, size_t offset) : std::runtime_error(msg), ParseResult(code, offset) {} }; #include "rapidjson/reader.h"
See
RAPIDJSON_PARSE_ERROR, rapidjson::GenericReader::Parse

RAPIDJSON_PARSE_ERROR(parseErrorCode,offset)

(Internal) macro to indicate and handle a parse error.

Parameters

parseErrorCode - rapidjson::ParseErrorCode of the error

offset - position of the error in JSON input (size_t)

Invokes RAPIDJSON_PARSE_ERROR_NORETURN and stops the parsing.
See
RAPIDJSON_PARSE_ERROR_NORETURN

RapidJSON configuration

Configuration macros for library features.

Some RapidJSON features are configurable to adapt the library to a wide variety of platforms, environments and usage scenarios. Most of the features can be configured in terms of overridden or predefined preprocessor macros at compile-time.

Some additional customization is available in the RapidJSON error handling APIs.

Note
These macros should be given on the compiler command-line (where applicable) to avoid inconsistent values when compiling different translation units of a single application.

RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY (64 * 1024)

User-defined kDefaultChunkCapacity definition.

User can define this as any size that is a power of 2.

RAPIDJSON_DEFAULT_ALLOCATOR MemoryPoolAllocator<CrtAllocator>

Allows to choose default allocator.

User can define this to use CrtAllocator or MemoryPoolAllocator.

RAPIDJSON_DEFAULT_STACK_ALLOCATOR CrtAllocator

Allows to choose default stack allocator for Document.

User can define this to use CrtAllocator or MemoryPoolAllocator.

RAPIDJSON_VALUE_DEFAULT_OBJECT_CAPACITY 16

User defined kDefaultObjectCapacity value.

User can define this as any natural number.

RAPIDJSON_VALUE_DEFAULT_ARRAY_CAPACITY 16

User defined kDefaultArrayCapacity value.

User can define this as any natural number.

RAPIDJSON_MAJOR_VERSION 1

Major version of RapidJSON in integer.

RAPIDJSON_MINOR_VERSION 1

Minor version of RapidJSON in integer.

RAPIDJSON_PATCH_VERSION 0

Patch version of RapidJSON in integer.

RAPIDJSON_VERSION_STRING RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION)

Version of RapidJSON in "<major>.<minor>.<patch>" string format.

RAPIDJSON_NAMESPACE rapidjson

provide custom rapidjson namespace

In order to avoid symbol clashes and/or "One Definition Rule" errors between multiple inclusions of (different versions of) RapidJSON in a single binary, users can customize the name of the main RapidJSON namespace.

In case of a single nesting level, defining RAPIDJSON_NAMESPACE to a custom name (e.g. MyRapidJSON) is sufficient. If multiple levels are needed, both RAPIDJSON_NAMESPACE_BEGIN and RAPIDJSON_NAMESPACE_END need to be defined as well:

// in some .cpp file
#define RAPIDJSON_NAMESPACE my::rapidjson
#define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapidjson {
#define RAPIDJSON_NAMESPACE_END   } }
#include "rapidjson/..."
See
rapidjson

RAPIDJSON_HAS_STDSTRING

Enable RapidJSON support for std::string.

By defining this preprocessor symbol to 1, several convenience functions for using rapidjson::GenericValue with std::string are enabled, especially for construction and comparison.

Mentioned in:

Changelog / Added

Features / DOM (Document)

Examples / serialize.cpp

RAPIDJSON_USE_MEMBERSMAP

Enable RapidJSON support for object members handling in a std::multimap.

By defining this preprocessor symbol to 1, rapidjson::GenericValue object members are stored in a std::multimap for faster lookup and deletion times, a trade off with a slightly slower insertion time and a small object allocat(or)ed memory overhead.

RAPIDJSON_NO_INT64DEFINE

Use external 64-bit integer types.

RapidJSON requires the 64-bit integer types int64_t and uint64_t types to be available at global scope.

If users have their own definition, define RAPIDJSON_NO_INT64DEFINE to prevent RapidJSON from defining its own types.

RAPIDJSON_ENDIAN

Endianness of the machine.

GCC 4.6 provided macro for detecting endianness of the target machine. But other compilers may not have this. User can define RAPIDJSON_ENDIAN to either RAPIDJSON_LITTLEENDIAN or RAPIDJSON_BIGENDIAN.

Default detection implemented with reference to

RAPIDJSON_ALIGN(x)
(((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))

Data alignment of the machine.

Parameters

x - pointer to align

Some machines require strict data alignment. The default is 8 bytes. User can customize by defining the RAPIDJSON_ALIGN function macro.

RAPIDJSON_48BITPOINTER_OPTIMIZATION 0

Use only lower 48-bit address for some pointers.

This optimization uses the fact that current X86-64 architecture only implement lower 48-bit virtual address. The higher 16-bit can be used for storing other data. GenericValue uses this optimization to reduce its size form 24 bytes to 16 bytes in 64-bit architecture.

RAPIDJSON_SIMD

Enable SSE2/SSE4.2/Neon optimization.

RapidJSON supports optimized implementations for some parsing operations based on the SSE2, SSE4.2 or NEon SIMD extensions on modern Intel or ARM compatible processors.

To enable these optimizations, three different symbols can be defined;

// Enable SSE2 optimization.
#define RAPIDJSON_SSE2

// Enable SSE4.2 optimization.
#define RAPIDJSON_SSE42

Enable ARM Neon optimization. #define RAPIDJSON_NEON

RAPIDJSON_SSE42 takes precedence over SSE2, if both are defined.

If any of these symbols is defined, RapidJSON defines the macro RAPIDJSON_SIMD to indicate the availability of the optimized code.

RAPIDJSON_NO_SIZETYPEDEFINE

User-provided SizeType definition.

In order to avoid using 32-bit size types for indexing strings and arrays, define this preprocessor symbol and provide the type rapidjson::SizeType before including RapidJSON:

#define RAPIDJSON_NO_SIZETYPEDEFINE
namespace rapidjson { typedef ::std::size_t SizeType; }
#include "rapidjson/..."
See
rapidjson::SizeType

RAPIDJSON_ASSERT(x)
assert(x)

Assertion.

By default, rapidjson uses C assert() for internal assertions. User can override it by defining RAPIDJSON_ASSERT(x) macro.

Note
Parsing errors are handled and can be customized by the RapidJSON error handling APIs.

RAPIDJSON_LIKELY(x)
(x)

Compiler branching hint for expression with high probability to be true.

Parameters

x - Boolean expression likely to be true.

RAPIDJSON_UNLIKELY(x)
(x)

Compiler branching hint for expression with low probability to be true.

Parameters

x - Boolean expression unlikely to be true.

RAPIDJSON_NOEXCEPT_ASSERT(x)
RAPIDJSON_ASSERT(x)

Assertion (in non-throwing contexts).

Some functions provide a noexcept guarantee, if the compiler supports it. In these cases, the RAPIDJSON_ASSERT macro cannot be overridden to throw an exception. This macro adds a separate customization point for such cases.

Defaults to C assert() (as RAPIDJSON_ASSERT), if noexcept is supported, and to RAPIDJSON_ASSERT otherwise.

RAPIDJSON_PARSE_DEFAULT_FLAGS kParseNoFlags

User-defined kParseDefaultFlags definition.

User can define this as any ParseFlag combinations.

Mentioned in:

Dom / Parsing {#Parsing}

RAPIDJSON_VALIDATE_DEFAULT_FLAGS kValidateNoFlags

User-defined kValidateDefaultFlags definition.

User can define this as any ValidateFlag combinations.

RAPIDJSON_WRITE_DEFAULT_FLAGS kWriteNoFlags

User-defined kWriteDefaultFlags definition.

User can define this as any WriteFlag combinations.

Mentioned in:

Sax / Template {#WriterTemplate}

Namespaces

rapidjsonmain RapidJSON namespace

Structures

imaxdiv_t

Functions

imaxdiv

Defines

Defines (encodedstream.h)

RAPIDJSON_ENCODINGS_FUNC(x)
UTF8<Ch>::x, UTF16LE<Ch>::x, UTF16BE<Ch>::x, UTF32LE<Ch>::x, UTF32BE<Ch>::x

Defines (encodings.h)

RAPIDJSON_COPY()
c = is.Take(); *codepoint = (*codepoint << 6) | (static_cast<unsigned char>(c) & 0x3Fu)

RAPIDJSON_TRANS(mask)
result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)

RAPIDJSON_TAIL()
RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x70)

Defines (clzll.h)

RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll

Defines (regex.h)

RAPIDJSON_REGEX_VERBOSE 0

Defines (inttypes.h)

PRId8 "d"

PRIi8 "i"

PRIdLEAST8 "d"

PRIiLEAST8 "i"

PRIdFAST8 "d"

PRIiFAST8 "i"

PRId16 "hd"

PRIi16 "hi"

PRIdLEAST16 "hd"

PRIiLEAST16 "hi"

PRIdFAST16 "hd"

PRIiFAST16 "hi"

PRId32 "I32d"

PRIi32 "I32i"

PRIdLEAST32 "I32d"

PRIiLEAST32 "I32i"

PRIdFAST32 "I32d"

PRIiFAST32 "I32i"

PRId64 "I64d"

Mentioned in:

PRIi64 "I64i"

PRIdLEAST64 "I64d"

PRIiLEAST64 "I64i"

PRIdFAST64 "I64d"

PRIiFAST64 "I64i"

PRIdMAX "I64d"

PRIiMAX "I64i"

PRIdPTR "Id"

PRIiPTR "Ii"

PRIo8 "o"

PRIu8 "u"

PRIx8 "x"

PRIX8 "X"

PRIoLEAST8 "o"

PRIuLEAST8 "u"

PRIxLEAST8 "x"

PRIXLEAST8 "X"

PRIoFAST8 "o"

PRIuFAST8 "u"

PRIxFAST8 "x"

PRIXFAST8 "X"

PRIo16 "ho"

PRIu16 "hu"

PRIx16 "hx"

PRIX16 "hX"

PRIoLEAST16 "ho"

PRIuLEAST16 "hu"

PRIxLEAST16 "hx"

PRIXLEAST16 "hX"

PRIoFAST16 "ho"

PRIuFAST16 "hu"

PRIxFAST16 "hx"

PRIXFAST16 "hX"

PRIo32 "I32o"

PRIu32 "I32u"

PRIx32 "I32x"

PRIX32 "I32X"

PRIoLEAST32 "I32o"

PRIuLEAST32 "I32u"

PRIxLEAST32 "I32x"

PRIXLEAST32 "I32X"

PRIoFAST32 "I32o"

PRIuFAST32 "I32u"

PRIxFAST32 "I32x"

PRIXFAST32 "I32X"

PRIo64 "I64o"

PRIu64 "I64u"

Mentioned in:

PRIx64 "I64x"

PRIX64 "I64X"

PRIoLEAST64 "I64o"

PRIuLEAST64 "I64u"

PRIxLEAST64 "I64x"

PRIXLEAST64 "I64X"

PRIoFAST64 "I64o"

PRIuFAST64 "I64u"

PRIxFAST64 "I64x"

PRIXFAST64 "I64X"

PRIoMAX "I64o"

PRIuMAX "I64u"

PRIxMAX "I64x"

PRIXMAX "I64X"

PRIoPTR "Io"

PRIuPTR "Iu"

PRIxPTR "Ix"

PRIXPTR "IX"

SCNd8 "d"

SCNi8 "i"

SCNdLEAST8 "d"

SCNiLEAST8 "i"

SCNdFAST8 "d"

SCNiFAST8 "i"

SCNd16 "hd"

SCNi16 "hi"

SCNdLEAST16 "hd"

SCNiLEAST16 "hi"

SCNdFAST16 "hd"

SCNiFAST16 "hi"

SCNd32 "ld"

SCNi32 "li"

SCNdLEAST32 "ld"

SCNiLEAST32 "li"

SCNdFAST32 "ld"

SCNiFAST32 "li"

SCNd64 "I64d"

SCNi64 "I64i"

SCNdLEAST64 "I64d"

SCNiLEAST64 "I64i"

SCNdFAST64 "I64d"

SCNiFAST64 "I64i"

SCNdMAX "I64d"

SCNiMAX "I64i"

SCNdPTR "ld"

SCNiPTR "li"

SCNo8 "o"

SCNu8 "u"

SCNx8 "x"

SCNX8 "X"

SCNoLEAST8 "o"

SCNuLEAST8 "u"

SCNxLEAST8 "x"

SCNXLEAST8 "X"

SCNoFAST8 "o"

SCNuFAST8 "u"

SCNxFAST8 "x"

SCNXFAST8 "X"

SCNo16 "ho"

SCNu16 "hu"

SCNx16 "hx"

SCNX16 "hX"

SCNoLEAST16 "ho"

SCNuLEAST16 "hu"

SCNxLEAST16 "hx"

SCNXLEAST16 "hX"

SCNoFAST16 "ho"

SCNuFAST16 "hu"

SCNxFAST16 "hx"

SCNXFAST16 "hX"

SCNo32 "lo"

SCNu32 "lu"

SCNx32 "lx"

SCNX32 "lX"

SCNoLEAST32 "lo"

SCNuLEAST32 "lu"

SCNxLEAST32 "lx"

SCNXLEAST32 "lX"

SCNoFAST32 "lo"

SCNuFAST32 "lu"

SCNxFAST32 "lx"

SCNXFAST32 "lX"

SCNo64 "I64o"

SCNu64 "I64u"

SCNx64 "I64x"

SCNX64 "I64X"

SCNoLEAST64 "I64o"

SCNuLEAST64 "I64u"

SCNxLEAST64 "I64x"

SCNXLEAST64 "I64X"

SCNoFAST64 "I64o"

SCNuFAST64 "I64u"

SCNxFAST64 "I64x"

SCNXFAST64 "I64X"

SCNoMAX "I64o"

SCNuMAX "I64u"

SCNxMAX "I64x"

SCNXMAX "I64X"

SCNoPTR "lo"

SCNuPTR "lu"

SCNxPTR "lx"

SCNXPTR "lX"

imaxabs _abs64

strtoimax _strtoi64

strtoumax _strtoui64

wcstoimax _wcstoi64

wcstoumax _wcstoui64

Defines (stdint.h)

_W64

INT8_MIN ((int8_t)_I8_MIN)

INT8_MAX _I8_MAX

INT16_MIN ((int16_t)_I16_MIN)

INT16_MAX _I16_MAX

INT32_MIN ((int32_t)_I32_MIN)

INT32_MAX _I32_MAX

INT64_MIN ((int64_t)_I64_MIN)

INT64_MAX _I64_MAX

UINT8_MAX _UI8_MAX

UINT16_MAX _UI16_MAX

UINT32_MAX _UI32_MAX

UINT64_MAX _UI64_MAX

INT_LEAST8_MIN INT8_MIN

INT_LEAST8_MAX INT8_MAX

INT_LEAST16_MIN INT16_MIN

INT_LEAST16_MAX INT16_MAX

INT_LEAST32_MIN INT32_MIN

INT_LEAST32_MAX INT32_MAX

INT_LEAST64_MIN INT64_MIN

INT_LEAST64_MAX INT64_MAX

UINT_LEAST8_MAX UINT8_MAX

UINT_LEAST16_MAX UINT16_MAX

UINT_LEAST32_MAX UINT32_MAX

UINT_LEAST64_MAX UINT64_MAX

INT_FAST8_MIN INT8_MIN

INT_FAST8_MAX INT8_MAX

INT_FAST16_MIN INT16_MIN

INT_FAST16_MAX INT16_MAX

INT_FAST32_MIN INT32_MIN

INT_FAST32_MAX INT32_MAX

INT_FAST64_MIN INT64_MIN

INT_FAST64_MAX INT64_MAX

UINT_FAST8_MAX UINT8_MAX

UINT_FAST16_MAX UINT16_MAX

UINT_FAST32_MAX UINT32_MAX

UINT_FAST64_MAX UINT64_MAX

INTPTR_MIN INT32_MIN

INTPTR_MAX INT32_MAX

UINTPTR_MAX UINT32_MAX

INTMAX_MIN INT64_MIN

INTMAX_MAX INT64_MAX

UINTMAX_MAX UINT64_MAX

PTRDIFF_MIN _I32_MIN

PTRDIFF_MAX _I32_MAX

SIG_ATOMIC_MIN INT_MIN

SIG_ATOMIC_MAX INT_MAX

SIZE_MAX _UI32_MAX

WCHAR_MIN 0

WCHAR_MAX _UI16_MAX

WINT_MIN 0

WINT_MAX _UI16_MAX

INT8_C(val)
val##i8

INT16_C(val)
val##i16

INT32_C(val)
val##i32

INT64_C(val)
val##i64

UINT8_C(val)
val##ui8

UINT16_C(val)
val##ui16

UINT32_C(val)
val##ui32

UINT64_C(val)
val##ui64

INTMAX_C INT64_C

UINTMAX_C UINT64_C

Defines (rapidjson.h)

RAPIDJSON_LITTLEENDIAN 0

Little endian machine.

RAPIDJSON_BIGENDIAN 1

Big endian machine.

RAPIDJSON_64BIT 0

Whether using 64-bit architecture.

RAPIDJSON_UINT64_C2(high32,low32)
((static_cast<uint64_t>(high32) << 32) | static_cast<uint64_t>(low32))

Construct a 64-bit literal by a pair of 32-bit integer.

64-bit literal with or without ULL suffix is prone to compiler warnings. UINT64_C() is C macro which cause compilation problems. Use this macro to define 64-bit constants by a pair of 32-bit integer.

RAPIDJSON_SETPOINTER(type,p,x)
(p = (x))

RAPIDJSON_GETPOINTER(type,p)
(p)

RAPIDJSON_STATIC_ASSERT(x)

(Internal) macro to check for conditions at compile-time

Parameters

x - compile-time condition

RAPIDJSON_MALLOC(size)
std::malloc(size)

! customization point for global malloc

RAPIDJSON_REALLOC(ptr,new_size)
std::realloc(ptr, new_size)

! customization point for global realloc

RAPIDJSON_FREE(ptr)
std::free(ptr)

! customization point for global free

RAPIDJSON_NEW(TypeName)
new TypeName

! customization point for global new

RAPIDJSON_DELETE(x)
delete x

! customization point for global delete

Defines (schema.h)

RAPIDJSON_SCHEMA_USE_INTERNALREGEX 1

Mentioned in:

RAPIDJSON_SCHEMA_USE_STDREGEX 0

Mentioned in:

RAPIDJSON_SCHEMA_HAS_REGEX 1

RAPIDJSON_SCHEMA_VERBOSE 0

RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword)

RAPIDJSON_INVALID_KEYWORD_RETURN(code)
RAPIDJSON_MULTILINEMACRO_BEGIN
context.invalidCode = code;
context.invalidKeyword = SchemaType::GetValidateErrorKeyword(code).GetString();
RAPIDJSON_INVALID_KEYWORD_VERBOSE(context.invalidKeyword);
return false;
RAPIDJSON_MULTILINEMACRO_END

RAPIDJSON_STRING_(name,...)
static const ValueType& Get##name##String() {
static const Ch s[] = { __VA_ARGS__, '\0' };
static const ValueType v(s, static_cast<SizeType>(sizeof(s) / sizeof(Ch) - 1));
return v;
}

RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_()

RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method,arg1)
if (!valid_) return false;
if ((!BeginValue() && !GetContinueOnErrors()) || (!CurrentSchema().method arg1 && !GetContinueOnErrors())) {
RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_();
return valid_ = false;
}

RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method,arg2)
for (Context* context = schemaStack_.template Bottom<Context>(); context != schemaStack_.template End<Context>(); context++) {
if (context->hasher)
static_cast<HasherType*>(context->hasher)->method arg2;
if (context->validators)
for (SizeType i_ = 0; i_ < context->validatorCount; i_++)
static_cast<GenericSchemaValidator*>(context->validators[i_])->method arg2;
if (context->patternPropertiesValidators)
for (SizeType i_ = 0; i_ < context->patternPropertiesValidatorCount; i_++)
static_cast<GenericSchemaValidator*>(context->patternPropertiesValidators[i_])->method arg2;
}

RAPIDJSON_SCHEMA_HANDLE_END_(method,arg2)
valid_ = (EndValue() || GetContinueOnErrors()) && (!outputHandler_ || outputHandler_->method arg2);
return valid_;

RAPIDJSON_SCHEMA_HANDLE_VALUE_(method,arg1,arg2)
RAPIDJSON_SCHEMA_HANDLE_BEGIN_ (method, arg1);
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2);
RAPIDJSON_SCHEMA_HANDLE_END_ (method, arg2)

Defines (writer.h)

Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

Typedefs

Typedefs (stdint.h)

typedef signed char int8_t

typedef signed short int16_t

typedef signed int int32_t

typedef unsigned char uint8_t

typedef unsigned short uint16_t

typedef unsigned int uint32_t

Mentioned in:

typedef signed __int64 int64_t

Mentioned in:

typedef unsigned __int64 uint64_t

Mentioned in:

typedef int8_t int_least8_t

typedef int16_t int_least16_t

typedef int32_t int_least32_t

typedef int64_t int_least64_t

typedef uint8_t uint_least8_t

typedef uint16_t uint_least16_t

typedef uint32_t uint_least32_t

typedef uint64_t uint_least64_t

typedef int8_t int_fast8_t

typedef int16_t int_fast16_t

typedef int32_t int_fast32_t

typedef int64_t int_fast64_t

typedef uint8_t uint_fast8_t

typedef uint16_t uint_fast16_t

typedef uint32_t uint_fast32_t

typedef uint64_t uint_fast64_t

typedef _W64 signed int intptr_t

typedef _W64 unsigned int uintptr_t

typedef int64_t intmax_t

typedef uint64_t uintmax_t






Add Discussion as Guest

Log in