NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
error_condition.hpp
1#ifndef NEFORCE_CORE_EXCEPTION_ERROR_CONDITION_HPP__
2#define NEFORCE_CORE_EXCEPTION_ERROR_CONDITION_HPP__
3#include "NeForce/core/exception/error_category.hpp"
4NEFORCE_BEGIN_NAMESPACE__
5
6class error_condition : icomparable<error_condition> {
7private:
8 int value_;
9 const error_category* category_;
10
11public:
12 error_condition() noexcept :
13 value_(0),
14 category_(&generic_category()) {}
15
16 error_condition(int val, const error_category& cat) noexcept :
17 value_(val),
18 category_(&cat) {}
19
20 explicit error_condition(errc e) noexcept { *this = make_error_condition(e); }
21
22 void assign(int val, const error_category& cat) noexcept {
23 value_ = val;
24 category_ = &cat;
25 }
26
27 void clear() noexcept {
28 value_ = 0;
29 category_ = &generic_category();
30 }
31
32 NEFORCE_NODISCARD int value() const noexcept { return value_; }
33 NEFORCE_NODISCARD const error_category& category() const noexcept { return *category_; }
34 NEFORCE_NODISCARD string message() const { return category_->message(value_); }
35
36 explicit operator bool() const noexcept { return value_ != 0; }
37
38 NEFORCE_NODISCARD bool operator==(const error_condition& rhs) const noexcept {
39 return category_ == rhs.category_ && value_ == rhs.value_;
40 }
41 NEFORCE_NODISCARD bool operator<(const error_condition& rhs) const noexcept {
42 if (*category_ < *rhs.category_) {
43 return true;
44 }
45 if (*rhs.category_ < *category_) {
46 return false;
47 }
48 return value_ < rhs.value_;
49 }
50};
51
52
53inline error_condition make_error_condition(errc e) noexcept { return {static_cast<int>(e), generic_category()}; }
54
55NEFORCE_END_NAMESPACE__
56#endif // NEFORCE_CORE_EXCEPTION_ERROR_CONDITION_HPP__
errc
系统错误码枚举
可比较对象接口模板