-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLib.cpp
More file actions
113 lines (94 loc) Β· 2.02 KB
/
Lib.cpp
File metadata and controls
113 lines (94 loc) Β· 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "Lib.h"
namespace Heresy
{
bool testFunction(int i, std::error_code& ec)
{
if (i < 4)
ec = error::TooSmall;
else if (i > 128)
ec = error::TooLarge;
else if( i % 2)
ec = error::Invaild;
else
{
ec = error::Success;
return true;
}
return false;
}
class ErrorCategory : public std::error_category
{
public:
std::string message(int c) const override
{
switch (static_cast<error>(c))
{
case error::Success:
return "Success";
case error::TooLarge:
return "Value too large";
case error::TooSmall:
return "Value too small";
case error::Invaild:
return "Not a multiple of 2";
default:
return "Undefined";
}
}
const char* name() const noexcept override
{
return "Error code category";
}
public:
static const std::error_category& get()
{
const static ErrorCategory sCategory;
return sCategory;
}
};
class ErrcCategory : public std::error_category
{
public:
std::string message(int c) const override
{
return "API error";
}
const char* name() const noexcept override
{
return "Error condition category";
}
bool equivalent(const std::error_code& ec, int c) const noexcept override
{
switch (static_cast<errc>(c))
{
case errc::OutOfRange:
return (ec == error::TooLarge || ec == error::TooSmall);
case errc::InvaildInput:
return (ec == error::Invaild);
}
return false;
}
public:
static const std::error_category& get()
{
const static ErrcCategory sCategory;
return sCategory;
}
};
std::error_code make_error_code(error ec)
{
return std::error_code(static_cast<int>(ec), ErrorCategory::get());
}
std::error_condition make_error_condition(error ec)
{
return std::error_condition(static_cast<int>(ec), ErrorCategory::get());
}
std::error_code make_error_code(errc ec)
{
return std::error_code(static_cast<int>(ec), ErrcCategory::get());
}
std::error_condition make_error_condition(errc ec)
{
return std::error_condition(static_cast<int>(ec), ErrcCategory::get());
}
}