3 * - By John Hodge (thePowersGang)
5 * system_error (header)
6 * - C++11's system_error exception
8 #ifndef _LIBCXX_SYSTEM_ERROR_
9 #define _LIBCXX_SYSTEM_ERROR_
11 #include "_libcxx_helpers.h"
14 # error "This header requires C++11 support enabled"
23 class error_condition;
26 static bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
27 static bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
28 static bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept;
29 static bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
30 static bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
31 static bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
32 static bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
34 extern const error_category& generic_category() noexcept;
35 extern const error_category& system_category() noexcept;
40 const error_category* m_cat;
42 error_condition() noexcept:
43 error_condition(0, ::std::generic_category())
46 error_condition(int val, const error_category& cat) noexcept:
51 //template <class ErrorConditionEnum> error_condition(ErrorConditionEnum e) noexcept;
52 //template <class ErrorConditionEnum> error_condition& operator=(ErrorConditionEnum e) noexcept;
53 void assign(int val, const error_category& cat) noexcept {
57 void clear() noexcept {
58 assign(0, ::std::generic_category());
60 int value() const noexcept {
63 const error_category& category() const noexcept {
66 string message() const;
67 explicit operator bool() const noexcept {
77 error_category(const error_category&) = delete; // disallow copying
78 virtual ~error_category() noexcept {
80 bool operator==(const error_category& rhs) const noexcept {
83 bool operator!=(const error_category& rhs) const noexcept {
84 return !(*this == rhs);
86 bool operator<(const error_category& rhs) const noexcept {
89 virtual const char* name() const noexcept = 0;
90 virtual error_condition default_error_condition(int val) const noexcept {
91 return error_condition(val, *this);
93 virtual bool equivalent(int valcode, const ::std::error_condition& cond) const noexcept {
94 return default_error_condition(valcode) == cond;
96 virtual bool equivalent(const error_code& code, int valcond) const noexcept; // in system_error.cc
97 virtual ::std::string message(int val) const = 0;
103 const ::std::error_category* m_ecat;
105 error_code() noexcept:
106 error_code(0, ::std::generic_category())
109 error_code(int ev, const ::std::error_category& ecat) noexcept:
114 //template <class ErrorCodeEnum>
115 //error_code(ErrorCodeEnum e) noexcept;
116 void assign(int val, const error_category& ecat) noexcept {
120 //template <class ErrorCodeEnum>
121 //error_code& operator= (ErrorCodeEnum e) noexcept;
122 void clear() noexcept {
126 int value() const noexcept {
129 const error_category& category() const noexcept {
132 error_condition default_error_condition() const noexcept {
133 return category().default_error_condition(value());
135 ::std::string message() const {
136 return category().message(value());
138 operator bool() const noexcept {
144 public ::std::exception
146 const error_code m_error_code;
147 ::std::string m_what_str;
149 system_error(::std::error_code ec);
150 system_error(::std::error_code ec, const ::std::string& what_arg);
151 system_error(::std::error_code ec, const char* what_arg);
152 system_error(int ev, const ::std::error_category& ecat);
153 system_error(int ev, const ::std::error_category& ecat, const ::std::string& what_arg);
154 system_error(int ev, const ::std::error_category& ecat, const char* what_arg);
155 ~system_error() noexcept;
157 const char* what() const noexcept;
160 static inline bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept {
161 return lhs.category() == rhs.category() && lhs.value() == rhs.value();
163 static inline bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept {
164 return !(lhs == rhs);
166 static inline bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept {
167 return lhs.category() < rhs.category() || lhs.value() < rhs.value();
169 static inline bool operator==(const error_condition& lhs, const error_code& rhs) noexcept {
170 return lhs.category().equivalent(rhs, lhs.value()) || rhs.category().equivalent(rhs.value(), lhs);
172 static inline bool operator==(const error_code& lhs, const error_condition& rhs) noexcept {
173 return lhs.category().equivalent(lhs.value(),rhs) || rhs.category().equivalent(lhs,rhs.value());
175 static inline bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept {
176 return !(lhs == rhs);
178 static inline bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept {
179 return !(lhs == rhs);