10 #ifndef COMPWA_FUNCTIONTREE_TREENODE_HPP_ 11 #define COMPWA_FUNCTIONTREE_TREENODE_HPP_ 22 namespace FunctionTree {
35 class TreeNode :
public std::enable_shared_from_this<TreeNode>,
40 TreeNode(std::shared_ptr<Strategy> strategy);
44 std::shared_ptr<Strategy> strategy =
nullptr);
50 void addNode(std::shared_ptr<TreeNode> node);
51 void addNodes(std::vector<std::shared_ptr<TreeNode>> nodes);
52 void addParent(std::weak_ptr<TreeNode> node);
66 std::shared_ptr<TreeNode> p) {
67 return os << p->print(-1);
73 std::string
print(
int level = -1, std::string prefix =
"");
77 std::vector<std::weak_ptr<TreeNode>>
Parents;
90 std::shared_ptr<Strategy>
Strat;
94 std::shared_ptr<ComPWA::FunctionTree::Parameter>
recalculate();
100 template <
typename T,
101 typename = std::enable_if_t<
102 (std::is_same<int, T>::value || std::is_same<double, T>::value ||
103 std::is_same<std::complex<double>, T>::value ||
104 std::is_same<std::vector<int>, T>::value ||
105 std::is_same<std::vector<double>, T>::value ||
106 std::is_same<std::vector<std::complex<double>>, T>::value)>>
107 std::shared_ptr<TreeNode>
createLeaf(
const T &value, std::string name =
"") {
109 std::make_shared<TreeNode>(std::make_shared<Value<T>>(name, value));
void fillParameters(ParameterList &list)
Fill ParameterList with parameters.
bool HasChanged
Node has changed and needs to call recalculate()
ParObserver Base class parameter observer.
std::string print(int level=-1, std::string prefix="")
Print node and its child nodes to std::string.
std::shared_ptr< Parameter > parameter()
Obtain parameter of node.
TreeNode(std::shared_ptr< Strategy > strategy)
Constructor for tree using a strategy.
TreeNode is the basic building block of the FunctionTree.
std::shared_ptr< Strategy > Strat
Node strategy.
void removeExpiredParents()
This file contains Functions implementing the Strategy interface so they can be used inside a node of...
std::shared_ptr< ComPWA::FunctionTree::Parameter > OutputParameter
(cached) node value
void addNode(std::shared_ptr< TreeNode > node)
std::vector< std::weak_ptr< TreeNode > > Parents
List of parent nodes.
std::shared_ptr< TreeNode > createLeaf(std::shared_ptr< Parameter > parameter)
friend std::ostream & operator<<(std::ostream &os, std::shared_ptr< TreeNode > p)
void addParent(std::weak_ptr< TreeNode > node)
std::vector< std::shared_ptr< TreeNode > > ChildNodes
void addNodes(std::vector< std::shared_ptr< TreeNode >> nodes)
std::shared_ptr< ComPWA::FunctionTree::Parameter > recalculate()
Obtain parameter of node.
This class provides a list of parameters and values of different types.
void update()
Flags the node as modified. Should only be called from its child nodes.