The Sparta Modeling Framework
Loading...
Searching...
No Matches
TreeNodePrivateAttorney.hpp
1// <TreeNode> -*- C++ -*-
2
3
4#pragma once
5
7
8namespace sparta {
9
20 {
21 public:
26 {
27 return node.getAllChildren_();
28 }
29
34 {
35 sparta_assert(node);
36 return getAllChildren(*node);
37 }
38
44 static TreeNode* getChild(TreeNode* node, const std::string& path,
45 const bool must_exist = false)
46 {
47 return node->getChild_(path, must_exist, true /* private also */);
48 }
49
50 static uint32_t findChildren(TreeNode* node, const std::string& pattern,
51 std::vector<TreeNode*>& results)
52 {
53 return node->findChildren_(pattern, results, true /* allow private */);
54 }
55
59 static bool hasChild(const TreeNode* node, const std::string& path)
60 {
61 return node->hasChild_(path, true /* private also */);
62 }
63
64 template <typename DataT, typename T, void (T::*TMethod)(const DataT&)>
65 static void registerForNotification(TreeNode* node, T* obj,
66 const std::string& name, bool ensure_possible=true)
67 {
68 sparta_assert(node != nullptr);
69 node->registerForNotification_<DataT, T, TMethod>(obj, name,
70 ensure_possible,
71 true /*allow_private*/);
72 }
73 template <typename DataT, typename T, void (T::*TMethod)(const TreeNode&, const TreeNode&, const DataT&)>
74 static void registerForNotification(TreeNode* node, T* obj,
75 const std::string& name,
76 bool ensure_possible=true)
77 {
78 sparta_assert(node != nullptr);
79 node->registerForNotification_<DataT, T, TMethod>(obj, name,
80 ensure_possible,
81 true /*allow_private*/);
82 }
83
84 template <typename DataT, typename T, void (T::*TMethod)(const DataT&)>
85 static void deregisterForNotification(TreeNode* node,
86 T* obj, const std::string& name)
87 {
88 sparta_assert(node != nullptr);
89 node->deregisterForNotification_<DataT, T, TMethod>(obj,
90 name,
91 true /* allow_private */);
92 }
93
94 template <typename DataT, typename T, void (T::*TMethod)(const TreeNode&, const TreeNode&, const DataT&)>
95 static void deregisterForNotification(TreeNode* node,
96 T* obj, const std::string& name)
97 {
98 sparta_assert(node != nullptr);
99 node->deregisterForNotification_<DataT, T, TMethod>(obj,
100 name,
101 true /* allow_private */);
102 }
103 };
104
105} // namespace sparta
106
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Basic Node framework in sparta device tree composite pattern.
static const TreeNode::ChildrenVector & getAllChildren(const TreeNode *node)
static TreeNode * getChild(TreeNode *node, const std::string &path, const bool must_exist=false)
static const TreeNode::ChildrenVector & getAllChildren(const TreeNode &node)
static bool hasChild(const TreeNode *node, const std::string &path)
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
std::vector< TreeNode * > ChildrenVector
Vector of TreeNode children.
Definition TreeNode.hpp:243
Macros for handling exponential backoff.