Usermode/libc++ - system_error and vector implementation
[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 #if __cplusplus <= 199711L      // C++11 check
12 # error "This header requires C++11 support enabled"
13 #endif
14
15 #include <exception>
16
17 namespace std {
18
19 class error_category;
20 class error_condition;
21 class error_code;
22
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;
30
31 extern const error_category&    generic_category() noexcept;
32 extern const error_category&    system_category() noexcept;
33
34 class error_condition
35 {
36          int    m_val;
37         const error_category*   m_cat;
38 public:
39         error_condition() noexcept:
40                 error_condition(0, ::std::generic_category())
41         {
42         }
43         error_condition(int val, const error_category& cat) noexcept:
44                 m_val(val),
45                 m_cat(&cat)
46         {
47         }
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 {
51                 m_val = val;
52                 m_cat = &cat;
53         }
54         void clear() noexcept {
55                 assign(0, ::std::generic_category());
56         }
57         int value() const noexcept {
58                 return m_val;
59         }
60         const error_category& category() const noexcept {
61                 return *m_cat;
62         }
63         string message() const;
64         explicit operator bool() const noexcept {
65                 return m_val != 0;
66         }
67 };
68
69 class error_category
70 {
71 public:
72         error_category() {
73         }
74         error_category(const error_category&) = delete; // disallow copying
75         virtual ~error_category() noexcept {
76         }
77         bool operator==(const error_category& rhs) const noexcept {
78                 return this == &rhs;
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         virtual const char* name() const noexcept = 0;
87         virtual error_condition default_error_condition(int val) const noexcept {
88                 return error_condition(val, *this);
89         }
90         virtual bool equivalent(int valcode, const ::std::error_condition& cond) const noexcept {
91                 return default_error_condition(valcode) == cond;
92         }
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;
95 };
96
97 class error_code
98 {
99         int     m_ev;
100         const ::std::error_category*    m_ecat;
101 public:
102         error_code() noexcept:
103                 error_code(0, ::std::generic_category())
104         {
105         }
106         error_code(int ev, const ::std::error_category& ecat) noexcept:
107                 m_ev(ev),
108                 m_ecat(&ecat)
109         {
110         }
111         //template <class ErrorCodeEnum>
112         //error_code(ErrorCodeEnum e) noexcept;
113         void assign(int val, const error_category& ecat) noexcept {
114                 m_ev = val;
115                 m_ecat = &ecat;
116         }
117         //template <class ErrorCodeEnum>
118         //error_code& operator= (ErrorCodeEnum e) noexcept;
119         void clear() noexcept {
120                 m_ev = 0;
121                 m_ecat = 0;
122         }
123         int value() const noexcept {
124                 return m_ev;
125         }
126         const error_category& category() const noexcept {
127                 return *m_ecat;
128         }
129         error_condition default_error_condition() const noexcept {
130                 return category().default_error_condition(value());
131         }
132         ::std::string message() const {
133                 return category().message(value());
134         }
135         operator bool() const noexcept {
136                 return m_ev != 0;
137         }
138 };
139
140 class system_error:
141         public ::std::exception
142 {
143         const error_code        m_error_code;
144         ::std::string   m_what_str;
145 public:
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;
153         
154         const char* what() const noexcept;
155 };
156
157 bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept {
158         return lhs.category() == rhs.category() && lhs.value() == rhs.value();
159 }
160 bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept {
161         return !(lhs == rhs);
162 }
163 bool operator< (const error_condition& lhs, const error_condition& rhs) noexcept {
164         return lhs.category() < rhs.category() || lhs.value() < rhs.value();
165 }
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);
168 }
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());
171 }
172 bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept {
173         return !(lhs == rhs);
174 }
175 bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept {
176         return !(lhs == rhs);
177 }
178
179
180
181 };      // namespace std
182
183 #endif
184
185 // vim: ft=cpp
186

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