Result of parsing (wraps ParseErrorCode) ! \ingroup RAPIDJSON_ERRORS \code Document doc; ParseResult ok = doc.Parse("[42]"); if (!ok) { fprintf(stderr, "JSON parse error: %s (%u)", GetParseError_En(ok.Code()), ok.Offset()); exit(EXIT_FAILURE); } \endcode \see GenericReader::Parse, GenericDocument::Parse */
| 104 | \see GenericReader::Parse, GenericDocument::Parse |
| 105 | */ |
| 106 | struct ParseResult { |
| 107 | public: |
| 108 | //! Default constructor, no error. |
| 109 | ParseResult() : code_(kParseErrorNone), offset_(0) {} |
| 110 | //! Constructor to set an error. |
| 111 | ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {} |
| 112 | |
| 113 | //! Get the error code. |
| 114 | ParseErrorCode Code() const { return code_; } |
| 115 | //! Get the error offset, if \ref IsError(), 0 otherwise. |
| 116 | size_t Offset() const { return offset_; } |
| 117 | |
| 118 | //! Conversion to \c bool, returns \c true, iff !\ref IsError(). |
| 119 | operator bool() const { return !IsError(); } |
| 120 | //! Whether the result is an error. |
| 121 | bool IsError() const { return code_ != kParseErrorNone; } |
| 122 | |
| 123 | bool operator==(const ParseResult& that) const { return code_ == that.code_; } |
| 124 | bool operator==(ParseErrorCode code) const { return code_ == code; } |
| 125 | friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; } |
| 126 | |
| 127 | //! Reset error code. |
| 128 | void Clear() { Set(kParseErrorNone); } |
| 129 | //! Update error code and offset. |
| 130 | void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; } |
| 131 | |
| 132 | private: |
| 133 | ParseErrorCode code_; |
| 134 | size_t offset_; |
| 135 | }; |
| 136 | |
| 137 | //! Function pointer type of GetParseError(). |
| 138 | /*! \ingroup RAPIDJSON_ERRORS |
no outgoing calls
no test coverage detected