C++ mpi module for stochmagnet_main Package
EXPR_ParentNode.h
1 #ifndef EXPR_ParentNode_H
2 #define EXPR_ParentNode_H
3 
4 //inherited class header
5 #include "EXPR_Node.h"
6 
7 //class factory header
8 #include "CORE_ClassFactory.h"
9 
10 //child node
11 #include "EXPR_ChildNode.h"
12 
13 //strings functions headers
14 #include "core_string.h"
15 
23 class EXPR_ParentNode : public virtual EXPR_Node {
24 
25 
26 private:
27 
28 
29 
30 private:
31  //associations
32  std::vector<CORE_SharedPointer<EXPR_ChildNode>> mChildren;
33 
34 
35 protected:
36  //builders
37 
40  EXPR_ParentNode();
41 
42  //deleters
45  virtual ~EXPR_ParentNode();
46 
47 public:
48  //MEMORY
49  //======
57  virtual tMemSize getMemorySize() const override {
58  return sizeof(*this)+getContentsMemorySize();
59  }
60 
69  virtual tMemSize getContentsMemorySize() const override {
70  tMemSize mem=EXPR_Node::getContentsMemorySize();
71  for(const auto& child: mChildren) mem+=child->getContentsMemorySize();
72  return mem;
73  }
74 
75  //methods
76 
80  inline void addChild(CORE_SharedPointer<EXPR_ChildNode> cNode) {
81  mChildren.push_back(cNode);
82  }
86  inline void addChild(CORE_UniquePointer<EXPR_ChildNode> cNode) {
87  CORE_SharedPointer<EXPR_ChildNode> sharedChild=CORE_ClassFactory::NewSharedPointer(cNode);
88  mChildren.push_back(sharedChild);
89  }
90 
94  inline const std::vector<CORE_SharedPointer<EXPR_ChildNode>>& getChildren() const {
95  return mChildren;
96  }
100  inline std::vector<CORE_SharedPointer<EXPR_ChildNode>>& getChildren() {
101  return mChildren;
102  }
103 
108  inline CORE_SharedPointer<EXPR_ChildNode> getSharedChild(const tIndex& i) {
109  if (i>=mChildren.size()) {
110  CORE_SharedPointer<EXPR_ChildNode> nullChild;
111  return nullChild;
112  }
113  return mChildren[i];
114  }
115 
120  inline EXPR_ChildNode* getChild(const tIndex& i) {
121  if (i>=mChildren.size()) return null;
122  return mChildren[i].get();
123  }
124 
129  inline const EXPR_ChildNode* getChild(const tIndex& i) const {
130  if (i>=mChildren.size()) return null;
131  return mChildren[i].get();
132  }
133 
134 
139  virtual void adimensionize(const tReal& L,std::map<tString,tBoolean>& alreadyComputed) override {
140  //cout << getIdentityString()<<"::EXPR_ParentNode::adimensionize("<<L<<") \n";
141  if (alreadyComputed.find(getIdentityString())==alreadyComputed.end()) {
142  for(auto& child:mChildren) {
143  child->adimensionize(L,alreadyComputed);
144  }
145 
146  EXPR_Node::adimensionize(L,alreadyComputed);
147  }
148  }
149 
156  virtual void computeBoundingBox(std::map<tString,tBoolean>& alreadyComputed) override;
157 
162  virtual tBoolean isInside(std::array<tReal,3> M) const override ;
163 
164 
169  virtual tString toString() const override {
170  tString ret="";
171  if (mChildren.size()>0) {
172  ret=mChildren[0]->toString();
173  core_string::trim(ret);
174  }
175  return ret;
176  }
177 };
178 
179 
180 
181 
182 #endif
183 
184 
CORE_SharedPointer< T > NewSharedPointer() const
create a shared instance of a class with same type as T with no argument
Definition: CORE_ClassFactory.h:198
tString getIdentityString() const
retrun the string identification of the class
Definition: CORE_Object.h:321
This class describes a child node of the tree.
Definition: EXPR_ChildNode.h:12
This class is a base class of the binary tree.
Definition: EXPR_Node.h:16
virtual void adimensionize(const tReal &L, std::map< tString, tBoolean > &alreadyComputed)
adimensionize the node
Definition: EXPR_Node.cpp:135
virtual tMemSize getContentsMemorySize() const override
return nthe memory size of the included associations
Definition: EXPR_Node.h:79
This class is a parent node with children.
Definition: EXPR_ParentNode.h:23
std::vector< CORE_SharedPointer< EXPR_ChildNode > > & getChildren()
get the children
Definition: EXPR_ParentNode.h:100
virtual ~EXPR_ParentNode()
delete the class
Definition: EXPR_ParentNode.cpp:8
void addChild(CORE_SharedPointer< EXPR_ChildNode > cNode)
add the children
Definition: EXPR_ParentNode.h:80
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: EXPR_ParentNode.h:57
virtual tBoolean isInside(std::array< tReal, 3 > M) const override
return true if the point is in the bounding box of the first child node
Definition: EXPR_ParentNode.cpp:13
EXPR_ChildNode * getChild(const tIndex &i)
get the child at index for writting
Definition: EXPR_ParentNode.h:120
const EXPR_ChildNode * getChild(const tIndex &i) const
get the child at index for readind
Definition: EXPR_ParentNode.h:129
EXPR_ParentNode()
create the class
Definition: EXPR_ParentNode.cpp:5
CORE_SharedPointer< EXPR_ChildNode > getSharedChild(const tIndex &i)
get the shared child at index for writting
Definition: EXPR_ParentNode.h:108
virtual tMemSize getContentsMemorySize() const override
return nthe memory size of the included associations
Definition: EXPR_ParentNode.h:69
virtual void adimensionize(const tReal &L, std::map< tString, tBoolean > &alreadyComputed) override
adimensionize the node
Definition: EXPR_ParentNode.h:139
virtual tString toString() const override
return the string representation of this
Definition: EXPR_ParentNode.h:169
const std::vector< CORE_SharedPointer< EXPR_ChildNode > > & getChildren() const
get the children
Definition: EXPR_ParentNode.h:94
void addChild(CORE_UniquePointer< EXPR_ChildNode > cNode)
add the children
Definition: EXPR_ParentNode.h:86
virtual void computeBoundingBox(std::map< tString, tBoolean > &alreadyComputed) override
compute the bounding box of the geometry after applying the transformation cosidering only first chil...
Definition: EXPR_ParentNode.cpp:30