Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

Expression Class Reference

#include <Expression.h>

Inherited by TypedExpression< bool >, TypedExpression< double >, TypedExpression< EString >, TypedExpression< int32 >, TypedExpression< int64 >, TypedExpression< single >, and TypedExpression< Timestamp >.

List of all members.


Detailed Description

The base class for expressions.

An expression has a static type: a bool, int32, int64, single, double or EString. It can be evaluated either as that type or as a type which can be implicitly coerced to it; for example, if an expression has integer type, eval<int32>() or eval<int64>() will yield its integer value and eval<single>() or eval<double>() will yield the same value but as a float. (However, eval<bool>() will throw an exception since an int cannot be coerced to an bool.)

When evaluating an expression, provide an EvalContext which described the environment of the expression (e.g., the tuples to which the tuple may refer).

Subclasses may override evalImpl() and isImpl() methods to specify the behavior when an expression is evaluated as a particular type (specified using an EvalAs<T> as the first argument). Custom expression types (e.g., user-defined functions) should generally be derived from TypedExpression<> rather than Expression. TypedExpression<> implements the default coercion behavior.

The default eval<xxx>() methods all throw exceptions, and the default is<xxx>() functions all return false (unless otherwise noted). is<xxx>() should always return true iff eval<xxx>() is typesafe.


Public Member Functions

virtual ~Expression ()
 Destructor.
template<typename T> T eval (const EvalContext &ctxt) throw ( EvalException )
 Evaluates this expression as a T.
template<typename T> bool is () const
 Returns true iff this expression can be evaluated as a T.
virtual int32 getStringLength () const
 Returns the size of the string returned by the expression, or -1 if not known.
int32 getLength () const
 Returns the size returned by the expression, or -1 if not known.
void evalInto (char *buf, const EvalContext &ctxt) throw (EvalException)
 Evaluates into a buffer.
virtual bool is_numeric () const
 Returns true iff the expression can be evaluated as a numeric.
DataType getType () const
 Returns the actual type to which the expression will evaluate.
TupleDescription::Field getField (string name=string()) const throw (ExprException)
 Returns a TupleDescription::Field describing this value.
virtual void dump (string &s, unsigned int indent=0) const
 Dumps a human-readable representation of the expression.
string as_string () const
 Returns a dump of the expression.
TupleDescription::Field toField (string name) const throw ( AuroraException )
 Return a field suitable for holding this expression.

Static Public Member Functions

ptr< Expressionparse (string expr, const ExprContext &ctxt) throw ( ExprException )
 Parses and returns an expression given a context.
void evalVectorInto (const vector< ptr< Expression > > &exprs, char *buf, const EvalContext &ctxt) throw ( EvalException )
 Evaluate each of the expressions in exprs, concatenating the results, and place them in the buffer.
ptr< ExpressionmakeFieldExpresssion (string tuple_name, string field_name, const ExprContext &ctxt) throw ( ExprException )
 Create a field expression from the given tuple and field names.

Protected Member Functions

 Expression (DataType type)
virtual bool evalImpl (EvalAs< bool >, const EvalContext &) throw ( EvalException )
 Evaluate as a bool.
virtual bool isImpl (EvalAs< bool >) const
 Returns true iff the expression can be evaluated as a bool.
virtual int32 evalImpl (EvalAs< int32 >, const EvalContext &) throw ( EvalException )
 Evaluate as an int32.
virtual bool isImpl (EvalAs< int32 >) const
 Returns true iff the expression can be evaluated as an int32.
virtual int64 evalImpl (EvalAs< int64 >, const EvalContext &) throw ( EvalException )
 Evaluate as an int64.
virtual bool isImpl (EvalAs< int64 >) const
 Returns true iff the expression can be evaluated as an int64.
virtual single evalImpl (EvalAs< single >, const EvalContext &) throw ( EvalException )
 Evaluate as a single.
virtual bool isImpl (EvalAs< single >) const
 Returns true iff the expression can be evaluated as a single.
virtual double evalImpl (EvalAs< double >, const EvalContext &) throw ( EvalException )
 Evaluate as a double.
virtual bool isImpl (EvalAs< double >) const
 Returns true iff the expression can be evaluated as a double.
virtual EString evalImpl (EvalAs< EString >, const EvalContext &) throw ( EvalException )
 Evaluate as a string.
virtual bool isImpl (EvalAs< EString >) const
 Returns true iff the expression can be evaluated as an EString.
virtual string evalImpl (EvalAs< string >, const EvalContext &ctxt) throw ( EvalException )
 Evaluate as a string.
virtual bool isImpl (EvalAs< string >) const
 Returns true iff the expression can be evaluated as a string.
virtual Timestamp evalImpl (EvalAs< Timestamp >, const EvalContext &) throw ( EvalException )
 Evaluate as a Timestamp.
virtual bool isImpl (EvalAs< Timestamp >) const
 Returns true iff the expression can be evaluated as a double.
virtual void dump_children (string &s, unsigned int indent) const
virtual string value () const


Constructor & Destructor Documentation

virtual Expression::~Expression  )  [virtual]
 

Destructor.

Expression::Expression DataType  type  )  [protected]
 


Member Function Documentation

string Expression::as_string  )  const
 

Returns a dump of the expression.

virtual void Expression::dump string &  s,
unsigned int  indent = 0
const [virtual]
 

Dumps a human-readable representation of the expression.

virtual void Expression::dump_children string &  s,
unsigned int  indent
const [protected, virtual]
 

template<typename T>
T Expression::eval const EvalContext ctxt  )  throw ( EvalException )
 

Evaluates this expression as a T.

(Invokes the appropriate evalImpl<>() method.)

virtual Timestamp Expression::evalImpl EvalAs< Timestamp ,
const EvalContext
throw ( EvalException ) [protected, virtual]
 

Evaluate as a Timestamp.

Reimplemented in TypedExpression< Timestamp >.

virtual string Expression::evalImpl EvalAs< string >  ,
const EvalContext ctxt
throw ( EvalException ) [protected, virtual]
 

Evaluate as a string.

By default calls eval<EString>; in general subclasses should override evalImpl(EvalAs<EString>) rather than this.

virtual EString Expression::evalImpl EvalAs< EString ,
const EvalContext
throw ( EvalException ) [protected, virtual]
 

Evaluate as a string.

Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, TypedExpression< single >, TypedExpression< double >, TypedExpression< EString >, ConstantExpression< EString >, FieldExpression< EString >, and PadFunction::Impl.

virtual double Expression::evalImpl EvalAs< double >  ,
const EvalContext
throw ( EvalException ) [protected, virtual]
 

Evaluate as a double.

Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, TypedExpression< double >, and RandFunction::DoubleRandFunction.

virtual single Expression::evalImpl EvalAs< single >  ,
const EvalContext
throw ( EvalException ) [protected, virtual]
 

Evaluate as a single.

Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, TypedExpression< single >, and RandFunction::SingleRandFunction.

virtual int64 Expression::evalImpl EvalAs< int64 >  ,
const EvalContext
throw ( EvalException ) [protected, virtual]
 

Evaluate as an int64.

Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, and RandFunction::Int64RandFunction.

virtual int32 Expression::evalImpl EvalAs< int32 >  ,
const EvalContext
throw ( EvalException ) [protected, virtual]
 

Evaluate as an int32.

Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, FidAlarmCounterFunc::Impl, LRSecToMinFunction::LRSecToMinFunctionImpl, and RandFunction::Int32RandFunction.

virtual bool Expression::evalImpl EvalAs< bool >  ,
const EvalContext
throw ( EvalException ) [protected, virtual]
 

Evaluate as a bool.

Reimplemented in TypedExpression< bool >.

void Expression::evalInto char *  buf,
const EvalContext ctxt
throw (EvalException)
 

Evaluates into a buffer.

The buffer length must be getLength() (and getLength() must not be -1).

void Expression::evalVectorInto const vector< ptr< Expression > > &  exprs,
char *  buf,
const EvalContext ctxt
throw ( EvalException ) [static]
 

Evaluate each of the expressions in exprs, concatenating the results, and place them in the buffer.

The buffer must be as large as them sum of the getLength()s of the expressions, and none can be -1.

TupleDescription::Field Expression::getField string  name = string()  )  const throw (ExprException)
 

Returns a TupleDescription::Field describing this value.

Throws an exception if this is a variable-length string field.

int32 Expression::getLength  )  const
 

Returns the size returned by the expression, or -1 if not known.

virtual int32 Expression::getStringLength  )  const [virtual]
 

Returns the size of the string returned by the expression, or -1 if not known.

By default returns -1.

Reimplemented in FieldExpression< EString >, and PadFunction::Impl.

DataType Expression::getType  )  const
 

Returns the actual type to which the expression will evaluate.

template<typename T>
bool Expression::is  )  const
 

Returns true iff this expression can be evaluated as a T.

(Invokes the appropriate isImpl<>() method.)

virtual bool Expression::is_numeric  )  const [virtual]
 

Returns true iff the expression can be evaluated as a numeric.

By default returns is<double>().

virtual bool Expression::isImpl EvalAs< Timestamp  )  const [protected, virtual]
 

Returns true iff the expression can be evaluated as a double.

Reimplemented in TypedExpression< Timestamp >.

virtual bool Expression::isImpl EvalAs< string >   )  const [protected, virtual]
 

Returns true iff the expression can be evaluated as a string.

By default calls is_EString().

virtual bool Expression::isImpl EvalAs< EString  )  const [protected, virtual]
 

Returns true iff the expression can be evaluated as an EString.

Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, TypedExpression< single >, TypedExpression< double >, and TypedExpression< EString >.

virtual bool Expression::isImpl EvalAs< double >   )  const [protected, virtual]
 

Returns true iff the expression can be evaluated as a double.

Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, and TypedExpression< double >.

virtual bool Expression::isImpl EvalAs< single >   )  const [protected, virtual]
 

Returns true iff the expression can be evaluated as a single.

Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, and TypedExpression< single >.

virtual bool Expression::isImpl EvalAs< int64 >   )  const [protected, virtual]
 

Returns true iff the expression can be evaluated as an int64.

Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, and TypedExpression< int64 >.

virtual bool Expression::isImpl EvalAs< int32 >   )  const [protected, virtual]
 

Returns true iff the expression can be evaluated as an int32.

Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, and TypedExpression< int64 >.

virtual bool Expression::isImpl EvalAs< bool >   )  const [protected, virtual]
 

Returns true iff the expression can be evaluated as a bool.

Reimplemented in TypedExpression< bool >.

ptr< Expression > Expression::makeFieldExpresssion string  tuple_name,
string  field_name,
const ExprContext ctxt
throw ( ExprException ) [static]
 

Create a field expression from the given tuple and field names.

If tuple_name is "", then there must be exactly one tuple in the context with a field named field_name or an exception is thrown.

ptr< Expression > Expression::parse string  expr,
const ExprContext ctxt
throw ( ExprException ) [static]
 

Parses and returns an expression given a context.

TupleDescription::Field Expression::toField string  name  )  const throw ( AuroraException )
 

Return a field suitable for holding this expression.

virtual string Expression::value  )  const [protected, virtual]
 

Reimplemented in ConstantExpression< EString >.


The documentation for this class was generated from the following files:
Generated on Fri Nov 12 15:15:23 2004 for Borealis by doxygen 1.3.8