@@ -34,18 +34,18 @@ IfElseAction::IfElseAction(event::Loop &loop)
3434
3535IfElseAction::~IfElseAction () {
3636 CHECK_DELETE_RESET_OBJ (if_action_);
37- CHECK_DELETE_RESET_OBJ (succ_action_ );
38- CHECK_DELETE_RESET_OBJ (fail_action_ );
37+ CHECK_DELETE_RESET_OBJ (then_action_ );
38+ CHECK_DELETE_RESET_OBJ (else_action_ );
3939}
4040
4141void IfElseAction::toJson (Json &js) const {
4242 AssembleAction::toJson (js);
4343 auto &js_children = js[" children" ];
4444 if_action_->toJson (js_children[" 0.if" ]);
45- if (succ_action_ != nullptr )
46- succ_action_ ->toJson (js_children[" 1.succ" ]);
47- if (fail_action_ != nullptr )
48- fail_action_ ->toJson (js_children[" 2.fail" ]);
45+ if (then_action_ != nullptr )
46+ then_action_ ->toJson (js_children[" 1.succ" ]);
47+ if (else_action_ != nullptr )
48+ else_action_ ->toJson (js_children[" 2.fail" ]);
4949}
5050
5151bool IfElseAction::setChildAs (Action *child, const std::string &role) {
@@ -59,23 +59,23 @@ bool IfElseAction::setChildAs(Action *child, const std::string &role) {
5959 }
6060 return true ;
6161
62- } else if (role == " succ" ) {
63- CHECK_DELETE_RESET_OBJ (succ_action_ );
64- succ_action_ = child;
65- if (succ_action_ != nullptr ) {
66- succ_action_ ->setFinishCallback (std::bind (&IfElseAction::finish, this , _1, _2, _3));
67- succ_action_ ->setBlockCallback (std::bind (&IfElseAction::block, this , _1, _2));
68- succ_action_ ->setParent (this );
62+ } else if (role == " succ" || role == " then " ) {
63+ CHECK_DELETE_RESET_OBJ (then_action_ );
64+ then_action_ = child;
65+ if (then_action_ != nullptr ) {
66+ then_action_ ->setFinishCallback (std::bind (&IfElseAction::finish, this , _1, _2, _3));
67+ then_action_ ->setBlockCallback (std::bind (&IfElseAction::block, this , _1, _2));
68+ then_action_ ->setParent (this );
6969 }
7070 return true ;
7171
72- } else if (role == " fail" ) {
73- CHECK_DELETE_RESET_OBJ (fail_action_ );
74- fail_action_ = child;
75- if (fail_action_ != nullptr ) {
76- fail_action_ ->setFinishCallback (std::bind (&IfElseAction::finish, this , _1, _2, _3));
77- fail_action_ ->setBlockCallback (std::bind (&IfElseAction::block, this , _1, _2));
78- fail_action_ ->setParent (this );
72+ } else if (role == " fail" || role == " else " ) {
73+ CHECK_DELETE_RESET_OBJ (else_action_ );
74+ else_action_ = child;
75+ if (else_action_ != nullptr ) {
76+ else_action_ ->setFinishCallback (std::bind (&IfElseAction::finish, this , _1, _2, _3));
77+ else_action_ ->setBlockCallback (std::bind (&IfElseAction::block, this , _1, _2));
78+ else_action_ ->setParent (this );
7979 }
8080 return true ;
8181 }
@@ -90,14 +90,14 @@ bool IfElseAction::isReady() const {
9090 return false ;
9191 }
9292
93- if (!succ_action_ && !fail_action_ ) {
93+ if (!then_action_ && !else_action_ ) {
9494 LogWarn (" %d:%s[%s] both succ and fail func is null" , id (), type ().c_str (), label ().c_str ());
9595 return false ;
9696 }
9797
9898 if ((!if_action_->isReady ()) ||
99- (succ_action_ != nullptr && !succ_action_ ->isReady ()) ||
100- (fail_action_ != nullptr && !fail_action_ ->isReady ()))
99+ (then_action_ != nullptr && !then_action_ ->isReady ()) ||
100+ (else_action_ != nullptr && !else_action_ ->isReady ()))
101101 return false ;
102102
103103 return true ;
@@ -114,9 +114,9 @@ void IfElseAction::onStop() {
114114 TBOX_ASSERT (if_action_ != nullptr );
115115 if (if_action_->state () == State::kFinished ) {
116116 if (if_action_->result () == Result::kSuccess ) {
117- succ_action_ ->stop ();
117+ then_action_ ->stop ();
118118 } else {
119- fail_action_ ->stop ();
119+ else_action_ ->stop ();
120120 }
121121 } else {
122122 if_action_->stop ();
@@ -129,9 +129,9 @@ void IfElseAction::onPause() {
129129 TBOX_ASSERT (if_action_ != nullptr );
130130 if (if_action_->state () == State::kFinished ) {
131131 if (if_action_->result () == Result::kSuccess ) {
132- succ_action_ ->pause ();
132+ then_action_ ->pause ();
133133 } else {
134- fail_action_ ->pause ();
134+ else_action_ ->pause ();
135135 }
136136 } else {
137137 if_action_->pause ();
@@ -146,16 +146,16 @@ void IfElseAction::onResume() {
146146 TBOX_ASSERT (if_action_ != nullptr );
147147 if (if_action_->state () == State::kFinished ) {
148148 if (if_action_->result () == Result::kSuccess ) {
149- if (succ_action_ ->state () == State::kFinished ) {
150- finish (succ_action_ ->result () == Result::kSuccess );
149+ if (then_action_ ->state () == State::kFinished ) {
150+ finish (then_action_ ->result () == Result::kSuccess );
151151 } else {
152- succ_action_ ->resume ();
152+ then_action_ ->resume ();
153153 }
154154 } else {
155- if (fail_action_ ->state () == State::kFinished ) {
156- finish (fail_action_ ->result () == Result::kSuccess );
155+ if (else_action_ ->state () == State::kFinished ) {
156+ finish (else_action_ ->result () == Result::kSuccess );
157157 } else {
158- fail_action_ ->resume ();
158+ else_action_ ->resume ();
159159 }
160160 }
161161 } else {
@@ -167,25 +167,25 @@ void IfElseAction::onReset() {
167167 TBOX_ASSERT (if_action_ != nullptr );
168168 if_action_->reset ();
169169
170- if (succ_action_ != nullptr )
171- succ_action_ ->reset ();
170+ if (then_action_ != nullptr )
171+ then_action_ ->reset ();
172172
173- if (fail_action_ != nullptr )
174- fail_action_ ->reset ();
173+ if (else_action_ != nullptr )
174+ else_action_ ->reset ();
175175
176176 AssembleAction::onReset ();
177177}
178178
179179void IfElseAction::onCondActionFinished (bool is_succ, const Reason &why, const Trace &trace) {
180180 if (state () == State::kRunning ) {
181181 if (is_succ) {
182- if (succ_action_ != nullptr ) {
183- succ_action_ ->start ();
182+ if (then_action_ != nullptr ) {
183+ then_action_ ->start ();
184184 return ;
185185 }
186186 } else {
187- if (fail_action_ != nullptr ) {
188- fail_action_ ->start ();
187+ if (else_action_ != nullptr ) {
188+ else_action_ ->start ();
189189 return ;
190190 }
191191 }
0 commit comments