-
Notifications
You must be signed in to change notification settings - Fork 0
/
act_utils.h
110 lines (92 loc) · 1.55 KB
/
act_utils.h
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
#pragma once
#include <string>
namespace Act
{
namespace Platform
{
void ErrorMessageBox(std::string msg);
};
namespace StringFormat
{
template <typename T, typename... TR>
inline std::string Join(T first, TR... rest)
{
std::string ret;
ret += first;
ret += Join(rest...);
return ret;
}
inline std::string Join()
{
return std::string();
}
template <typename... T>
inline std::string Line(T... values)
{
return Join(values...) + "\n";
}
template <typename... T>
inline std::string IntentLine(T... values)
{
return std::string(" ") + Line(values...);
}
template <typename... T>
inline std::string JoinLines(T... values)
{
std::string ret = Join(values...);
if (ret.back() == '\n')
{
ret.resize(ret.size() - 1);
}
return ret;
}
}
class Task
{
public:
Task() :
Task(std::string())
{
}
Task(std::string msg)
{
this->msg = msg;
this->parent = GetLastTask();
PushTask();
}
void Error(std::string msg)
{
using namespace StringFormat;
Platform::ErrorMessageBox(JoinLines(
Line("Error: ", msg),
Line("In task: ", this->msg)
));
throw std::exception();
}
static void SendError(std::string msg)
{
GetLastTask()->Error(msg);
}
private:
std::string msg;
Task* parent;
private:
void PushTask()
{
GetStatic() = this;
}
void PopTask()
{
GetStatic() = parent;
}
static Task* GetLastTask()
{
return GetStatic();
}
static inline Task*& GetStatic()
{
static Task* val = nullptr;
return val;
}
};
}