| 6 | namespace BT |
| 7 | { |
| 8 | TreeObserver::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 | |
| 47 | TreeObserver::~TreeObserver() |
| 48 | {} |
nothing calls this directly
no test coverage detected