File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 18
18
* of the source tree.
19
19
*/
20
20
#include " module.h"
21
+
21
22
#include < algorithm>
23
+
22
24
#include < tbox/base/log.h>
23
25
#include < tbox/base/json.hpp>
24
26
@@ -40,11 +42,15 @@ Module::~Module()
40
42
41
43
bool Module::add (Module *child, bool required)
42
44
{
43
- if (state_ != State::kNone )
45
+ if (state_ != State::kNone ) {
46
+ LogWarn (" module %s's state is not State::kNone" , name_.c_str ());
44
47
return false ;
48
+ }
45
49
46
- if (child == nullptr )
50
+ if (child == nullptr ) {
51
+ LogWarn (" child == nullptr" );
47
52
return false ;
53
+ }
48
54
49
55
auto iter = std::find_if (children_.begin (), children_.end (),
50
56
[child] (const ModuleItem &item) {
@@ -55,6 +61,8 @@ bool Module::add(Module *child, bool required)
55
61
return false ;
56
62
57
63
children_.emplace_back (ModuleItem{ child, required });
64
+ child->vars_ .setParent (&vars_);
65
+
58
66
return true ;
59
67
}
60
68
Original file line number Diff line number Diff line change 21
21
#define TBOX_MAIN_MODULE_H_20220326
22
22
23
23
#include < vector>
24
+
24
25
#include < tbox/base/json_fwd.h>
26
+ #include < tbox/util/variables.h>
27
+
25
28
#include " context.h"
26
29
27
30
namespace tbox {
@@ -105,6 +108,7 @@ class Module {
105
108
inline std::string name () const { return name_; }
106
109
inline Context& ctx () const { return ctx_; }
107
110
inline State state () const { return state_; }
111
+ inline util::Variables& vars () { return vars_; }
108
112
109
113
protected:
110
114
// ! 下面的5个虚函数,可由使用者根据需要重写。如果没有操作,就不用重写
@@ -130,6 +134,8 @@ class Module {
130
134
};
131
135
std::vector<ModuleItem> children_;
132
136
State state_ = State::kNone ;
137
+
138
+ util::Variables vars_;
133
139
};
134
140
135
141
}
You can’t perform that action at this time.
0 commit comments