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"
22 class error_condition;
25 static bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
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_code& rhs) noexcept;
29 static bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
30 static bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
31 static bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
33 extern const error_category& generic_category() noexcept;
34 extern const error_category& system_category() noexcept;
39 const error_category* m_cat;
41 error_condition() noexcept:
42 error_condition(0, ::std::generic_category())
45 error_condition(int val, const error_category& cat) noexcept:
50 //template <class ErrorConditionEnum> error_condition(ErrorConditionEnum e) noexcept;
51 //template <class ErrorConditionEnum> error_condition& operator=(ErrorConditionEnum e) noexcept;
52 void assign(int val, const error_category& cat) noexcept {
56 void clear() noexcept {
57 assign(0, ::std::generic_category());
59 int value() const noexcept {
62 const error_category& category() const noexcept {
65 string message() const;
66 explicit operator bool() const noexcept {
76 error_category(const error_category&) = delete; // disallow copying
77 virtual ~error_category() noexcept {
79 bool operator==(const error_category& rhs) const noexcept {
82 bool operator!=(const error_category& rhs) const noexcept {
83 return !(*this == rhs);
85 bool operator<(const error_category& rhs) const noexcept {
88 virtual const char* name() const noexcept = 0;
89 virtual error_condition default_error_condition(int val) const noexcept {
90 return error_condition(val, *this);
92 virtual bool equivalent(int valcode, const ::std::error_condition& cond) const noexcept {
93 return default_error_condition(valcode) == cond;
95 virtual bool equivalent(const error_code& code, int valcond) const noexcept; // in system_error.cc
96 virtual ::std::string message(int val) const = 0;
102 const ::std::error_category* m_ecat;
104 error_code() noexcept:
105 error_code(0, ::std::generic_category())
108 error_code(int ev, const ::std::error_category& ecat) noexcept:
113 //template <class ErrorCodeEnum>
114 //error_code(ErrorCodeEnum e) noexcept;
115 void assign(int val, const error_category& ecat) noexcept {
119 //template <class ErrorCodeEnum>
120 //error_code& operator= (ErrorCodeEnum e) noexcept;
121 void clear() noexcept {
125 int value() const noexcept {
128 const error_category& category() const noexcept {
131 error_condition default_error_condition() const noexcept {
132 return category().default_error_condition(value());
134 ::std::string message() const {
135 return category().message(value());
137 operator bool() const noexcept {
143 public ::std::exception
145 const error_code m_error_code;
146 ::std::string m_what_str;
148 system_error(::std::error_code ec);
149 system_error(::std::error_code ec, const ::std::string& what_arg);
150 system_error(::std::error_code ec, const char* what_arg);
151 system_error(int ev, const ::std::error_category& ecat);
152 system_error(int ev, const ::std::error_category& ecat, const ::std::string& what_arg);
153 system_error(int ev, const ::std::error_category& ecat, const char* what_arg);
154 ~system_error() noexcept;
156 const char* what() const noexcept;
159 static inline bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept {
160 return lhs.category() == rhs.category() && lhs.value() == rhs.value();
162 static inline bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept {
163 return !(lhs == rhs);
165 static inline bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept {
166 return lhs.category() < rhs.category() || lhs.value() < rhs.value();
168 static inline bool operator==(const error_condition& lhs, const error_code& rhs) noexcept {
169 return lhs.category().equivalent(rhs, lhs.value()) || rhs.category().equivalent(rhs.value(), lhs);
171 static inline bool operator==(const error_code& lhs, const error_condition& rhs) noexcept {
172 return lhs.category().equivalent(lhs.value(),rhs) || rhs.category().equivalent(lhs,rhs.value());
174 static inline bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept {
175 return !(lhs == rhs);
177 static inline bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept {
178 return !(lhs == rhs);