ExprNodeRep.h

Classes

TableExprNodeRep -- Abstract base class for a node in a table column expression tree (full description)
TableExprNodeBinary -- Abstract base class for a node having 0, 1, or 2 child nodes. (full description)
TableExprNodeMulti -- Abstract base class for a node having multiple child nodes. (full description)

class TableExprNodeRep

Types

enum NodeDataType

NTBool
NTDouble
NTComplex
NTString
NTRegex
NTDate
NTNumeric
NTAny
# NTDouble or NTComplex

enum ValueType

VTScalar
VTArray
VTRecord
VTSetElem
VTSet
VTIndex

enum OperType

OtPlus
OtMinus
OtTimes
OtDivide
OtModulo
OtEQ
OtGE
OtGT
OtNE
OtIN
OtAND
OtOR
OtNOT
OtMIN
OtColumn
OtField
OtLiteral
OtFunc
OtSlice
OtUndef
OtRownr
OtRandom

enum ArgType

NoArr
ArrArr
ArrSca
ScaArr

enum ExprType

Constant
A constant subexpression which can be evaluated immediately.
Variable
A variable (i.e. row dependent) subexpression which has to be evaluated for each table row.

Interface

Public Members
TableExprNodeRep (NodeDataType, ValueType, OperType, ArgType, ExprType, Int ndim, const IPosition& shape, const Table& table)
TableExprNodeRep (NodeDataType, ValueType, OperType, const Table&)
TableExprNodeRep (const TableExprNodeRep&)
virtual ~TableExprNodeRep()
TableExprNodeRep* link()
static void unlink (TableExprNodeRep*)
virtual Bool getBool (const TableExprId& id)
virtual Double getDouble (const TableExprId& id)
virtual DComplex getDComplex (const TableExprId& id)
virtual String getString (const TableExprId& id)
virtual Regex getRegex (const TableExprId& id)
virtual MVTime getDate (const TableExprId& id)
virtual Array<Bool> getArrayBool (const TableExprId& id)
virtual Array<Double> getArrayDouble (const TableExprId& id)
virtual Array<DComplex> getArrayDComplex (const TableExprId& id)
virtual Array<String> getArrayString (const TableExprId& id)
virtual Array<MVTime> getArrayDate (const TableExprId& id)
virtual Bool hasBool (const TableExprId& id, Bool value)
virtual Bool hasDouble (const TableExprId& id, Double value)
virtual Bool hasDComplex (const TableExprId& id, const DComplex& value)
virtual Bool hasString (const TableExprId& id, const String& value)
virtual Bool hasDate (const TableExprId& id, const MVTime& value)
virtual Array<Bool> hasArrayBool (const TableExprId& id, const Array<Bool>& value)
virtual Array<Bool> hasArrayDouble (const TableExprId& id, const Array<Double>& value)
virtual Array<Bool> hasArrayDComplex (const TableExprId& id, const Array<DComplex>& value)
virtual Array<Bool> hasArrayString (const TableExprId& id, const Array<String>& value)
virtual Array<Bool> hasArrayDate (const TableExprId& id, const Array<MVTime>& value)
uInt nrow() const
virtual Bool getColumnDataType (DataType&) const
virtual Array<Bool> getColumnBool()
virtual Array<uChar> getColumnuChar()
virtual Array<Short> getColumnShort()
virtual Array<uShort> getColumnuShort()
virtual Array<Int> getColumnInt()
virtual Array<uInt> getColumnuInt()
virtual Array<Float> getColumnFloat()
virtual Array<Double> getColumnDouble()
virtual Array<Complex> getColumnComplex()
virtual Array<DComplex> getColumnDComplex()
virtual Array<String> getColumnString()
virtual void ranges (Block<TableExprRange>&)
NodeDataType dataType() const
ValueType valueType() const
void setValueType (ValueType vtype)
OperType operType() const
ExprType exprType() const
Bool isConstant() const
Int ndim() const
const IPosition& shape() const
const IPosition& shape (const TableExprId& id)
virtual Bool isDefined (const TableExprId& id)
virtual void show (ostream&, uInt indent) const
Table& table()
const Table& table() const
virtual void replaceTablePtr (const Table&)
static void createRange (Block<TableExprRange>&, TableExprNodeColumn*, Double start, Double end)
static void createRange (Block<TableExprRange>&)
Protected Members
virtual const IPosition& getShape (const TableExprId& id)
static TableExprNodeRep* getRep (TableExprNode&)
virtual void convertConstChild()
void checkTablePtr (const TableExprNodeRep* node)
static void checkTablePtr (Table& table, const TableExprNodeRep* node)
void fillExprType (const TableExprNodeRep* node)
static void fillExprType (ExprType&, const TableExprNodeRep* node)
static TableExprNodeRep* convertNode (TableExprNodeRep* thisNode, Bool convertConstType)
Private Members
TableExprNodeRep& operator= (const TableExprNodeRep&)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Prerequisite

Etymology

TableExprNodeRep is the (abstract) REPresentation of a node in a table expression tree.

Synopsis

TableExprNodeRep is the base class for all nodes in a table expression tree. It is used by the handle class TableExprNode.

The objects of this class are reference-counted to make it possible that the same object is reused.

Motivation

TableExprNodeRep and its derivations store a table select expression before actually evaluating it. It is also possible that the classes are used by the table expression parser defined in TableParse and TableGram.
For each operator a special derived class is implemented. Another approach could have been to store the operator as a flag and switch on that. However, that causes extra overhead and the C++ virtual function mechanism is designed for these purposes.

To Do

Member Description

enum NodeDataType

Define the data types of a node.

enum ValueType

Define the value types.

enum OperType

Define the operator types. LE and LT are handled as GE and GT with swapped operands.

enum ArgType

Define the value types of the 2 arguments when arrays are involved.

enum ExprType

Define (sub-)expression type

TableExprNodeRep (NodeDataType, ValueType, OperType, ArgType, ExprType, Int ndim, const IPosition& shape, const Table& table)

Construct a node.

TableExprNodeRep (NodeDataType, ValueType, OperType, const Table&)

This constructor is called from the derived TableExprNodeRep.

TableExprNodeRep (const TableExprNodeRep&)

Copy constructor.

virtual ~TableExprNodeRep()

The destructor deletes all the underlying TableExprNode objects.

TableExprNodeRep* link()

Link to this object, i.e. increase its reference count.

static void unlink (TableExprNodeRep*)

Unlink from the given object. If its reference count is zero, delete it.

virtual Bool getBool (const TableExprId& id)
virtual Double getDouble (const TableExprId& id)
virtual DComplex getDComplex (const TableExprId& id)
virtual String getString (const TableExprId& id)
virtual Regex getRegex (const TableExprId& id)
virtual MVTime getDate (const TableExprId& id)

Get a scalar value for this node in the given row. The appropriate functions are implemented in the derived classes and will usually invoke the get in their children and apply the operator on the resulting values.

virtual Array<Bool> getArrayBool (const TableExprId& id)
virtual Array<Double> getArrayDouble (const TableExprId& id)
virtual Array<DComplex> getArrayDComplex (const TableExprId& id)
virtual Array<String> getArrayString (const TableExprId& id)
virtual Array<MVTime> getArrayDate (const TableExprId& id)

Get an array value for this node in the given row. The appropriate functions are implemented in the derived classes and will usually invoke the get in their children and apply the operator on the resulting values.

virtual Bool hasBool (const TableExprId& id, Bool value)
virtual Bool hasDouble (const TableExprId& id, Double value)
virtual Bool hasDComplex (const TableExprId& id, const DComplex& value)
virtual Bool hasString (const TableExprId& id, const String& value)
virtual Bool hasDate (const TableExprId& id, const MVTime& value)
virtual Array<Bool> hasArrayBool (const TableExprId& id, const Array<Bool>& value)
virtual Array<Bool> hasArrayDouble (const TableExprId& id, const Array<Double>& value)
virtual Array<Bool> hasArrayDComplex (const TableExprId& id, const Array<DComplex>& value)
virtual Array<Bool> hasArrayString (const TableExprId& id, const Array<String>& value)
virtual Array<Bool> hasArrayDate (const TableExprId& id, const Array<MVTime>& value)

Does a value occur in an array or set? The default implementation tests if it is in an array.

uInt nrow() const

Get the number of rows in the table associated with this expression. One is returned if the expression is a constant. Zero is returned if no table is associated with it.

virtual Bool getColumnDataType (DataType&) const

Get the data type of the column. It returns True when it could set the data type (which it can if the expression is a scalar column or a constant array column pixel). Otherwise it returns False.

virtual Array<Bool> getColumnBool()
virtual Array<uChar> getColumnuChar()
virtual Array<Short> getColumnShort()
virtual Array<uShort> getColumnuShort()
virtual Array<Int> getColumnInt()
virtual Array<uInt> getColumnuInt()
virtual Array<Float> getColumnFloat()
virtual Array<Double> getColumnDouble()
virtual Array<Complex> getColumnComplex()
virtual Array<DComplex> getColumnDComplex()
virtual Array<String> getColumnString()

Get the value of the expression evaluated for the entire column. The data of function called should match the data type as returned by function getColumnDataType.

virtual void ranges (Block<TableExprRange>&)

Convert the tree to a number of range vectors which at least select the same things. This function is very useful to convert the expression to some intervals covering the select expression. This can be used to do a rough fast selection via an index and do the the slower final selection on that much smaller subset. The function can only convert direct comparisons of columns with constants (via ==, !=, >, >=, < or <=) and their combinations using && or ||.

NodeDataType dataType() const

Get the data type of the derived TableExprNode object. This is the data type of the resulting value. E.g. a compare of 2 numeric values results in a Bool, thus the data type of, say, TableExprNodeEQ is always Bool. Function getInternalDT gives the internal data type, thus in the example above the data type of T.

ValueType valueType() const

Get the value type.

void setValueType (ValueType vtype)

Set the value type.

OperType operType() const

Get the operator type.

ExprType exprType() const

Get the expression type.

Bool isConstant() const

Is the exprerssion a constant?

Int ndim() const

Get the fixed dimensionality (same for all rows).

const IPosition& shape() const

Get the fixed shape (same for all rows).

const IPosition& shape (const TableExprId& id)

Get the shape for the given row. It returns the fixed shape if defined, otherwise getShape(id).

virtual Bool isDefined (const TableExprId& id)

Is the value in the given row defined? The default implementation returns True.

virtual void show (ostream&, uInt indent) const

Show the expression tree.

Table& table()
const Table& table() const

Get table. This gets the Table object to which a TableExprNode belongs. A TableExprNode belongs to the Table to which the column(s) used in an expression belong. Note that all columns in an expression have to belong to the same table.

virtual void replaceTablePtr (const Table&)

Replace the Table pointer in this node and all its children.

static void createRange (Block<TableExprRange>&, TableExprNodeColumn*, Double start, Double end)

Create a range object from a column and an interval.

static void createRange (Block<TableExprRange>&)

Create a empty range object.

virtual const IPosition& getShape (const TableExprId& id)

Get the shape for the given row.

static TableExprNodeRep* getRep (TableExprNode&)

Get pointer to REPresentation object. This is used by derived classes.

virtual void convertConstChild()

When one of the children is a constant, convert its data type to that of the other operand. This avoids that conversions are done for each get. The default implementation does nothing.

void checkTablePtr (const TableExprNodeRep* node)
static void checkTablePtr (Table& table, const TableExprNodeRep* node)

Check if this node uses the same table pointer. Fill the Table object if it is still null.

void fillExprType (const TableExprNodeRep* node)
static void fillExprType (ExprType&, const TableExprNodeRep* node)

Set expression type to Variable if node is Variable.

static TableExprNodeRep* convertNode (TableExprNodeRep* thisNode, Bool convertConstType)

When the node is constant, it is evaluated and replaced by the appropriate TableExprNodeConst object. If not constant, it calls the virtual ConvertConstChild function which can convert a constant child when appropriate.

TableExprNodeRep& operator= (const TableExprNodeRep&)

A copy of a TableExprNodeRep cannot be made.

class TableExprNodeBinary : public TableExprNodeRep

Interface

Public Members
TableExprNodeBinary (NodeDataType, ValueType, OperType, const Table&)
TableExprNodeBinary (NodeDataType, const TableExprNodeRep&, OperType)
virtual ~TableExprNodeBinary()
virtual void show (ostream&, uInt indent) const
static NodeDataType getDT (NodeDataType leftDtype, NodeDataType rightDype, OperType operType)
static TableExprNodeRep getTypes (const TableExprNodeRep& left, const TableExprNodeRep& right, OperType operType)
static TableExprNodeRep* fillNode (TableExprNodeBinary* thisNode, TableExprNodeRep* left, TableExprNodeRep* right, Bool convertConstType)
void convertConstChild()
virtual void replaceTablePtr (const Table&)
const TableExprNodeRep* getLeftChild() const
const TableExprNodeRep* getRightChild() const

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Prerequisite

Etymology

TableExprNodeBinary is a node in the table expression tree representing a binary node (i.e. having 2 operands).

Synopsis

TableExprNodeBinary is the abstract base class for all nodes in a table expression tree using up to 2 operands. It is used as the base class for the node classes representing operator +, -, etc..

Motivation

This class contains the common functionality for the classes representing a binary (or unary) operator.

Member Description

TableExprNodeBinary (NodeDataType, ValueType, OperType, const Table&)

Constructor

TableExprNodeBinary (NodeDataType, const TableExprNodeRep&, OperType)

virtual ~TableExprNodeBinary()

Destructor

virtual void show (ostream&, uInt indent) const

Show the expression tree.

static NodeDataType getDT (NodeDataType leftDtype, NodeDataType rightDype, OperType operType)

Check the data types and get the common one.

static TableExprNodeRep getTypes (const TableExprNodeRep& left, const TableExprNodeRep& right, OperType operType)

Check the data and value types and get the common one.

static TableExprNodeRep* fillNode (TableExprNodeBinary* thisNode, TableExprNodeRep* left, TableExprNodeRep* right, Bool convertConstType)

Link the children to the node and convert the children to constants if needed and possible. Also convert the node to constant if possible.

void convertConstChild()

When one of the children is a constant, convert its data type to that of the other operand. This avoids that conversions are done for each get.

virtual void replaceTablePtr (const Table&)

Replace the Table in this node and all its children.

const TableExprNodeRep* getLeftChild() const
const TableExprNodeRep* getRightChild() const

Get the child nodes.


class TableExprNodeMulti : public TableExprNodeRep

Interface

TableExprNodeMulti (NodeDataType, ValueType, OperType, const TableExprNodeRep& source)
virtual ~TableExprNodeMulti()
virtual void show (ostream&, uInt indent) const
static uInt checkNumOfArg (uInt low, uInt high, const PtrBlock<TableExprNodeRep*>& nodes)
virtual void replaceTablePtr (const Table&)
const PtrBlock<TableExprNodeRep*>& getChildren() const
Protected Members
static NodeDataType checkDT (Block<Int>& dtypeOper, NodeDataType dtIn, NodeDataType dtOut, const PtrBlock<TableExprNodeRep*>& nodes)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Prerequisite

Etymology

TableExprNodeMulti is a node in the table expression tree which can have MULTIple child nodes.

Synopsis

TableExprNodeMulti is the abstract base class for all nodes in a table expression tree using multiple operands. It is used as the base class for the node classes representing functions, sets, indices, etc..

Motivation

This class contains the common functionality for the classes representing a node with multiple operands.

Member Description

TableExprNodeMulti (NodeDataType, ValueType, OperType, const TableExprNodeRep& source)

Constructor

virtual ~TableExprNodeMulti()

Destructor

virtual void show (ostream&, uInt indent) const

Show the expression tree.

static uInt checkNumOfArg (uInt low, uInt high, const PtrBlock<TableExprNodeRep*>& nodes)

Check number of arguments low <= number_of_args <= high It throws an exception if wrong number of arguments.

virtual void replaceTablePtr (const Table&)

Replace the Table pointer in this node and all its children.

const PtrBlock<TableExprNodeRep*>& getChildren() const

Get the child nodes.

static NodeDataType checkDT (Block<Int>& dtypeOper, NodeDataType dtIn, NodeDataType dtOut, const PtrBlock<TableExprNodeRep*>& nodes)

Check datatype of nodes and return output type. It also sets the expected data type of the operands (from dtIn).