@@ -137,6 +137,7 @@ void BuildNodes(TerminalNodes &term, Loop *wp_loop)
137137
138138 term.mountNode (dir1_1_token, term.rootNode (), " root" ); // ! 循环引用
139139
140+ // ! 演示使用 AddFuncNode() 函数直接添加函数结点
140141 auto add_func_dir_node = term.createDirNode ();
141142 term.mountNode (term.rootNode (), add_func_dir_node, " add_func" );
142143
@@ -145,4 +146,44 @@ void BuildNodes(TerminalNodes &term, Loop *wp_loop)
145146 AddFuncNode (term, add_func_dir_node, " int_value" , int_value, 0 , 100 );
146147 AddFuncNode (term, add_func_dir_node, " double_value" , double_value, 0 , 1 );
147148 AddFuncNode (term, add_func_dir_node, " str_value" , str_value);
149+
150+ // ! 演示使用 XxxxxFuncNodeProfile 来添加函数结点
151+ auto profile_func_dir_node = term.createDirNode ();
152+ term.mountNode (term.rootNode (), profile_func_dir_node, " profile_func" );
153+
154+ {
155+ BooleanFuncNodeProfile profile;
156+ profile.set_func = [&] (bool value) { bool_value = value; return true ; };
157+ profile.get_func = [&] () { return bool_value; };
158+
159+ AddFuncNode (term, profile_func_dir_node, " bool_value" , profile);
160+ }
161+
162+ {
163+ StringFuncNodeProfile profile;
164+ profile.set_func = [&] (const std::string &value) { str_value = value; return true ; };
165+ profile.get_func = [&] () { return str_value; };
166+
167+ AddFuncNode (term, profile_func_dir_node, " str_value" , profile);
168+ }
169+
170+ {
171+ IntegerFuncNodeProfile profile;
172+ profile.set_func = [&] (int value) { int_value = value; return true ; };
173+ profile.get_func = [&] () { return int_value; };
174+ profile.min_value = 1 ;
175+ profile.max_value = 5 ;
176+
177+ AddFuncNode (term, profile_func_dir_node, " int_value" , profile);
178+ }
179+
180+ {
181+ DoubleFuncNodeProfile profile;
182+ profile.set_func = [&] (double value) { double_value = value; return true ; };
183+ profile.get_func = [&] () { return double_value; };
184+ profile.min_value = -1 ;
185+ profile.max_value = 1 ;
186+
187+ AddFuncNode (term, profile_func_dir_node, " double_value" , profile);
188+ }
148189}
0 commit comments