496970eb08b048bbe6112564589fb4b2b72bdb27
[tpg/acess2.git] / Usermode / Libraries / libc++.so_src / include_exp / system_error
1 /*
2  * Acess2 C++ Library
3  * - By John Hodge (thePowersGang)
4  *
5  * system_error (header)
6  * - C++11's system_error exception
7  */
8 #ifndef _LIBCXX_SYSTEM_ERROR_
9 #define _LIBCXX_SYSTEM_ERROR_
10
11 #include "_libcxx_helpers.h"
12
13 #if !_CXX11_AVAIL
14 # error "This header requires C++11 support enabled"
15 #endif
16
17 #include <exception>
18 #include <string>
19
20 namespace std {
21
22 class error_category;
23 class error_condition;
24 class error_code;
25
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;
33
34 extern const error_category&    generic_category() noexcept;
35 extern const error_category&    system_category() noexcept;
36
37 class error_condition
38 {
39          int    m_val;
40         const error_category*   m_cat;
41 public:
42         error_condition() noexcept:
43                 error_condition(0, ::std::generic_category())
44         {
45         }
46         error_condition(int val, const error_category& cat) noexcept:
47                 m_val(val),
48                 m_cat(&cat)
49         {
50         }
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 {
54                 m_val = val;
55                 m_cat = &cat;
56         }
57         void clear() noexcept {
58                 assign(0, ::std::generic_category());
59         }
60         int value() const noexcept {
61                 return m_val;
62         }
63         const error_category& category() const noexcept {
64                 return *m_cat;
65         }
66         string message() const;
67         explicit operator bool() const noexcept {
68                 return m_val != 0;
69         }
70 };
71
72 class error_category
73 {
74 public:
75         error_category() {
76         }
77         error_category(const error_category&) = delete; // disallow copying
78         virtual ~error_category() noexcept {
79         }
80         bool operator==(const error_category& rhs) const noexcept {
81                 return this == &rhs;
82         }
83         bool operator!=(const error_category& rhs) const noexcept {
84                 return !(*this == rhs);
85         }
86         bool operator<(const error_category& rhs) const noexcept {
87                 return this < &rhs;
88         }
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);
92         }
93         virtual bool equivalent(int valcode, const ::std::error_condition& cond) const noexcept {
94                 return default_error_condition(valcode) == cond;
95         }
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;
98 };
99
100 class error_code
101 {
102         int     m_ev;
103         const ::std::error_category*    m_ecat;
104 public:
105         error_code() noexcept:
106                 error_code(0, ::std::generic_category())
107         {
108         }
109         error_code(int ev, const ::std::error_category& ecat) noexcept:
110                 m_ev(ev),
111                 m_ecat(&ecat)
112         {
113         }
114         //template <class ErrorCodeEnum>
115         //error_code(ErrorCodeEnum e) noexcept;
116         void assign(int val, const error_category& ecat) noexcept {
117                 m_ev = val;
118                 m_ecat = &ecat;
119         }
120         //template <class ErrorCodeEnum>
121         //error_code& operator= (ErrorCodeEnum e) noexcept;
122         void clear() noexcept {
123                 m_ev = 0;
124                 m_ecat = 0;
125         }
126         int value() const noexcept {
127                 return m_ev;
128         }
129         const error_category& category() const noexcept {
130                 return *m_ecat;
131         }
132         error_condition default_error_condition() const noexcept {
133                 return category().default_error_condition(value());
134         }
135         ::std::string message() const {
136                 return category().message(value());
137         }
138         operator bool() const noexcept {
139                 return m_ev != 0;
140         }
141 };
142
143 class system_error:
144         public ::std::exception
145 {
146         const error_code        m_error_code;
147         ::std::string   m_what_str;
148 public:
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;
156         
157         const char* what() const noexcept;
158 };
159
160 static inline bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept {
161         return lhs.category() == rhs.category() && lhs.value() == rhs.value();
162 }
163 static inline bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept {
164         return !(lhs == rhs);
165 }
166 static inline bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept {
167         return lhs.category() < rhs.category() || lhs.value() < rhs.value();
168 }
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);
171 }
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());
174 }
175 static inline bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept {
176         return !(lhs == rhs);
177 }
178 static inline bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept {
179         return !(lhs == rhs);
180 }
181
182
183
184 };      // namespace std
185
186 #endif
187
188 // vim: ft=cpp
189

UCC git Repository :: git.ucc.asn.au