-
Notifications
You must be signed in to change notification settings - Fork 0
/
Status.hxx.in
114 lines (92 loc) · 2.67 KB
/
Status.hxx.in
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
114
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifndef @KWSYS_NAMESPACE@_Status_hxx
#define @KWSYS_NAMESPACE@_Status_hxx
#include <@KWSYS_NAMESPACE@/Configure.hxx>
#include <string>
/*
* Detect a symbol collision with the name of this class. X11 headers use
* `#define Status int` instead of using `typedef` which poisons any other
* usage of this name.
*/
#if defined(Status) && defined(_X11_XLIB_H_)
# error \
"Status.hxx must be included *before* any X11 headers to avoid a collision with the `Status` define that is made in its API."
#endif
namespace @KWSYS_NAMESPACE@ {
/** \class Status
* \brief OS-specific status of a system operation.
*/
class @KWSYS_NAMESPACE@_EXPORT Status
{
public:
enum class Kind
{
Success,
POSIX,
#ifdef _WIN32
Windows,
#endif
};
/** Construct with kind "Success". */
Status() = default;
/** Construct with kind "Success". */
static Status Success() { return Status(); }
/** Construct with kind "POSIX" using given errno-style value. */
static Status POSIX(int e)
{
Status s(Kind::POSIX);
s.POSIX_ = e;
return s;
}
/** Construct with kind "POSIX" using errno. */
static Status POSIX_errno();
#ifdef _WIN32
/** Construct with kind "Windows" using given GetLastError()-style value. */
static Status Windows(unsigned int e)
{
Status s(Kind::Windows);
s.Windows_ = e;
return s;
}
/** Construct with kind "Windows" using GetLastError(). */
static Status Windows_GetLastError();
#endif
/** Return true on "Success", false otherwise. */
bool IsSuccess() const { return this->Kind_ == Kind::Success; }
/** Return true on "Success", false otherwise. */
explicit operator bool() const { return this->IsSuccess(); }
/** Return the kind of status. */
Kind GetKind() const { return this->Kind_; }
/** If the kind is "POSIX", returns the errno-style value.
Otherwise, returns 0. */
int GetPOSIX() const
{
return this->Kind_ == Kind::POSIX ? this->POSIX_ : 0;
}
#ifdef _WIN32
/** If the kind is "Windows", returns the GetLastError()-style value.
Otherwise, returns 0. */
unsigned int GetWindows() const
{
return this->Kind_ == Kind::Windows ? this->Windows_ : 0;
}
#endif
/** Return a human-readable description of the status. */
std::string GetString() const;
private:
Status(Kind kind)
: Kind_(kind)
{
}
Kind Kind_ = Kind::Success;
union
{
int POSIX_;
#ifdef _WIN32
unsigned int Windows_;
#endif
};
};
} // namespace @KWSYS_NAMESPACE@
#endif