11 #ifndef ASIO_ERROR_CODE_HPP 12 #define ASIO_ERROR_CODE_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 20 #if defined(ASIO_HAS_STD_SYSTEM_ERROR) 21 # include <system_error> 22 #else // defined(ASIO_HAS_STD_SYSTEM_ERROR) 24 # include "asio/detail/noncopyable.hpp" 25 # if !defined(ASIO_NO_IOSTREAM) 27 # endif // !defined(ASIO_NO_IOSTREAM) 28 #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR) 30 #include "asio/detail/push_options.hpp" 34 #if defined(ASIO_HAS_STD_SYSTEM_ERROR) 36 typedef std::error_category error_category;
38 #else // defined(ASIO_HAS_STD_SYSTEM_ERROR) 50 virtual const char*
name()
const = 0;
53 virtual std::string
message(
int value)
const = 0;
64 return !(*
this == rhs);
68 #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR) 71 extern ASIO_DECL
const error_category& system_category();
73 #if defined(ASIO_HAS_STD_SYSTEM_ERROR) 77 #else // defined(ASIO_HAS_STD_SYSTEM_ERROR) 86 category_(&system_category())
98 template <
typename ErrorEnum>
101 *
this = make_error_code(e);
108 category_ = &system_category();
112 void assign(
int v,
const error_category& c)
133 return category_->message(value_);
145 operator unspecified_bool_type()
const 150 return &error_code::unspecified_bool_true;
160 friend bool operator==(
const error_code& e1,
const error_code& e2)
162 return e1.value_ == e2.value_ && e1.category_ == e2.category_;
166 friend bool operator!=(
const error_code& e1,
const error_code& e2)
168 return e1.value_ != e2.value_ || e1.category_ != e2.category_;
176 const error_category* category_;
179 # if !defined(ASIO_NO_IOSTREAM) 182 template <
typename Elem,
typename Traits>
183 std::basic_ostream<Elem, Traits>& operator<<(
184 std::basic_ostream<Elem, Traits>& os,
const error_code& ec)
190 # endif // !defined(ASIO_NO_IOSTREAM) 192 #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR) 196 #include "asio/detail/pop_options.hpp" 198 #if defined(ASIO_HEADER_ONLY) 199 # include "asio/impl/error_code.ipp" 200 #endif // defined(ASIO_HEADER_ONLY) 202 #endif // ASIO_ERROR_CODE_HPP error_code()
Default constructor.
Definition: error_code.hpp:84
Definition: noncopyable.hpp:25
virtual const char * name() const =0
Returns a string naming the error gategory.
error_code(ErrorEnum e)
Construct from an error code enum.
Definition: error_code.hpp:99
bool operator!=(const error_category &rhs) const
Inequality operator to compare two error categories.
Definition: error_code.hpp:62
virtual std::string message(int value) const =0
Returns a string describing the error denoted by value.
friend bool operator==(const error_code &e1, const error_code &e2)
Equality operator to compare two error objects.
Definition: error_code.hpp:160
int value() const
Get the error value.
Definition: error_code.hpp:119
error_code(int v, const error_category &c)
Construct with specific error code and category.
Definition: error_code.hpp:91
void clear()
Clear the error value to the default.
Definition: error_code.hpp:105
std::string message() const
Get the message associated with the error.
Definition: error_code.hpp:131
friend bool operator!=(const error_code &e1, const error_code &e2)
Inequality operator to compare two error objects.
Definition: error_code.hpp:166
Class to represent an error code value.
Definition: error_code.hpp:80
Definition: error_code.hpp:136
bool operator==(const error_category &rhs) const
Equality operator to compare two error categories.
Definition: error_code.hpp:56
bool operator!() const
Operator to test if the error represents success.
Definition: error_code.hpp:154
virtual ~error_category()
Destructor.
Definition: error_code.hpp:45
const error_category & category() const
Get the error category.
Definition: error_code.hpp:125
Definition: any_io_executor.hpp:28
void assign(int v, const error_category &c)
Assign a new error value.
Definition: error_code.hpp:112