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 #if __cplusplus <= 199711L // C++11 check
12 # error "This header requires C++11 support enabled"
20 class error_condition;
23 bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
24 bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
25 bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept;
26 bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
27 bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
28 bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
29 bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
31 extern const error_category& generic_category() noexcept;
32 extern const error_category& system_category() noexcept;
37 const error_category* m_cat;
39 error_condition() noexcept:
40 error_condition(0, ::std::generic_category())
43 error_condition(int val, const error_category& cat) noexcept:
48 //template <class ErrorConditionEnum> error_condition(ErrorConditionEnum e) noexcept;
49 //template <class ErrorConditionEnum> error_condition& operator=(ErrorConditionEnum e) noexcept;
50 void assign(int val, const error_category& cat) noexcept {
54 void clear() noexcept {
55 assign(0, ::std::generic_category());
57 int value() const noexcept {
60 const error_category& category() const noexcept {
63 string message() const;
64 explicit operator bool() const noexcept {
74 error_category(const error_category&) = delete; // disallow copying
75 virtual ~error_category() noexcept {
77 bool operator==(const error_category& rhs) const noexcept {
80 bool operator!=(const error_category& rhs) const noexcept {
81 return !(*this == rhs);
83 bool operator<(const error_category& rhs) const noexcept {
86 virtual const char* name() const noexcept = 0;
87 virtual error_condition default_error_condition(int val) const noexcept {
88 return error_condition(val, *this);
90 virtual bool equivalent(int valcode, const ::std::error_condition& cond) const noexcept {
91 return default_error_condition(valcode) == cond;
93 virtual bool equivalent(const error_code& code, int valcond) const noexcept; // in system_error.cc
94 virtual ::std::string message(int val) const = 0;
100 const ::std::error_category* m_ecat;
102 error_code() noexcept:
103 error_code(0, ::std::generic_category())
106 error_code(int ev, const ::std::error_category& ecat) noexcept:
111 //template <class ErrorCodeEnum>
112 //error_code(ErrorCodeEnum e) noexcept;
113 void assign(int val, const error_category& ecat) noexcept {
117 //template <class ErrorCodeEnum>
118 //error_code& operator= (ErrorCodeEnum e) noexcept;
119 void clear() noexcept {
123 int value() const noexcept {
126 const error_category& category() const noexcept {
129 error_condition default_error_condition() const noexcept {
130 return category().default_error_condition(value());
132 ::std::string message() const {
133 return category().message(value());
135 operator bool() const noexcept {
141 public ::std::exception
143 const error_code m_error_code;
144 ::std::string m_what_str;
146 system_error(::std::error_code ec);
147 system_error(::std::error_code ec, const ::std::string& what_arg);
148 system_error(::std::error_code ec, const char* what_arg);
149 system_error(int ev, const ::std::error_category& ecat);
150 system_error(int ev, const ::std::error_category& ecat, const ::std::string& what_arg);
151 system_error(int ev, const ::std::error_category& ecat, const char* what_arg);
152 ~system_error() noexcept;
154 const char* what() const noexcept;
157 bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept {
158 return lhs.category() == rhs.category() && lhs.value() == rhs.value();
160 bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept {
161 return !(lhs == rhs);
163 bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept {
164 return lhs.category() < rhs.category() || lhs.value() < rhs.value();
166 bool operator==(const error_condition& lhs, const error_code& rhs) noexcept {
167 return lhs.category().equivalent(rhs, lhs.value()) || rhs.category().equivalent(rhs.value(), lhs);
169 bool operator==(const error_code& lhs, const error_condition& rhs) noexcept {
170 return lhs.category().equivalent(lhs.value(),rhs) || rhs.category().equivalent(lhs,rhs.value());
172 bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept {
173 return !(lhs == rhs);
175 bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept {
176 return !(lhs == rhs);