error.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON
2 // available.
3 //
4 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
5 // rights reserved.
6 //
7 // Licensed under the MIT License (the "License"); you may not use this file
8 // except in compliance with the License. You may obtain a copy of the License
9 // at
10 //
11 // http://opensource.org/licenses/MIT
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 // License for the specific language governing permissions and limitations under
17 // the License.
18 
19 #ifndef RAPIDJSON_ERROR_ERROR_H_
20 #define RAPIDJSON_ERROR_ERROR_H_
21 
22 #include "../rapidjson.h"
23 
24 #ifdef __clang__
25 RAPIDJSON_DIAG_PUSH
26 RAPIDJSON_DIAG_OFF(padded)
27 #endif
28 
33 // RAPIDJSON_ERROR_CHARTYPE
35 
37 
42 #ifndef RAPIDJSON_ERROR_CHARTYPE
43 #define RAPIDJSON_ERROR_CHARTYPE char
44 #endif
45 
47 // RAPIDJSON_ERROR_STRING
48 
50 
55 #ifndef RAPIDJSON_ERROR_STRING
56 #define RAPIDJSON_ERROR_STRING(x) x
57 #endif
58 
60 
62 // ParseErrorCode
63 
65 
70 
73 
76 
81 
85 
97 
101 
104 };
105 
107 
120 struct ParseResult {
122  typedef bool (ParseResult::*BooleanType)() const;
123 
124  public:
128  ParseResult(ParseErrorCode code, size_t offset)
129  : code_(code), offset_(offset) {}
130 
132  ParseErrorCode Code() const { return code_; }
134  size_t Offset() const { return offset_; }
135 
137  operator BooleanType() const {
138  return !IsError() ? &ParseResult::IsError : NULL;
139  }
141  bool IsError() const { return code_ != kParseErrorNone; }
142 
143  bool operator==(const ParseResult &that) const { return code_ == that.code_; }
144  bool operator==(ParseErrorCode code) const { return code_ == code; }
145  friend bool operator==(ParseErrorCode code, const ParseResult &err) {
146  return code == err.code_;
147  }
148 
149  bool operator!=(const ParseResult &that) const { return !(*this == that); }
150  bool operator!=(ParseErrorCode code) const { return !(*this == code); }
151  friend bool operator!=(ParseErrorCode code, const ParseResult &err) {
152  return err != code;
153  }
154 
156  void Clear() { Set(kParseErrorNone); }
158  void Set(ParseErrorCode code, size_t offset = 0) {
159  code_ = code;
160  offset_ = offset;
161  }
162 
163  private:
165  size_t offset_;
166 };
167 
169 
178 typedef const RAPIDJSON_ERROR_CHARTYPE *(*GetParseErrorFunc)(ParseErrorCode);
179 
181 
182 #ifdef __clang__
183 RAPIDJSON_DIAG_POP
184 #endif
185 
186 #endif // RAPIDJSON_ERROR_ERROR_H_
bool operator!=(ParseErrorCode code) const
Definition: error.h:150
No error.
Definition: error.h:69
friend bool operator!=(ParseErrorCode code, const ParseResult &err)
Definition: error.h:151
Invalid value.
Definition: error.h:75
Parsing was terminated.
Definition: error.h:102
size_t Offset() const
Get the error offset, if IsError(), 0 otherwise.
Definition: error.h:134
bool operator==(ParseErrorCode code) const
Definition: error.h:144
ParseErrorCode code_
Definition: error.h:164
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
The document is empty.
Definition: error.h:71
bool operator==(const ParseResult &that) const
Definition: error.h:143
bool operator!=(const ParseResult &that) const
Definition: error.h:149
Missing a name for object member.
Definition: error.h:77
Result of parsing (wraps ParseErrorCode)
Definition: error.h:120
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
Number too big to be stored in double.
Definition: error.h:98
void Set(ParseErrorCode code, size_t offset=0)
Update error code and offset.
Definition: error.h:158
ParseErrorCode
Error code of parsing.
Definition: error.h:68
ParseErrorCode Code() const
Get the error code.
Definition: error.h:132
bool(ParseResult::* BooleanType)() const
! Unspecified boolean type
Definition: error.h:122
Miss exponent in number.
Definition: error.h:100
Invalid escape character in string.
Definition: error.h:93
Invalid encoding in string.
Definition: error.h:96
bool IsError() const
Whether the result is an error.
Definition: error.h:141
ParseResult()
Default constructor, no error.
Definition: error.h:126
#define RAPIDJSON_ERROR_CHARTYPE
Character type of error messages.
Definition: error.h:43
Miss fraction part in number.
Definition: error.h:99
void Clear()
Reset error code.
Definition: error.h:156
Unspecific syntax error.
Definition: error.h:103
ParseResult(ParseErrorCode code, size_t offset)
Constructor to set an error.
Definition: error.h:128
size_t offset_
Definition: error.h:165
friend bool operator==(ParseErrorCode code, const ParseResult &err)
Definition: error.h:145


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46