error.h
Engine/source/persistence/rapidjson/error/error.h
Classes:
Result of parsing (wraps ParseErrorCode)
Public Defines
RAPIDJSON_ERROR_CHARTYPE() char
Character type of error messages.
Macro for converting string literial to RAPIDJSON_ERROR_CHARTYPE[].
Public Enumerations
ParseErrorCode { kParseErrorNone = 0 kParseErrorDocumentEmpty kParseErrorDocumentRootNotSingular kParseErrorValueInvalid kParseErrorObjectMissName kParseErrorObjectMissColon kParseErrorObjectMissCommaOrCurlyBracket kParseErrorArrayMissCommaOrSquareBracket kParseErrorStringUnicodeEscapeInvalidHex kParseErrorStringUnicodeSurrogateInvalid kParseErrorStringEscapeInvalid kParseErrorStringMissQuotationMark kParseErrorStringInvalidEncoding kParseErrorNumberTooBig kParseErrorNumberMissFraction kParseErrorNumberMissExponent kParseErrorTermination kParseErrorUnspecificSyntaxError }
Error code of parsing.
Public Typedefs
GetParseErrorFunc )(ParseErrorCode)
Function pointer type of GetParseError().
Detailed Description
Public Defines
RAPIDJSON_ERROR_CHARTYPE() char
Character type of error messages.
The default character type is
char. On Windows, user can define this macro as
TCHARfor 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.
Public Enumerations
ParseErrorCode
Enumerator
- kParseErrorNone = 0
No error.
- kParseErrorDocumentEmpty
The document is empty.
- kParseErrorDocumentRootNotSingular
The document root must not follow by other values.
- kParseErrorValueInvalid
Invalid value.
- kParseErrorObjectMissName
Missing a name for object member.
- kParseErrorObjectMissColon
Missing a colon after a name of object member.
- kParseErrorObjectMissCommaOrCurlyBracket
Missing a comma or '}' after an object member.
- kParseErrorArrayMissCommaOrSquareBracket
Missing a comma or ']' after an array element.
- kParseErrorStringUnicodeEscapeInvalidHex
Incorrect hex digit after \u escape in string.
- kParseErrorStringUnicodeSurrogateInvalid
The surrogate pair in string is invalid.
- kParseErrorStringEscapeInvalid
Invalid escape character in string.
- kParseErrorStringMissQuotationMark
Missing a closing quotation mark in string.
- kParseErrorStringInvalidEncoding
Invalid encoding in string.
- kParseErrorNumberTooBig
Number too big to be stored in double.
- kParseErrorNumberMissFraction
Miss fraction part in number.
- kParseErrorNumberMissExponent
Miss exponent in number.
- kParseErrorTermination
Parsing was terminated.
- kParseErrorUnspecificSyntaxError
Unspecific syntax error.
Error code of parsing.
Public Typedefs
typedef const RAPIDJSON_ERROR_CHARTYPE *(* GetParseErrorFunc )(ParseErrorCode)
Function pointer type of GetParseError().
This is the prototype for
GetParseError_X(), where
Xis a locale. User can dynamically change locale in runtime, e.g.:
GetParseErrorFunc GetParseError = GetParseError_En; // or whatever const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode());
1 2// Tencent is pleased to support the open source community by making RapidJSON available. 3// 4// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 5// 6// Licensed under the MIT License (the "License"); you may not use this file except 7// in compliance with the License. You may obtain a copy of the License at 8// 9// http://opensource.org/licenses/MIT 10// 11// Unless required by applicable law or agreed to in writing, software distributed 12// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 13// CONDITIONS OF ANY KIND, either express or implied. See the License for the 14// specific language governing permissions and limitations under the License. 15 16#ifndef RAPIDJSON_ERROR_ERROR_H_ 17#define RAPIDJSON_ERROR_ERROR_H_ 18 19#include "../rapidjson.h" 20 21#ifdef __clang__ 22RAPIDJSON_DIAG_PUSH 23RAPIDJSON_DIAG_OFF(padded) 24#endif 25 26/*! \file error.h */ 27 28/*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */ 29 30/////////////////////////////////////////////////////////////////////////////// 31// RAPIDJSON_ERROR_CHARTYPE 32 33//! Character type of error messages. 34/*! \ingroup RAPIDJSON_ERRORS 35 The default character type is \c char. 36 On Windows, user can define this macro as \c TCHAR for supporting both 37 unicode/non-unicode settings. 38*/ 39#ifndef RAPIDJSON_ERROR_CHARTYPE 40#define RAPIDJSON_ERROR_CHARTYPE char 41#endif 42 43/////////////////////////////////////////////////////////////////////////////// 44// RAPIDJSON_ERROR_STRING 45 46//! Macro for converting string literial to \ref RAPIDJSON_ERROR_CHARTYPE[]. 47/*! \ingroup RAPIDJSON_ERRORS 48 By default this conversion macro does nothing. 49 On Windows, user can define this macro as \c _T(x) for supporting both 50 unicode/non-unicode settings. 51*/ 52#ifndef RAPIDJSON_ERROR_STRING 53#define RAPIDJSON_ERROR_STRING(x) x 54#endif 55 56RAPIDJSON_NAMESPACE_BEGIN 57 58/////////////////////////////////////////////////////////////////////////////// 59// ParseErrorCode 60 61//! Error code of parsing. 62/*! \ingroup RAPIDJSON_ERRORS 63 \see GenericReader::Parse, GenericReader::GetParseErrorCode 64*/ 65enum ParseErrorCode { 66 kParseErrorNone = 0, //!< No error. 67 68 kParseErrorDocumentEmpty, //!< The document is empty. 69 kParseErrorDocumentRootNotSingular, //!< The document root must not follow by other values. 70 71 kParseErrorValueInvalid, //!< Invalid value. 72 73 kParseErrorObjectMissName, //!< Missing a name for object member. 74 kParseErrorObjectMissColon, //!< Missing a colon after a name of object member. 75 kParseErrorObjectMissCommaOrCurlyBracket, //!< Missing a comma or '}' after an object member. 76 77 kParseErrorArrayMissCommaOrSquareBracket, //!< Missing a comma or ']' after an array element. 78 79 kParseErrorStringUnicodeEscapeInvalidHex, //!< Incorrect hex digit after \\u escape in string. 80 kParseErrorStringUnicodeSurrogateInvalid, //!< The surrogate pair in string is invalid. 81 kParseErrorStringEscapeInvalid, //!< Invalid escape character in string. 82 kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string. 83 kParseErrorStringInvalidEncoding, //!< Invalid encoding in string. 84 85 kParseErrorNumberTooBig, //!< Number too big to be stored in double. 86 kParseErrorNumberMissFraction, //!< Miss fraction part in number. 87 kParseErrorNumberMissExponent, //!< Miss exponent in number. 88 89 kParseErrorTermination, //!< Parsing was terminated. 90 kParseErrorUnspecificSyntaxError //!< Unspecific syntax error. 91}; 92 93//! Result of parsing (wraps ParseErrorCode) 94/*! 95 \ingroup RAPIDJSON_ERRORS 96 \code 97 Document doc; 98 ParseResult ok = doc.Parse("[42]"); 99 if (!ok) { 100 fprintf(stderr, "JSON parse error: %s (%u)", 101 GetParseError_En(ok.Code()), ok.Offset()); 102 exit(EXIT_FAILURE); 103 } 104 \endcode 105 \see GenericReader::Parse, GenericDocument::Parse 106*/ 107struct ParseResult { 108 //!! Unspecified boolean type 109 typedef bool (ParseResult::*BooleanType)() const; 110private: 111 ParseErrorCode code_; 112 size_t offset_; 113 114public: 115 //! Default constructor, no error. 116 ParseResult() : code_(kParseErrorNone), offset_(0) {} 117 //! Constructor to set an error. 118 ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {} 119 120 //! Get the error code. 121 ParseErrorCode Code() const { return code_; } 122 //! Get the error offset, if \ref IsError(), 0 otherwise. 123 size_t _Offset() const { return offset_; } 124 125 //! Explicit conversion to \c bool, returns \c true, iff !\ref IsError(). 126 operator BooleanType() const { return !IsError() ? &ParseResult::IsError : NULL; } 127 //! Whether the result is an error. 128 bool IsError() const { return code_ != kParseErrorNone; } 129 130 bool operator==(const ParseResult& that) const { return code_ == that.code_; } 131 bool operator==(ParseErrorCode code) const { return code_ == code; } 132 friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; } 133 134 bool operator!=(const ParseResult& that) const { return !(*this == that); } 135 bool operator!=(ParseErrorCode code) const { return !(*this == code); } 136 friend bool operator!=(ParseErrorCode code, const ParseResult & err) { return err != code; } 137 138 //! Reset error code. 139 void Clear() { Set(kParseErrorNone); } 140 //! Update error code and offset. 141 void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; } 142}; 143 144//! Function pointer type of GetParseError(). 145/*! \ingroup RAPIDJSON_ERRORS 146 147 This is the prototype for \c GetParseError_X(), where \c X is a locale. 148 User can dynamically change locale in runtime, e.g.: 149\code 150 GetParseErrorFunc GetParseError = GetParseError_En; // or whatever 151 const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode()); 152\endcode 153*/ 154typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode); 155 156RAPIDJSON_NAMESPACE_END 157 158#ifdef __clang__ 159RAPIDJSON_DIAG_POP 160#endif 161 162#endif // RAPIDJSON_ERROR_ERROR_H_ 163