@@ -30,18 +30,6 @@ class Py_SyncActionNode : public SyncActionNode
30
30
py::gil_scoped_acquire gil;
31
31
return py::get_overload (this , " tick" )().cast <NodeStatus>();
32
32
}
33
-
34
- py::object Py_getInput (const std::string& name)
35
- {
36
- py::object obj;
37
- getInput (name, obj);
38
- return obj;
39
- }
40
-
41
- void Py_setOutput (const std::string& name, const py::object& value)
42
- {
43
- setOutput (name, value);
44
- }
45
33
};
46
34
47
35
class Py_StatefulActionNode final : public StatefulActionNode
@@ -68,21 +56,21 @@ class Py_StatefulActionNode final : public StatefulActionNode
68
56
py::gil_scoped_acquire gil;
69
57
py::get_overload (this , " on_halted" )();
70
58
}
59
+ };
71
60
72
- // TODO: Share these duplicated methods with other node types.
73
- py::object Py_getInput (const std::string& name)
74
- {
75
- py::object obj;
76
- getInput (name, obj);
77
- return obj;
78
- }
61
+ template < typename T>
62
+ py::object Py_getInput (const T& node, const std::string& name)
63
+ {
64
+ py::object obj;
65
+ node. getInput (name, obj);
66
+ return obj;
67
+ }
79
68
80
- // TODO: Share these duplicated methods with other node types.
81
- void Py_setOutput (const std::string& name, const py::object& value)
82
- {
83
- setOutput (name, value);
84
- }
85
- };
69
+ template <typename T>
70
+ void Py_setOutput (T& node, const std::string& name, const py::object& value)
71
+ {
72
+ node.setOutput (name, value);
73
+ }
86
74
87
75
// Add a conversion specialization from string values into general py::objects
88
76
// by evaluating as a Python expression.
@@ -190,17 +178,17 @@ PYBIND11_MODULE(btpy_cpp, m)
190
178
191
179
py::class_<Py_SyncActionNode>(m, " SyncActionNode" )
192
180
.def (py::init<const std::string&, const NodeConfig&>())
193
- .def (" tick " , &Py_SyncActionNode::tick )
194
- .def (" get_input " , &Py_SyncActionNode::Py_getInput )
195
- .def (" set_output " , &Py_SyncActionNode::Py_setOutput );
181
+ .def (" get_input " , &Py_getInput< Py_SyncActionNode> )
182
+ .def (" set_output " , &Py_setOutput< Py_SyncActionNode> )
183
+ .def (" tick " , &Py_SyncActionNode::tick );
196
184
197
185
py::class_<Py_StatefulActionNode>(m, " StatefulActionNode" )
198
186
.def (py::init<const std::string&, const NodeConfig&>())
187
+ .def (" get_input" , &Py_getInput<Py_StatefulActionNode>)
188
+ .def (" set_output" , &Py_setOutput<Py_StatefulActionNode>)
199
189
.def (" on_start" , &Py_StatefulActionNode::onStart)
200
190
.def (" on_running" , &Py_StatefulActionNode::onRunning)
201
- .def (" on_halted" , &Py_StatefulActionNode::onHalted)
202
- .def (" get_input" , &Py_StatefulActionNode::Py_getInput)
203
- .def (" set_output" , &Py_StatefulActionNode::Py_setOutput);
191
+ .def (" on_halted" , &Py_StatefulActionNode::onHalted);
204
192
}
205
193
206
194
} // namespace BT
0 commit comments