MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / TreeObserver

Method TreeObserver

src/loggers/bt_observer.cpp:8–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6namespace BT
7{
8TreeObserver::TreeObserver(const BT::Tree& tree) : StatusChangeLogger(tree.rootNode())
9{
10 std::function<void(const TreeNode&)> recursiveStep;
11
12 recursiveStep = [&](const TreeNode& node) {
13 if(auto control = dynamic_cast<const ControlNode*>(&node))
14 {
15 for(const auto& child : control->children())
16 {
17 recursiveStep(*child);
18 }
19 }
20 else if(auto decorator = dynamic_cast<const DecoratorNode*>(&node))
21 {
22 if(decorator->type() != NodeType::SUBTREE)
23 {
24 recursiveStep(*decorator->child());
25 }
26 }
27
28 if(_path_to_uid.count(node.fullPath()) != 0)
29 {
30 throw LogicError("TreeObserver not built correctly. Report issue");
31 }
32 _path_to_uid[node.fullPath()] = node.UID();
33 };
34
35 for(const auto& subtree : tree.subtrees)
36 {
37 recursiveStep(*subtree->nodes.front());
38 }
39
40 for(const auto& [path, uid] : _path_to_uid)
41 {
42 _statistics[uid] = {};
43 _uid_to_path[uid] = path;
44 }
45}
46
47TreeObserver::~TreeObserver()
48{}

Callers

nothing calls this directly

Calls 5

LogicErrorClass · 0.85
rootNodeMethod · 0.80
UIDMethod · 0.80
typeMethod · 0.45
childMethod · 0.45

Tested by

no test coverage detected