C++ main module for gpm Package  1.0
MATH_ParentExpression.h
Go to the documentation of this file.
1 #ifndef MATH_ParentExpression_H
2 #define MATH_ParentExpression_H
3 
4 #include "MATH_Expression.h"
5 
6 
7 #include "MATH_ChildExpression.h"
8 
23  SP_OBJECT(MATH_ParentExpression);
24  // ATTRIBUTES
25 
26 public:
27 
28 
29 private:
30 
31 
32 
33  // ASSOCIATION
34  SV::MATH_ChildExpression mArguments;
35 
36 
37 protected:
38  // METHODS
39 
40  // CONSTRUCTORS
41 
45 
46 
47 
48  // DESTRUCTORS
49 
50 
53  virtual ~MATH_ParentExpression(void);
54 
55 
56  // SET methods
57 public:
58 
61  inline void setArgumentsNumber(const int& n) {
62  mArguments.setSize(n);
63  }
67  virtual tBoolean addArgument(SP::MATH_ChildExpression operand);
68 
73  SP::MATH_ChildExpression sp;
74  if (operand!=null) {
75  operand->getSharedPointer(sp);
76  return addArgument(sp);
77  }
78  return false;
79  }
85  tBoolean setArgument(const int& index,SP::MATH_ChildExpression org);
86 
92  inline tBoolean setArgument(const int& index,MATH_ChildExpression* arg) {
93  SP::MATH_ChildExpression p;
94  if (arg!=null) {
95  arg->getSharedPointer(p);
96  }
97  return setArgument(index,p);
98  }
101  void resetArgument(const int& index);
104  inline void resetArguments() {
105  for (int i=mArguments.getSize()-1;i>=0;i--)
106  resetArgument(i);
107  }
108 
109 
110 
111 
112  // GET methods
113 public:
114 
115 
118  virtual const MATH_RootExpression* getRootNode() const=0;
119 
124  inline SPC::MATH_ChildExpression getArgument(const int& i) const {
125  return mArguments[i];
126  }
131  inline SP::MATH_ChildExpression getArgument(const int& i) {
132  return mArguments[i];
133  }
134 
137  inline int getArgumentsNumber() const {
138  return mArguments.getSize();
139  }
140 
141 public:
142 
143  // OTHERS methods
163  virtual int evaluate(const tFlag& action,MATH_Environment& symbols,MATH_Variable& var) const {
164  const MATH_ChildExpression *arg=null;
165  int nArgs=mArguments.getSize();
166  int retCode=0;
167  for (int i=0;i<nArgs;i++) {
168  arg=mArguments.get(i);
169  if (arg!=null) {
170  retCode=arg->evaluate(action,symbols,var);
171  if (retCode<0) return FAIL;
172  }
173  }
174  return retCode;
175  }
176 
179  virtual tString toString() const;
180 
181 };
182 
183 #endif
DEFINE_SPTR(MATH_ParentExpression)
This class decribes a variable class for evaluation.
Definition: MATH_Variable.h:16
int getArgumentsNumber() const
get the arguments number
Definition: MATH_ParentExpression.h:137
tBoolean setArgument(const int &index, MATH_ChildExpression *arg)
set an argument at index
Definition: MATH_ParentExpression.h:92
void setArgumentsNumber(const int &n)
set the arguments number
Definition: MATH_ParentExpression.h:61
This class is the base class of a math expression.
Definition: MATH_Expression.h:24
SPC::MATH_ChildExpression getArgument(const int &i) const
get argument at index i for reading
Definition: MATH_ParentExpression.h:124
virtual ~MATH_ParentExpression(void)
destroy
Definition: MATH_ParentExpression.cpp:7
virtual int evaluate(const tFlag &action, MATH_Environment &symbols, MATH_Variable &var) const
void evaluate the expression
Definition: MATH_ParentExpression.h:163
#define tBoolean
Definition: types.h:35
#define null
Definition: types.h:13
virtual const MATH_RootExpression * getRootNode() const =0
return the root node of the parent
MATH_ParentExpression(void)
create
Definition: MATH_ParentExpression.cpp:4
This class is a root expression The MATH_RootExpression::newClassFactoryInstance() creates the class ...
Definition: MATH_RootExpression.h:24
void getSharedPointer(SP::CORE_Object &p)
get the shared pointer of this class into p
Definition: CORE_Object.h:65
virtual int evaluate(const tFlag &action, MATH_Environment &symbols, MATH_Variable &value) const =0
void evaluate the expression
static const int FAIL
Definition: MATH_Expression.h:42
This class is a children of a parent expression.
Definition: MATH_ChildExpression.h:23
void resetArguments()
reset all the arguments
Definition: MATH_ParentExpression.h:104
virtual tBoolean addArgument(SP::MATH_ChildExpression operand)
add the argument
Definition: MATH_ParentExpression.cpp:11
This class describes a parent of math expression tree. A parent have arguments:
Definition: MATH_ParentExpression.h:22
#define tString
Definition: types.h:36
SP::MATH_ChildExpression getArgument(const int &i)
get argument at index i for writing
Definition: MATH_ParentExpression.h:131
This class decribes an environment class.
Definition: MATH_Environment.h:14
tBoolean setArgument(const int &index, SP::MATH_ChildExpression org)
set the argument at index
Definition: MATH_ParentExpression.cpp:34
void resetArgument(const int &index)
reset the argument at index
Definition: MATH_ParentExpression.cpp:58
virtual tBoolean addArgument(MATH_ChildExpression *operand)
add the argument
Definition: MATH_ParentExpression.h:72
virtual tString toString() const
to String
Definition: MATH_ParentExpression.cpp:73
#define tFlag
Definition: types.h:14