NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
error_condition.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_EXCEPTION_ERROR_CONDITION_HPP__
2#define NEFORCE_CORE_EXCEPTION_ERROR_CONDITION_HPP__
3
12
14NEFORCE_BEGIN_NAMESPACE__
15
20
28class error_condition : public icomparable<error_condition> {
29private:
30 int value_{0};
31 const error_category* category_{&generic_category()};
32
33public:
39 error_condition() noexcept = default;
40
46 error_condition(int val, const error_category& cat) noexcept :
47 value_(val),
48 category_(&cat) {}
49
56 explicit error_condition(errc e) noexcept { *this = make_error_condition(e); }
57
63 void assign(int val, const error_category& cat) noexcept {
64 value_ = val;
65 category_ = &cat;
66 }
67
73 void clear() noexcept {
74 value_ = 0;
75 category_ = &generic_category();
76 }
77
82 NEFORCE_NODISCARD int value() const noexcept { return value_; }
83
88 NEFORCE_NODISCARD const error_category& category() const noexcept { return *category_; }
89
94 NEFORCE_NODISCARD string message() const { return category_->message(value_); }
95
100 explicit operator bool() const noexcept { return value_ != 0; }
101
102 NEFORCE_NODISCARD bool equal_to(const error_condition& rhs) const noexcept {
103 return category_ == rhs.category_ && value_ == rhs.value_;
104 }
105 NEFORCE_NODISCARD bool less_than(const error_condition& rhs) const noexcept {
106 if (*category_ < *rhs.category_) {
107 return true;
108 }
109 if (*rhs.category_ < *category_) {
110 return false;
111 }
112 return value_ < rhs.value_;
113 }
114};
115
121inline error_condition make_error_condition(errc e) noexcept { return {static_cast<int>(e), generic_category()}; }
122 // ErrorCode
124
125NEFORCE_END_NAMESPACE__
126#endif // NEFORCE_CORE_EXCEPTION_ERROR_CONDITION_HPP__
错误类别抽象基类
void assign(int val, const error_category &cat) noexcept
赋值错误条件值和类别
error_condition(errc e) noexcept
从 errc 枚举构造
void clear() noexcept
清空错误条件
const error_category & category() const noexcept
获取错误类别
error_condition() noexcept=default
默认构造函数
string message() const
获取错误描述信息
int value() const noexcept
获取错误条件值
错误类别体系
const error_category & generic_category() noexcept
获取通用错误类别单例
errc
系统错误码枚举
error_condition make_error_condition(errc e) noexcept
从 errc 枚举创建错误条件
相等比较仿函数
可比较对象接口模板