forked from ChunelFeng/CGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGAspectManager.cpp
More file actions
125 lines (97 loc) · 2.93 KB
/
GAspectManager.cpp
File metadata and controls
125 lines (97 loc) · 2.93 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
114
115
116
117
118
119
120
121
122
123
124
125
/***************************
@Author: Chunel
@Contact: chunel@foxmail.com
@File: GAspectManager.cpp
@Time: 2023/12/29 19:45
@Desc:
***************************/
#include "GAspectManager.h"
CGRAPH_NAMESPACE_BEGIN
GAspectManager::GAspectManager() {
aspect_arr_ = {};
}
GAspectManager::~GAspectManager() {
clear();
}
CStatus GAspectManager::reflect(const GAspectType &type,
const CStatus &curStatus) {
CGRAPH_FUNCTION_BEGIN
for (GAspectPtr aspect : aspect_arr_) {
switch (type) {
/**
* 仅针对Begin对应的内容,进行返回值判断
* run()方法切面更容易被执行,故放在最前方判断
*/
case GAspectType::BEGIN_RUN :
status = aspect->beginRun();
break;
case GAspectType::FINISH_RUN :
aspect->finishRun(curStatus);
break;
case GAspectType::BEGIN_INIT :
status = aspect->beginInit();
break;
case GAspectType::FINISH_INIT :
aspect->finishInit(curStatus);
break;
case GAspectType::BEGIN_DESTROY :
status = aspect->beginDestroy();
break;
case GAspectType::FINISH_DESTROY :
aspect->finishDestroy(curStatus);
break;
case GAspectType::ENTER_CRASHED :
aspect->enterCrashed();
break;
default:
status = CErrStatus("unknown aspect type");
}
CGRAPH_FUNCTION_CHECK_STATUS
}
CGRAPH_FUNCTION_END
}
CStatus GAspectManager::add(GAspectPtr aspect) {
CGRAPH_FUNCTION_BEGIN CGRAPH_ASSERT_NOT_NULL(aspect)
aspect_arr_.emplace_back(aspect);
CGRAPH_FUNCTION_END
}
GAspectManager *GAspectManager::setName(const std::string &name) {
for (GAspectPtr aspect : aspect_arr_) {
CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(aspect)
aspect->setName(name);
}
return this;
}
CSize GAspectManager::getSize() const {
auto size = aspect_arr_.size();
return size;
}
CStatus GAspectManager::clear() {
CGRAPH_FUNCTION_BEGIN
for (GAspectPtr aspect: aspect_arr_) {
CGRAPH_DELETE_PTR(aspect)
}
aspect_arr_.clear();
CGRAPH_FUNCTION_END
}
CStatus GAspectManager::popLast() {
CGRAPH_FUNCTION_BEGIN
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(0 == getSize(), "no aspect to pop")
auto *last = aspect_arr_.back();
CGRAPH_DELETE_PTR(last);
aspect_arr_.pop_back(); // 弹出最后一个
CGRAPH_FUNCTION_END
}
CVoidPtr GAspectManager::setGParamManager(GParamManagerPtr pm) {
for (auto *cur: aspect_arr_) {
cur->setGParamManager(pm);
}
return this;
}
CVoidPtr GAspectManager::setGEventManager(GEventManagerPtr em) {
for (auto *cur : aspect_arr_) {
cur->setGEventManager(em);
}
return this;
}
CGRAPH_NAMESPACE_END