C++ main module for gpm Package  1.0
MATH_LTOperator.h
Go to the documentation of this file.
1 #ifndef MATH_LTOperator_H
2 #define MATH_LTOperator_H
3 
4 #include "MATH_BinaryOperator.h"
5 #include "MATH_Variable.h"
6 
18  SP_OBJECT(MATH_LTOperator);
19 
20  // ATTRIBUTES
21 
22 
23 protected:
24  // METHODS
25 
26  // CONSTRUCTORS
27 
31  setName("<");
32  setPriority(0);
33  }
34 
35 
36 
37  // DESTRUCTORS
38 
39 
42  virtual ~MATH_LTOperator(void) {
43  }
44 
45 
46 private:
47 
48 public:
51  static inline SP::MATH_LTOperator New() {
52  SP::MATH_LTOperator p(new MATH_LTOperator(),MATH_LTOperator::Delete());
53  p->setThis(p);
54  return p;
55  }
56 
59  virtual SP::MATH_NodeExpression newInstance() const {
60  return New();
61  }
62 
63 
64  // SET methods
65 
66 
67  // GET methods
68 
69 public:
70  // OTHERS methods
91  virtual int evaluate(const tFlag& action,MATH_Environment& symbols,MATH_Variable& var) const {
92  SPC::MATH_ChildExpression arg1=getArgument(0);
93  SPC::MATH_ChildExpression arg2=getArgument(1);
94  if ((arg1.get()==null) || (arg2.get()==null)) return NULL_OPERAND;
95 
96  int retCode=0;
97 
98  //tFlag type1;
99 
100 
101  int i1=var.getStartIndex();
102  if (arg1.get()!=null) retCode=arg1->evaluate(ALGEBRIC,symbols,var);
103  //type1=var.getType();
104 
105  int i2=var.getSize();
106  var.setFirstIndex(i2+i1);
107  if (arg2.get()!=null) retCode=arg2->evaluate(ALGEBRIC,symbols,var);
108  int n=var.getSize();
109  var.setFirstIndex(i1);
110  double *var1=&var[0];//size i2
111  const double *var2=&var[i2];//size n
112 
113 
114 
115  //m=min(n,i2)
116  int i,m=(i2<n)?i2:n;
117  tBoolean ok=true;
118  for (i=0;i<m;i++) {
119  if (var1[i]<var2[i]) {
120  ok=true;
121  break;
122  } else if (var1[i]>var2[i]) {
123  ok=false;
124  break;
125  }
126  }
127  if ((i==m) && (i2<=n)) ok=true;
128  var1[0]=ok;
129  var.setSize(1);
130 
131 
133 
134  return retCode;
135  }
136 
137 
138 };
139 
140 #endif
This class decribes a variable class for evaluation.
Definition: MATH_Variable.h:16
virtual ~MATH_LTOperator(void)
destroy
Definition: MATH_LTOperator.h:42
tBoolean setSize(const int &n)
set the size of the variable be careful of the used of operator[] : the values may be reallocated whi...
Definition: MATH_Variable.cpp:37
SPC::MATH_ChildExpression getArgument(const int &i) const
get argument at index i for reading
Definition: MATH_ParentExpression.h:124
#define tBoolean
Definition: types.h:35
static SP::MATH_LTOperator New()
create a node expression
Definition: MATH_LTOperator.h:51
virtual int evaluate(const tFlag &action, MATH_Environment &symbols, MATH_Variable &var) const
void evaluate the expression
Definition: MATH_LTOperator.h:91
#define null
Definition: types.h:13
void setPriority(const int &p)
set the priority of the operator
Definition: MATH_BinaryOperator.h:49
void setType(const tFlag &type)
set the type
Definition: MATH_Variable.h:183
DEFINE_SPTR(MATH_LTOperator)
static const tFlag BOOLEAN
Definition: MATH_Variable.h:27
int getSize() const
get the size
Definition: MATH_Variable.h:237
This class decribes a binary operator.
Definition: MATH_BinaryOperator.h:15
int getStartIndex() const
get the first index
Definition: MATH_Variable.h:248
This class describes an < operator.
Definition: MATH_LTOperator.h:17
virtual SP::MATH_NodeExpression newInstance() const
create a node expression
Definition: MATH_LTOperator.h:59
void setFirstIndex(const int &index)
set the first index
Definition: MATH_Variable.h:118
This class decribes an environment class.
Definition: MATH_Environment.h:14
MATH_LTOperator(void)
create
Definition: MATH_LTOperator.h:30
void setName(const tString &n)
set the operator name
Definition: MATH_Operator.h:45
static const int NULL_OPERAND
Definition: MATH_Expression.h:46
static const tFlag ALGEBRIC
Definition: MATH_Expression.h:31
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14