1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/*
* Modification History
*
* 2001-February-11 Jason Rohrer
* Created.
*
* 2001-March-10 Jason Rohrer
* Added implementation of copy function.
*/
#ifndef INVERT_EXPRESSION_INCLUDED
#define INVERT_EXPRESSION_INCLUDED
#include "Expression.h"
#include "UnaryOperationExpression.h"
/**
* Expression implementation of a unary invert operation.
*
* @author Jason Rohrer
*/
class InvertExpression : public UnaryOperationExpression {
public:
/**
* Constructs a unary invert operation expression.
*
* Argument is destroyed when the class is destroyed.
*
* @param inArgument the argument.
*/
InvertExpression( Expression *inArgument );
/**
* A static version of getID().
*/
static long staticGetID();
// implements the Expression interface
virtual double evaluate();
virtual long getID();
virtual void print();
virtual Expression *copy();
protected:
static long mID;
};
// static init
long InvertExpression::mID = 2;
inline InvertExpression::InvertExpression( Expression *inArgument )
: UnaryOperationExpression( inArgument ) {
}
inline double InvertExpression::evaluate() {
return 1 / ( mArgument->evaluate() );
}
long InvertExpression::getID() {
return mID;
}
inline long InvertExpression::staticGetID() {
return mID;
}
inline void InvertExpression::print() {
printf( "( 1/" );
mArgument->print();
printf( " )" );
}
inline Expression *InvertExpression::copy() {
InvertExpression *copy = new InvertExpression( mArgument->copy() );
return copy;
}
#endif
|