C++ mpi module for stochmagnet_main Package
EXPR_Environment.h
1 #ifndef EXPR_Environment_H
2 #define EXPR_Environment_H
3 
4 //inherite class header
5 #include "EXPR_Object.h"
6 
7 //varaible node header
8 #include "EXPR_VariableNode.h"
9 
10 //class factory header
11  #include "CORE_ClassFactory.h"
12 
20 class EXPR_Environment : public virtual EXPR_Object {
21 
22 
23 private:
24  //attributes
25  //map of variable
26  //string -> object
27  std::map<tString,CORE_SharedPointer<EXPR_VariableNode>> mVariables;
28 
29 private:
30  //associations
31 protected:
32  //builders
33 
37  }
38 
39  //deleters
42  virtual ~EXPR_Environment() {
43  }
44 
45 public:
46  //methods
50  static inline CORE_UniquePointer<EXPR_Environment> New() {
51  CORE_UniquePointer<EXPR_Environment> p(new EXPR_Environment(),
53  return p;
54  }
55  //MEMORY
56  //======
64  virtual tMemSize getMemorySize() const override {
65  return sizeof(*this)+getContentsMemorySize();
66  }
67 
76  virtual tMemSize getContentsMemorySize() const override {
78  for(const auto& var:mVariables) {
79  mem+=var.first.length()*sizeof(tUChar);
80  mem+=var.second->getContentsMemorySize();
81  }
82  return mem;
83  }
88  inline CORE_SharedPointer<EXPR_VariableNode> lookUpSharedPointer(const tString& var) const {
89  auto iter=mVariables.find(var);
90  if (iter!= mVariables.cend()) return (iter->second);
91  CORE_SharedPointer<EXPR_VariableNode> nullPtr;
92  return nullPtr;
93  }
98  inline const EXPR_VariableNode* lookUp(const tString& var) const {
99  auto iter=mVariables.find(var);
100  if (iter!= mVariables.cend()) return (iter->second.get());
101  return null;
102  }
107  inline EXPR_VariableNode* lookUp(const tString& var) {
108  auto iter=mVariables.find(var);
109  if (iter!= mVariables.cend()) return (iter->second.get());
110  return null;
111  }
112 
113 
118  inline void record(const tString& varName,CORE_UniquePointer<EXPR_VariableNode> var) {
119  mVariables[varName]=CORE_ClassFactory::NewSharedPointer(var);
120  }
125  inline void record(const tString& varName,CORE_SharedPointer<EXPR_VariableNode> var) {
126  mVariables[varName]=var;
127  }
128 
129 
134  inline void adimensionize(const tReal& L,std::map<tString,tBoolean>& alreadyComputed) {
135  EXPR_RootNode *node;
136  for(auto& var:mVariables) {
137  node=(var.second)->getExpression();
138  if (node!=null) {
139  if (alreadyComputed.find(node->getIdentityString())==alreadyComputed.end()) {
140  node->adimensionize(L,alreadyComputed);
141  }
142  }
143  }
144  }
145 
146 
151  inline void computeBoundingBox(std::map<tString,tBoolean>& alreadyComputed) {
152 
153  EXPR_RootNode *node;
154  for(auto& var:mVariables) {
155  node=(var.second)->getExpression();
156  if (node!=null) {
157  if (alreadyComputed.find(node->getIdentityString())==alreadyComputed.end()) {
158  node->computeBoundingBox(alreadyComputed);
159  }
160  }
161  }
162  }
163 
166  inline tBoolean isConsistant() const {
167  tBoolean ok=true;
168  for(auto& var:mVariables) {
169  ok=ok && ((var.second)->getExpression()!=null);
170  }
171  return ok;
172  }
173 
177  virtual tString toString() const override {
178  std::stringstream sout;
179  const EXPR_RootNode *node;
180  for(const auto& var:mVariables) {
181  node=(var.second)->getExpression();
182  sout <<var.second->toString()<<"=";
183  if (node!=null) sout<<node->toString();
184  sout<<"\n";
185  }
186  return sout.str();
187  }
188 };
189 
190 #endif
191 
192 
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
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
tString getIdentityString() const
retrun the string identification of the class
Definition: CORE_Object.h:321
This class is the environment with contains all the variable value.
Definition: EXPR_Environment.h:20
void computeBoundingBox(std::map< tString, tBoolean > &alreadyComputed)
compute the bounding box of the node
Definition: EXPR_Environment.h:151
void record(const tString &varName, CORE_UniquePointer< EXPR_VariableNode > var)
register the data of the variable
Definition: EXPR_Environment.h:118
EXPR_VariableNode * lookUp(const tString &var)
return the value of the variable as boolean
Definition: EXPR_Environment.h:107
static CORE_UniquePointer< EXPR_Environment > New()
crete the new instance of this
Definition: EXPR_Environment.h:50
EXPR_Environment()
create the class
Definition: EXPR_Environment.h:36
const EXPR_VariableNode * lookUp(const tString &var) const
return the value of the variable as boolean
Definition: EXPR_Environment.h:98
void record(const tString &varName, CORE_SharedPointer< EXPR_VariableNode > var)
register the data of the variable
Definition: EXPR_Environment.h:125
virtual ~EXPR_Environment()
delete the class
Definition: EXPR_Environment.h:42
tBoolean isConsistant() const
return true if all variables have expression
Definition: EXPR_Environment.h:166
virtual tMemSize getContentsMemorySize() const override
return nthe memory size of the included associations
Definition: EXPR_Environment.h:76
void adimensionize(const tReal &L, std::map< tString, tBoolean > &alreadyComputed)
adimensionize the node
Definition: EXPR_Environment.h:134
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: EXPR_Environment.h:64
virtual tString toString() const override
return the string representation of this
Definition: EXPR_Environment.h:177
CORE_SharedPointer< EXPR_VariableNode > lookUpSharedPointer(const tString &var) const
return the value of the variable as boolean
Definition: EXPR_Environment.h:88
This class is the base class of all the parser package.
Definition: EXPR_Object.h:27
virtual tMemSize getContentsMemorySize() const override
return nthe memory size of the included associations
Definition: EXPR_Object.h:70
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
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
This class describes the root of the tree.
Definition: EXPR_RootNode.h:16
This class describes a variable node with contains:
Definition: EXPR_VariableNode.h:17