#include <Expression.h>
Inherited by TypedExpression< bool >, TypedExpression< double >, TypedExpression< EString >, TypedExpression< int32 >, TypedExpression< int64 >, TypedExpression< single >, and TypedExpression< Timestamp >.
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< Expression > | parse (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< Expression > | makeFieldExpresssion (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 |
|
Destructor.
|
|
|
|
Returns a dump of the expression.
|
|
Dumps a human-readable representation of the expression.
|
|
|
|
Evaluates this expression as a T. (Invokes the appropriate evalImpl<>() method.) |
|
Evaluate as a Timestamp.
Reimplemented in TypedExpression< Timestamp >.
|
|
Evaluate as a string. By default calls eval<EString>; in general subclasses should override evalImpl(EvalAs<EString>) rather than this. |
|
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.
|
|
Evaluate as a double.
Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, TypedExpression< double >, and RandFunction::DoubleRandFunction.
|
|
Evaluate as a single.
Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, TypedExpression< single >, and RandFunction::SingleRandFunction.
|
|
Evaluate as an int64.
Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, and RandFunction::Int64RandFunction.
|
|
Evaluate as an int32.
Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, FidAlarmCounterFunc::Impl, LRSecToMinFunction::LRSecToMinFunctionImpl, and RandFunction::Int32RandFunction.
|
|
Evaluate as a bool.
Reimplemented in TypedExpression< bool >.
|
|
Evaluates into a buffer. The buffer length must be getLength() (and getLength() must not be -1). |
|
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. |
|
Returns a TupleDescription::Field describing this value. Throws an exception if this is a variable-length string field. |
|
Returns the size returned by the expression, or -1 if not known.
|
|
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.
|
|
Returns the actual type to which the expression will evaluate.
|
|
Returns true iff this expression can be evaluated as a T. (Invokes the appropriate isImpl<>() method.) |
|
Returns true iff the expression can be evaluated as a numeric. By default returns is<double>(). |
|
Returns true iff the expression can be evaluated as a double.
Reimplemented in TypedExpression< Timestamp >.
|
|
Returns true iff the expression can be evaluated as a string. By default calls is_EString(). |
|
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 >.
|
|
Returns true iff the expression can be evaluated as a double.
Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, and TypedExpression< double >.
|
|
Returns true iff the expression can be evaluated as a single.
Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, TypedExpression< int64 >, and TypedExpression< single >.
|
|
Returns true iff the expression can be evaluated as an int64.
Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, and TypedExpression< int64 >.
|
|
Returns true iff the expression can be evaluated as an int32.
Reimplemented in TypedExpression< bool >, TypedExpression< int32 >, and TypedExpression< int64 >.
|
|
Returns true iff the expression can be evaluated as a bool.
Reimplemented in TypedExpression< bool >.
|
|
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. |
|
Parses and returns an expression given a context.
|
|
Return a field suitable for holding this expression.
|
|
Reimplemented in ConstantExpression< EString >.
|