simdjson  0.3.1
Ridiculously Fast JSON
error.h
1 #ifndef SIMDJSON_ERROR_H
2 #define SIMDJSON_ERROR_H
3 
4 #include "simdjson/common_defs.h"
5 #include <string>
6 #include <utility>
7 
8 namespace simdjson {
9 
13 enum error_code {
14  SUCCESS = 0,
15  SUCCESS_AND_HAS_MORE,
16  CAPACITY,
17  MEMALLOC,
18  TAPE_ERROR,
19  DEPTH_ERROR,
20  STRING_ERROR,
21  T_ATOM_ERROR,
22  F_ATOM_ERROR,
23  N_ATOM_ERROR,
24  NUMBER_ERROR,
25  UTF8_ERROR,
26  UNINITIALIZED,
27  EMPTY,
28  UNESCAPED_CHARS,
29  UNCLOSED_STRING,
30  UNSUPPORTED_ARCHITECTURE,
31  INCORRECT_TYPE,
32  NUMBER_OUT_OF_RANGE,
33  INDEX_OUT_OF_BOUNDS,
34  NO_SUCH_FIELD,
35  IO_ERROR,
36  INVALID_JSON_POINTER,
37  INVALID_URI_FRAGMENT,
38  UNEXPECTED_ERROR,
39 
40  NUM_ERROR_CODES
41 };
42 
52 inline const char *error_message(error_code error) noexcept;
53 
57 inline std::ostream& operator<<(std::ostream& out, error_code error) noexcept;
58 
62 struct simdjson_error : public std::exception {
67  simdjson_error(error_code error) noexcept : _error{error} { }
69  const char *what() const noexcept { return error_message(error()); }
71  error_code error() const noexcept { return _error; }
72 private:
74  error_code _error;
75 };
76 
77 namespace internal {
78 
99 template<typename T>
100 struct simdjson_result_base : public std::pair<T, error_code> {
101 
105  really_inline simdjson_result_base() noexcept;
106 
110  really_inline simdjson_result_base(error_code error) noexcept;
111 
115  really_inline simdjson_result_base(T &&value) noexcept;
116 
120  really_inline simdjson_result_base(T &&value, error_code error) noexcept;
121 
125  really_inline void tie(T &value, error_code &error) && noexcept;
126 
130  really_inline error_code error() const noexcept;
131 
132 #if SIMDJSON_EXCEPTIONS
133 
139  really_inline T& value() noexcept(false);
140 
146  really_inline T&& take_value() && noexcept(false);
147 
153  really_inline operator T&&() && noexcept(false);
154 
155 #endif // SIMDJSON_EXCEPTIONS
156 }; // struct simdjson_result_base
157 
158 } // namespace internal
159 
165 template<typename T>
166 struct simdjson_result : public internal::simdjson_result_base<T> {
170  really_inline simdjson_result() noexcept;
174  really_inline simdjson_result(T &&value) noexcept;
178  really_inline simdjson_result(error_code error_code) noexcept;
182  really_inline simdjson_result(T &&value, error_code error) noexcept;
183 
187  really_inline void tie(T& t, error_code & e) && noexcept;
188 
192  really_inline error_code error() const noexcept;
193 
194 #if SIMDJSON_EXCEPTIONS
195 
201  really_inline T& value() noexcept(false);
202 
208  really_inline T&& take_value() && noexcept(false);
209 
215  really_inline operator T&&() && noexcept(false);
216 
217 #endif // SIMDJSON_EXCEPTIONS
218 }; // struct simdjson_result
219 
223 using ErrorValues [[deprecated("This is an alias and will be removed, use error_code instead")]] = error_code;
224 
228 [[deprecated("Error codes should be stored and returned as `error_code`, use `error_message()` instead.")]]
229 inline const std::string &error_message(int error) noexcept;
230 
231 } // namespace simdjson
232 
233 #endif // SIMDJSON_ERROR_H
simdjson::simdjson_result::value
really_inline T & value() noexcept(false)
Get the result value.
Definition: error.h:134
simdjson::simdjson_result
The result of a simdjson operation that could fail.
Definition: error.h:166
simdjson::simdjson_error::simdjson_error
simdjson_error(error_code error) noexcept
Create an exception from a simdjson error code.
Definition: error.h:67
simdjson::simdjson_result::take_value
really_inline T && take_value() &&noexcept(false)
Take the result value (move it).
Definition: error.h:139
simdjson::simdjson_error
Exception thrown when an exception-supporting simdjson method is called.
Definition: error.h:62
simdjson::simdjson_result::tie
really_inline void tie(T &t, error_code &e) &&noexcept
Move the value and the error to the provided variables.
Definition: error.h:122
simdjson::simdjson_result::error
really_inline error_code error() const noexcept
The error.
Definition: error.h:127
simdjson::simdjson_error::error
error_code error() const noexcept
The error code.
Definition: error.h:71
simdjson::simdjson_error::what
const char * what() const noexcept
The error message.
Definition: error.h:69