casa
$Rev:20696$
|
Abstract base class for a user-defined TaQL function. More...
#include <UDFBase.h>
Public Types | |
typedef UDFBase * | MakeUDFObject (const String &functionName) |
The signature of a global or static member function creating an object of the UDF. | |
Public Member Functions | |
UDFBase () | |
Only default constructor is needed. | |
virtual | ~UDFBase () |
Destructor. | |
virtual Bool | getBool (const TableExprId &id) |
Evaluate the function and return the result. | |
virtual Int64 | getInt (const TableExprId &id) |
virtual Double | getDouble (const TableExprId &id) |
virtual DComplex | getDComplex (const TableExprId &id) |
virtual String | getString (const TableExprId &id) |
virtual TaqlRegex | getRegex (const TableExprId &id) |
virtual MVTime | getDate (const TableExprId &id) |
virtual Array< Bool > | getArrayBool (const TableExprId &id) |
virtual Array< Int64 > | getArrayInt (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) |
const String & | getUnit () const |
Get the unit. | |
void | init (const PtrBlock< TableExprNodeRep * > &arg, const Table &table, const TaQLStyle &) |
Initialize the function object. | |
TableExprNodeRep::NodeDataType | dataType () const |
Get the data type. | |
Int | ndim () const |
Get the dimensionality of the results. | |
const IPosition & | shape () const |
Get the result shape if the same for all results. | |
Bool | isConstant () const |
Tell if the UDF gives a constant result. | |
Static Public Member Functions | |
static void | registerUDF (const String &name, MakeUDFObject *func) |
Register a the name and construction function of a UDF (thread-safe). | |
static UDFBase * | createUDF (const String &name) |
Create a UDF object (thread-safe). | |
Protected Member Functions | |
PtrBlock< TableExprNodeRep * > & | operands () |
Get the operands. | |
void | setDataType (TableExprNodeRep::NodeDataType) |
Set the data type. | |
void | setNDim (Int ndim) |
Set the dimensionality of the results. | |
void | setShape (const IPosition &shape) |
Set the shape of the results if it is fixed and known. | |
void | setUnit (const String &unit) |
Set the unit of the result. | |
void | setConstant (Bool isConstant) |
Define if the result is constant (e.g. | |
Private Member Functions | |
virtual void | setup (const Table &table, const TaQLStyle &)=0 |
Set up the function object. | |
Private Attributes | |
PtrBlock< TableExprNodeRep * > | itsOperands |
TableExprNodeRep::NodeDataType | itsDataType |
Int | itsNDim |
IPosition | itsShape |
String | itsUnit |
Bool | itsIsConstant |
Static Private Attributes | |
static map< String, MakeUDFObject * > | theirRegistry |
static Mutex | theirMutex |
Abstract base class for a user-defined TaQL function.
This class makes it possible to add user-defined functions (UDF) to TaQL. A UDF has to be implemented in a class derived from this class. A few functions have to be implemented in the class as described below.
A UDF is a class derived from this base class. It must contain the following member functions. See also the example below.
makeObject | a static function to create an object of the UDF class. This function needs to be registered. |
setup | this virtual function is called after the object has been created. It should initialize the object using the function arguments that can be obtained using the function operands() . The setup function should perform the following:
|
getXXX | there are virtual get functions for each possible data type. The get functions matching the data types that can be set by the setup function need to be implemented. |
A UDF has to be made known to TaQL by adding it to the UDF registry with its name and 'makeObject' function. UDFs will usually reside in a shared library that is loaded dynamically. TaQL will load a UDF in the following way:
class TestUDF: public UDFBase { public: TestUDF() {} static UDFBase* makeObject (const String&) { return new TestUDF(); } virtual void setup (const Table&, const TaQLStyle&) { AlwaysAssert (operands().size() == 1, AipsError); AlwaysAssert (operands()[0]->dataType() == TableExprNodeRep::NTInt, AipsError); AlwaysAssert (operands()[0]->valueType() == TableExprNodeRep::VTScalar, AipsError); setDataType (TableExprNodeRep::NTBool); setNDim (0); // scalar result setConstant (operands()[0].isConstant()); // constant result? } Bool getBool (const TableExprId& id) { return operands()[0]->getInt(id) == 1; } };
This example returns True if the function argument matches 1. It can be seen that it checks if the argument is an integer scalar.
typedef UDFBase* casa::UDFBase::MakeUDFObject(const String &functionName) |
Only default constructor is needed.
virtual casa::UDFBase::~UDFBase | ( | ) | [virtual] |
Destructor.
static UDFBase* casa::UDFBase::createUDF | ( | const String & | name | ) | [static] |
Create a UDF object (thread-safe).
TableExprNodeRep::NodeDataType casa::UDFBase::dataType | ( | ) | const [inline] |
virtual Array<Bool> casa::UDFBase::getArrayBool | ( | const TableExprId & | id | ) | [virtual] |
virtual Array<MVTime> casa::UDFBase::getArrayDate | ( | const TableExprId & | id | ) | [virtual] |
virtual Array<DComplex> casa::UDFBase::getArrayDComplex | ( | const TableExprId & | id | ) | [virtual] |
virtual Array<Double> casa::UDFBase::getArrayDouble | ( | const TableExprId & | id | ) | [virtual] |
virtual Array<Int64> casa::UDFBase::getArrayInt | ( | const TableExprId & | id | ) | [virtual] |
virtual Array<String> casa::UDFBase::getArrayString | ( | const TableExprId & | id | ) | [virtual] |
virtual Bool casa::UDFBase::getBool | ( | const TableExprId & | id | ) | [virtual] |
Evaluate the function and return the result.
Their default implementations throw a "not implemented" exception.
virtual MVTime casa::UDFBase::getDate | ( | const TableExprId & | id | ) | [virtual] |
virtual DComplex casa::UDFBase::getDComplex | ( | const TableExprId & | id | ) | [virtual] |
virtual Double casa::UDFBase::getDouble | ( | const TableExprId & | id | ) | [virtual] |
virtual Int64 casa::UDFBase::getInt | ( | const TableExprId & | id | ) | [virtual] |
virtual TaqlRegex casa::UDFBase::getRegex | ( | const TableExprId & | id | ) | [virtual] |
virtual String casa::UDFBase::getString | ( | const TableExprId & | id | ) | [virtual] |
const String& casa::UDFBase::getUnit | ( | ) | const [inline] |
void casa::UDFBase::init | ( | const PtrBlock< TableExprNodeRep * > & | arg, |
const Table & | table, | ||
const TaQLStyle & | |||
) |
Initialize the function object.
Bool casa::UDFBase::isConstant | ( | ) | const [inline] |
Tell if the UDF gives a constant result.
Definition at line 256 of file UDFBase.h.
References itsIsConstant.
Int casa::UDFBase::ndim | ( | ) | const [inline] |
PtrBlock<TableExprNodeRep*>& casa::UDFBase::operands | ( | ) | [inline, protected] |
static void casa::UDFBase::registerUDF | ( | const String & | name, |
MakeUDFObject * | func | ||
) | [static] |
Register a the name and construction function of a UDF (thread-safe).
An exception is thrown if this name already exists with a different construction function.
void casa::UDFBase::setConstant | ( | Bool | isConstant | ) | [protected] |
Define if the result is constant (e.g.
if all arguments are constant). If this function is not called by the setup function of the derived class, the result is not constant.
void casa::UDFBase::setDataType | ( | TableExprNodeRep::NodeDataType | ) | [protected] |
Set the data type.
This function must be called by the setup function of the derived class.
void casa::UDFBase::setNDim | ( | Int | ndim | ) | [protected] |
Set the dimensionality of the results.
0 means that the results are scalars.
-1 means that the results are arrays with unknown dimensionality.
>0 means that the results are arrays with that dimensionality. This function must be called by the setup function of the derived class.
void casa::UDFBase::setShape | ( | const IPosition & | shape | ) | [protected] |
Set the shape of the results if it is fixed and known.
void casa::UDFBase::setUnit | ( | const String & | unit | ) | [protected] |
Set the unit of the result.
If this function is not called by the setup function of the derived class, the result has no unit.
virtual void casa::UDFBase::setup | ( | const Table & | table, |
const TaQLStyle & | |||
) | [private, pure virtual] |
Set up the function object.
const IPosition& casa::UDFBase::shape | ( | ) | const [inline] |
Definition at line 265 of file UDFBase.h.
Referenced by dataType().
Bool casa::UDFBase::itsIsConstant [private] |
Definition at line 269 of file UDFBase.h.
Referenced by isConstant().
Int casa::UDFBase::itsNDim [private] |
PtrBlock<TableExprNodeRep*> casa::UDFBase::itsOperands [private] |
Definition at line 264 of file UDFBase.h.
Referenced by operands().
IPosition casa::UDFBase::itsShape [private] |
String casa::UDFBase::itsUnit [private] |
Mutex casa::UDFBase::theirMutex [static, private] |
map<String, MakeUDFObject*> casa::UDFBase::theirRegistry [static, private] |