Skip to content

Commit a3ce94f

Browse files
committed
minor changes
1 parent 3633e27 commit a3ce94f

File tree

4 files changed

+49
-50
lines changed

4 files changed

+49
-50
lines changed

include/behaviortree_cpp/controls/try_catch_node.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ class TryCatchNode : public ControlNode
5656
"the node is halted during the try-block") };
5757
}
5858

59-
virtual void halt() override;
59+
void halt() override;
6060

6161
private:
62-
size_t current_child_idx_;
63-
size_t skipped_count_;
64-
bool in_catch_;
62+
size_t current_child_idx_ = 0;
63+
size_t skipped_count_ = 0;
64+
bool in_catch_ = false;
6565

66-
virtual BT::NodeStatus tick() override;
66+
BT::NodeStatus tick() override;
6767
};
6868

6969
} // namespace BT

src/blackboard.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void Blackboard::debugMessage() const
105105
{
106106
// Lock storage_mutex_ (shared) to prevent iterator invalidation from
107107
// concurrent modifications (BUG-5 fix).
108-
const std::shared_lock<std::shared_mutex> storage_lock(storage_mutex_);
108+
const std::shared_lock storage_lock(storage_mutex_);
109109
for(const auto& [key, entry] : storage_)
110110
{
111111
auto port_type = entry->info.type();
@@ -141,7 +141,7 @@ std::vector<StringView> Blackboard::getKeys() const
141141
{
142142
// Lock storage_mutex_ (shared) to prevent iterator invalidation and
143143
// dangling StringView from concurrent modifications (BUG-6 fix).
144-
const std::shared_lock<std::shared_mutex> storage_lock(storage_mutex_);
144+
const std::shared_lock storage_lock(storage_mutex_);
145145
if(storage_.empty())
146146
{
147147
return {};
@@ -157,7 +157,7 @@ std::vector<StringView> Blackboard::getKeys() const
157157

158158
void Blackboard::clear()
159159
{
160-
const std::unique_lock<std::shared_mutex> storage_lock(storage_mutex_);
160+
const std::unique_lock storage_lock(storage_mutex_);
161161
storage_.clear();
162162
}
163163

@@ -198,8 +198,8 @@ void Blackboard::cloneInto(Blackboard& dst) const
198198

199199
// Step 1: snapshot src/dst entries under both storage_mutex_ locks.
200200
{
201-
std::shared_lock<std::shared_mutex> lk1(storage_mutex_, std::defer_lock);
202-
std::unique_lock<std::shared_mutex> lk2(dst.storage_mutex_, std::defer_lock);
201+
std::shared_lock lk1(storage_mutex_, std::defer_lock);
202+
std::unique_lock lk2(dst.storage_mutex_, std::defer_lock);
203203
std::lock(lk1, lk2);
204204

205205
std::unordered_set<std::string> dst_keys;
@@ -258,10 +258,10 @@ void Blackboard::cloneInto(Blackboard& dst) const
258258
// Step 3: insert new entries and remove stale ones under dst.storage_mutex_.
259259
if(!new_entries.empty() || !keys_to_remove.empty())
260260
{
261-
const std::unique_lock<std::shared_mutex> dst_lock(dst.storage_mutex_);
261+
const std::unique_lock dst_lock(dst.storage_mutex_);
262262
for(auto& [key, entry] : new_entries)
263263
{
264-
dst.storage_.insert({ key, std::move(entry) });
264+
dst.storage_.try_emplace(key, std::move(entry));
265265
}
266266
for(const auto& key : keys_to_remove)
267267
{
@@ -282,7 +282,7 @@ Blackboard::Ptr Blackboard::parent()
282282
std::shared_ptr<Blackboard::Entry> Blackboard::createEntryImpl(const std::string& key,
283283
const TypeInfo& info)
284284
{
285-
const std::unique_lock<std::shared_mutex> storage_lock(storage_mutex_);
285+
const std::unique_lock storage_lock(storage_mutex_);
286286
// This function might be called recursively, when we do remapping, because we move
287287
// to the top scope to find already existing entries
288288

src/controls/try_catch_node.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ namespace BT
1616
{
1717
TryCatchNode::TryCatchNode(const std::string& name, const NodeConfig& config)
1818
: ControlNode::ControlNode(name, config)
19-
, current_child_idx_(0)
20-
, skipped_count_(0)
21-
, in_catch_(false)
2219
{
2320
setRegistrationID("TryCatch");
2421
}

src/xml_parsing.cpp

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,46 @@ void validateInstanceName(const std::string& name, int line_number)
181181
}
182182
}
183183

184-
} // namespace
185-
186184
struct SubtreeModel
187185
{
188186
std::unordered_map<std::string, BT::PortInfo> ports;
189187
};
190188

189+
void parseSubtreeModelPorts(const XMLElement* sub_node, SubtreeModel& subtree_model)
190+
{
191+
const std::pair<const char*, PortDirection> port_types[3] = {
192+
{ "input_port", PortDirection::INPUT },
193+
{ "output_port", PortDirection::OUTPUT },
194+
{ "inout_port", PortDirection::INOUT }
195+
};
196+
197+
for(const auto& [name, direction] : port_types)
198+
{
199+
for(auto port_node = sub_node->FirstChildElement(name); port_node != nullptr;
200+
port_node = port_node->NextSiblingElement(name))
201+
{
202+
PortInfo port(direction);
203+
auto port_name = port_node->Attribute("name");
204+
if(port_name == nullptr)
205+
{
206+
throw RuntimeError("Missing attribute [name] in port (SubTree model)");
207+
}
208+
validatePortName(port_name, port_node->GetLineNum());
209+
if(auto default_value = port_node->Attribute("default"))
210+
{
211+
port.setDefaultValue(default_value);
212+
}
213+
if(auto description = port_node->Attribute("description"))
214+
{
215+
port.setDescription(description);
216+
}
217+
subtree_model.ports[port_name] = std::move(port);
218+
}
219+
}
220+
}
221+
222+
} // namespace
223+
191224
struct XMLParser::PImpl
192225
{
193226
TreeNode::Ptr createNodeFromXML(const XMLElement* element,
@@ -298,38 +331,7 @@ void BT::XMLParser::PImpl::loadSubtreeModel(const XMLElement* xml_root)
298331
throw RuntimeError("Missing attribute 'ID' in SubTree element "
299332
"within TreeNodesModel");
300333
}
301-
auto& subtree_model = subtree_models[subtree_id];
302-
303-
const std::pair<const char*, BT::PortDirection> port_types[3] = {
304-
{ "input_port", BT::PortDirection::INPUT },
305-
{ "output_port", BT::PortDirection::OUTPUT },
306-
{ "inout_port", BT::PortDirection::INOUT }
307-
};
308-
309-
for(const auto& [name, direction] : port_types)
310-
{
311-
for(auto port_node = sub_node->FirstChildElement(name); port_node != nullptr;
312-
port_node = port_node->NextSiblingElement(name))
313-
{
314-
BT::PortInfo port(direction);
315-
auto port_name = port_node->Attribute("name");
316-
if(port_name == nullptr)
317-
{
318-
throw RuntimeError("Missing attribute [name] in port (SubTree model)");
319-
}
320-
// Validate port name
321-
validatePortName(port_name, port_node->GetLineNum());
322-
if(auto default_value = port_node->Attribute("default"))
323-
{
324-
port.setDefaultValue(default_value);
325-
}
326-
if(auto description = port_node->Attribute("description"))
327-
{
328-
port.setDescription(description);
329-
}
330-
subtree_model.ports[port_name] = std::move(port);
331-
}
332-
}
334+
parseSubtreeModelPorts(sub_node, subtree_models[subtree_id]);
333335
}
334336
}
335337
}

0 commit comments

Comments
 (0)