-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresult.h
More file actions
71 lines (57 loc) · 1.02 KB
/
result.h
File metadata and controls
71 lines (57 loc) · 1.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
#pragma once
#include <string>
#include <cstdio>
#include <stdarg.h>
class Result
{
public:
Result()
: status(true)
{
}
Result(bool status)
: status(status)
{
}
Result(bool status, const std::string& error)
: status(status),
error(error)
{
}
Result(bool status, const char* fmt, ...)
: status(status)
{
va_list args;
char buffer[BUFSIZ];
va_start(args,fmt);
vsnprintf(buffer, sizeof(buffer), fmt, args);
va_end(args);
error = buffer;
}
Result(const Result& rhs)
: status(rhs.status),
error(rhs.error)
{
}
Result& operator=(const Result& rhs)
{
status = rhs.status;
error = rhs.error;
return *this;
}
operator bool() const
{
return status;
}
bool getStatus() const
{
return status;
}
const std::string& getError() const
{
return error;
}
protected:
bool status;
std::string error;
};