Usermode/libc++ - Debug in cxa code, list emplace and iterators, general STL fixes
[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
19 namespace std {
20
21 class error_category;
22 class error_condition;
23 class error_code;
24
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;
32
33 extern const error_category&    generic_category() noexcept;
34 extern const error_category&    system_category() noexcept;
35
36 class error_condition
37 {
38          int    m_val;
39         const error_category*   m_cat;
40 public:
41         error_condition() noexcept:
42                 error_condition(0, ::std::generic_category())
43         {
44         }
45         error_condition(int val, const error_category& cat) noexcept:
46                 m_val(val),
47                 m_cat(&cat)
48         {
49         }
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 {
53                 m_val = val;
54                 m_cat = &cat;
55         }
56         void clear() noexcept {
57                 assign(0, ::std::generic_category());
58         }
59         int value() const noexcept {
60                 return m_val;
61         }
62         const error_category& category() const noexcept {
63                 return *m_cat;
64         }
65         string message() const;
66         explicit operator bool() const noexcept {
67                 return m_val != 0;
68         }
69 };
70
71 class error_category
72 {
73 public:
74         error_category() {
75         }
76         error_category(const error_category&) = delete; // disallow copying
77         virtual ~error_category() noexcept {
78         }
79         bool operator==(const error_category& rhs) const noexcept {
80                 return this == &rhs;
81         }
82         bool operator!=(const error_category& rhs) const noexcept {
83                 return !(*this == rhs);
84         }
85         bool operator<(const error_category& rhs) const noexcept {
86                 return this < &rhs;
87         }
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);
91         }
92         virtual bool equivalent(int valcode, const ::std::error_condition& cond) const noexcept {
93                 return default_error_condition(valcode) == cond;
94         }
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;
97 };
98
99 class error_code
100 {
101         int     m_ev;
102         const ::std::error_category*    m_ecat;
103 public:
104         error_code() noexcept:
105                 error_code(0, ::std::generic_category())
106         {
107         }
108         error_code(int ev, const ::std::error_category& ecat) noexcept:
109                 m_ev(ev),
110                 m_ecat(&ecat)
111         {
112         }
113         //template <class ErrorCodeEnum>
114         //error_code(ErrorCodeEnum e) noexcept;
115         void assign(int val, const error_category& ecat) noexcept {
116                 m_ev = val;
117                 m_ecat = &ecat;
118         }
119         //template <class ErrorCodeEnum>
120         //error_code& operator= (ErrorCodeEnum e) noexcept;
121         void clear() noexcept {
122                 m_ev = 0;
123                 m_ecat = 0;
124         }
125         int value() const noexcept {
126                 return m_ev;
127         }
128         const error_category& category() const noexcept {
129                 return *m_ecat;
130         }
131         error_condition default_error_condition() const noexcept {
132                 return category().default_error_condition(value());
133         }
134         ::std::string message() const {
135                 return category().message(value());
136         }
137         operator bool() const noexcept {
138                 return m_ev != 0;
139         }
140 };
141
142 class system_error:
143         public ::std::exception
144 {
145         const error_code        m_error_code;
146         ::std::string   m_what_str;
147 public:
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;
155         
156         const char* what() const noexcept;
157 };
158
159 static inline bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept {
160         return lhs.category() == rhs.category() && lhs.value() == rhs.value();
161 }
162 static inline bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept {
163         return !(lhs == rhs);
164 }
165 static inline bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept {
166         return lhs.category() < rhs.category() || lhs.value() < rhs.value();
167 }
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);
170 }
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());
173 }
174 static inline bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept {
175         return !(lhs == rhs);
176 }
177 static inline bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept {
178         return !(lhs == rhs);
179 }
180
181
182
183 };      // namespace std
184
185 #endif
186
187 // vim: ft=cpp
188

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