C++ main module for gpm Package  1.0
MATH_AndBitwiseOperator.h
Go to the documentation of this file.
1 #ifndef MATH_AndBitwiseOperator_H
2 #define MATH_AndBitwiseOperator_H
3 
4 #include "MATH_BinaryOperator.h"
5 #include "MATH_Variable.h"
6 
16  SP_OBJECT(MATH_AndBitwiseOperator);
17 
18  // ATTRIBUTES
19 
20 
21 protected:
22  // METHODS
23 
24  // CONSTRUCTORS
25 
29  setPriority(4);
30  setName("&");
31  }
32 
33 
34 
35  // DESTRUCTORS
36 
37 
40  virtual ~MATH_AndBitwiseOperator(void) {
41  }
42 
43 
44 private:
45 
46 public:
49  static inline SP::MATH_AndBitwiseOperator New() {
50  SP::MATH_AndBitwiseOperator p(new MATH_AndBitwiseOperator(),MATH_AndBitwiseOperator::Delete());
51  p->setThis(p);
52  return p;
53  }
54 
57  virtual SP::MATH_NodeExpression newInstance() const {
58  return New();
59  }
60 
61 
62  // SET methods
63 
64 
65  // GET methods
66 
67 public:
68  // OTHERS methods
89  virtual int evaluate(const tFlag& action,MATH_Environment& symbols,MATH_Variable& var) const {
90  SPC::MATH_ChildExpression arg1=getArgument(0);
91  SPC::MATH_ChildExpression arg2=getArgument(1);
92  if ((arg1.get()==null) || (arg2.get()==null)) return NULL_OPERAND;
93  int retCode=0;
94 
95  int i1=var.getStartIndex();
96  if (arg1.get()!=null) retCode=arg1->evaluate(ALGEBRIC,symbols,var);
97  if (var.isString()) return TYPE_MISMATCHED;
98 
99 
100  int i2=var.getSize();
101  var.setFirstIndex(i1+i2);
102  if (arg2.get()!=null) retCode=arg2->evaluate(ALGEBRIC,symbols,var);
103 
104  var.setFirstIndex(i1);
105  if (var.isString()) return TYPE_MISMATCHED;
106 
107 
108  //int n=var.getSize();
109  double *var1=&var[0];//size i2
110  const double *var2=&var[i2];//size n
111 
112 
113  var1[0]=(double) ( (int) ((MATH_Variable::toInteger(var1[0])) & (MATH_Variable::toInteger(var2[0])) ) );
114  var.setSize(1);
115  return retCode;
116  }
117 
118 };
119 
120 #endif
This class decribes a variable class for evaluation.
Definition: MATH_Variable.h:16
static int toInteger(const double &v)
to int
Definition: MATH_Variable.h:302
tBoolean isString() const
retrun true if the type is string
Definition: MATH_Variable.h:287
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
DEFINE_SPTR(MATH_AndBitwiseOperator)
SPC::MATH_ChildExpression getArgument(const int &i) const
get argument at index i for reading
Definition: MATH_ParentExpression.h:124
static SP::MATH_AndBitwiseOperator New()
create a node expression
Definition: MATH_AndBitwiseOperator.h:49
virtual SP::MATH_NodeExpression newInstance() const
create a node expression
Definition: MATH_AndBitwiseOperator.h:57
virtual int evaluate(const tFlag &action, MATH_Environment &symbols, MATH_Variable &var) const
void evaluate the expression
Definition: MATH_AndBitwiseOperator.h:89
#define null
Definition: types.h:13
void setPriority(const int &p)
set the priority of the operator
Definition: MATH_BinaryOperator.h:49
This class describes an and bitwise (&) operator.
Definition: MATH_AndBitwiseOperator.h:15
MATH_AndBitwiseOperator(void)
create
Definition: MATH_AndBitwiseOperator.h:28
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
static const int TYPE_MISMATCHED
Definition: MATH_Expression.h:43
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
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
virtual ~MATH_AndBitwiseOperator(void)
destroy
Definition: MATH_AndBitwiseOperator.h:40
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14