File tree 4 files changed +39
-1
lines changed
4 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,10 @@ TEST(ToGraphviz, ActionJson) {
41
41
42
42
auto seq_action = new SequenceAction (*loop);
43
43
seq_action->set_label (" This is test" );
44
+ seq_action->vars ().define (" seq.value" , 12 );
44
45
auto if_else_action = new IfElseAction (*loop);
46
+ if_else_action->vars ().define (" if_else.name" , " hello" );
47
+ if_else_action->vars ().define (" if_else.value" , 100 );
45
48
if_else_action->setChildAs (new SuccAction (*loop), " if" );
46
49
if_else_action->setChildAs (new FunctionAction (*loop, []{return true ;}), " succ" );
47
50
if_else_action->setChildAs (new FunctionAction (*loop, []{return true ;}), " fail" );
Original file line number Diff line number Diff line change 23
23
#include < map>
24
24
#include < tbox/base/defines.h>
25
25
#include < tbox/base/json_fwd.h>
26
+ #include < tbox/util/json.h>
26
27
27
28
namespace tbox {
28
29
namespace util {
@@ -78,6 +79,15 @@ class Variables {
78
79
*/
79
80
bool get (const std::string &name, Json &js_out_value, bool local_only = false ) const ;
80
81
82
+ // ! 获取变量的模板
83
+ template <typename T>
84
+ bool get (const std::string &name, T &out_value, bool local_only = false ) const {
85
+ Json js;
86
+ if (get (name, js, local_only))
87
+ return json::Get (js, out_value);
88
+ return false ;
89
+ }
90
+
81
91
/* *
82
92
* 更新变量
83
93
*
Original file line number Diff line number Diff line change @@ -42,6 +42,31 @@ TEST(Variables, Base) {
42
42
EXPECT_FALSE (vars.has (" a" ));
43
43
}
44
44
45
+ TEST (Variables, GetTemplate) {
46
+ Variables vars;
47
+
48
+ EXPECT_TRUE (vars.define (" b" , true ));
49
+ EXPECT_TRUE (vars.define (" i" , 12 ));
50
+ EXPECT_TRUE (vars.define (" s" , " hello" ));
51
+ EXPECT_TRUE (vars.define (" d" , 12.345 ));
52
+
53
+ bool b = false ;
54
+ int i = 0 ;
55
+ std::string s;
56
+ double d = 0 ;
57
+
58
+ EXPECT_TRUE (vars.get (" b" , b));
59
+ EXPECT_TRUE (vars.get (" i" , i));
60
+ EXPECT_TRUE (vars.get (" s" , s));
61
+ EXPECT_TRUE (vars.get (" d" , d));
62
+ EXPECT_FALSE (vars.get (" s" , d));
63
+
64
+ EXPECT_TRUE (b);
65
+ EXPECT_EQ (i, 12 );
66
+ EXPECT_EQ (s, " hello" );
67
+ EXPECT_DOUBLE_EQ (d, 12.345 );
68
+ }
69
+
45
70
TEST (Variables, RepeatDefine) {
46
71
Variables vars;
47
72
EXPECT_TRUE (vars.define (" a" , 12 ));
Original file line number Diff line number Diff line change 21
21
# TBOX版本号
22
22
TBOX_VERSION_MAJOR := 1
23
23
TBOX_VERSION_MINOR := 11
24
- TBOX_VERSION_REVISION := 7
24
+ TBOX_VERSION_REVISION := 8
You can’t perform that action at this time.
0 commit comments