Skip to content

Commit 2341397

Browse files
authored
feat: add template specialization for convertFromString deque (#628)
1 parent 95d9d6d commit 2341397

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

include/behaviortree_cpp/decorators/loop_node.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,30 @@ class LoopNode : public DecoratorNode
121121
}
122122
};
123123

124+
template <> inline
125+
SharedQueue<int> convertFromString<SharedQueue<int>>(StringView str)
126+
{
127+
auto parts = splitString(str, ';');
128+
SharedQueue<int> output = std::make_shared<std::deque<int>>();
129+
for (const StringView& part : parts)
130+
{
131+
output->push_back(convertFromString<int>(part));
132+
}
133+
return output;
134+
}
135+
136+
template <> inline
137+
SharedQueue<bool> convertFromString<SharedQueue<bool>>(StringView str)
138+
{
139+
auto parts = splitString(str, ';');
140+
SharedQueue<bool> output = std::make_shared<std::deque<bool>>();
141+
for (const StringView& part : parts)
142+
{
143+
output->push_back(convertFromString<bool>(part));
144+
}
145+
return output;
146+
}
147+
124148
template <> inline
125149
SharedQueue<double> convertFromString<SharedQueue<double>>(StringView str)
126150
{
@@ -133,5 +157,17 @@ SharedQueue<double> convertFromString<SharedQueue<double>>(StringView str)
133157
return output;
134158
}
135159

160+
template <> inline
161+
SharedQueue<std::string> convertFromString<SharedQueue<std::string>>(StringView str)
162+
{
163+
auto parts = splitString(str, ';');
164+
SharedQueue<std::string> output = std::make_shared<std::deque<std::string>>();
165+
for (const StringView& part : parts)
166+
{
167+
output->push_back(convertFromString<std::string>(part));
168+
}
169+
return output;
170+
}
171+
136172

137173
} // namespace BT

src/bt_factory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ BehaviorTreeFactory::BehaviorTreeFactory():
9191
registerNodeType<SwitchNode<5>>("Switch5");
9292
registerNodeType<SwitchNode<6>>("Switch6");
9393

94+
registerNodeType<LoopNode<int>>("LoopInt");
95+
registerNodeType<LoopNode<bool>>("LoopBool");
9496
registerNodeType<LoopNode<double>>("LoopDouble");
9597
registerNodeType<LoopNode<std::string>>("LoopString");
9698

0 commit comments

Comments
 (0)