libFAUDES

Sections

Index

faudes::Function Class Reference
[Run-Time Interface]

#include <rtifncts.h>

Inherits faudes::Type.

Inherited by faudes::TNestedFunction< FTYPE, CFNCT >, faudes::TSimpleFunction1< FTYPE0, CFNCT >, faudes::TSimpleFunction2< FTYPE0, FTYPE1, CFNCT >, and faudes::TSimpleFunction3< FTYPE0, FTYPE1, FTYPE2, CFNCT >.

List of all members.


Detailed Description

A faudes-function hosts parameter values of some faudes type and provides a method to perform an operation on the specified paramters, e.g.

the parallel composition on two generators. The class Function is the base for all faudes-functions, which essenitally differ in the operation method.

The base class provides an application interface to

Derivates of the base class, that acually implement an operation, are required to cast the parameter values to the corresponding c types and then call the respective c function. To derive a class from Function, one will reimplment three virtual functions:

  • DoTypeCheck() to perform the cast
  • DoExecute() to call the c function.
  • the constructor New() to replicate the function object. See IntegerSum for a simple example of a derived faudes-function.

Technichal note: In contrast to faudes objects (derivates from Type), a faudes-function must be provided a reference to the corresponding FunctionDefinition. This is because a function should be aware of its signature(s). You must not delete the FunctionDefinition object during the lifetime of a faudes-function. Future implementations of Function may host a local copy of the corresponding FunctionDefinition ... its a "memory efficiency versus segfaults" trade off.

Public Member Functions

 Function (const FunctionDefinition *fdef)
 Constructor For the function to be operational, a valid reference to the corresponding FunctionDefinition is required.
 ~Function ()
 Destructor.
virtual FunctionNew () const =0
 Construct on heap.
void Definition (const FunctionDefinition *fdef)
 Set function definition.
const FunctionDefinitionDefinition (void) const
 Get function definition.
int VariantsSize (void) const
 Return number of variants.
void Variant (int n)
 Set signature from function definition.
void Variant (const std::string &rVariantName)
 Set signature from function definition.
const SignatureVariant () const
 Return pointer to assigned faudes::Signature.
int ParamsSize (void) const
 Return number of parameters with current signature.
void ParamValue (int n, Type *param)
 Set parameter at certain position.
TypeParamValue (int n) const
 Get parameter value.
void AllocateValues (void)
 Construct parameter values.
void AllocateValue (int i)
void FreeValues (void)
 Destruct parameter values.
void TypeCheck (void)
 Perform a type check on the current parameter values.
bool StrictTypeCheck (void) const
 Depreciated / untested.
void Execute (void)
 Perform operation.

Protected Member Functions

void Variant (const Signature *pVar)
 Set signature as specified.
template<class T>
void DoTypeCast (int n, T *&rTypedRef)
 Helper: generate typed reference for parameter.
virtual void DoTypeCheck ()=0
 Method to compare types of arguments with arguments of assigned faudes::Signature (i.e.
virtual void DoExecute ()=0
 Executes code of reimplemented method of child class(es).
void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write function-data (typeid-name of arguments) to TokenWriter.

Protected Attributes

const FunctionDefinitionpFuncDef
 corresponding function definition
const SignaturepVariant
 current variant aka signature
std::vector< Type * > mParameterValues
 Vector of arguments.


Constructor & Destructor Documentation

faudes::Function::Function ( const FunctionDefinition fdef  ) 

Constructor For the function to be operational, a valid reference to the corresponding FunctionDefinition is required.

The only exception is the prototype function object used in the FunctionDefinition itself.

faudes::Function::~Function (  )  [inline]

Destructor.


Member Function Documentation

virtual Function* faudes::Function::New (  )  const [pure virtual]

Construct on heap.

Create a new instance of this function class and return pointer. The new instance will use the same function definition as this instance.

Returns:
Pointer to faudes::Function instance.

Reimplemented from faudes::Type.

Implemented in faudes::TSimpleFunction1< FTYPE0, CFNCT >, faudes::TSimpleFunction2< FTYPE0, FTYPE1, CFNCT >, faudes::TSimpleFunction3< FTYPE0, FTYPE1, FTYPE2, CFNCT >, and faudes::TNestedFunction< FTYPE, CFNCT >.

void faudes::Function::Definition ( const FunctionDefinition fdef  ) 

Set function definition.

Normally, functions are provided with a function definition on construction. The only exception are prototype objects used in function definitions themselfs and in the function registry.

Parameters:
fdef Function definition to set.

const FunctionDefinition * faudes::Function::Definition ( void   )  const

Get function definition.

Returns:
Function definition used by this function.

int faudes::Function::VariantsSize ( void   )  const

Return number of variants.

Returns:
Size of vector.

void faudes::Function::Variant ( int  n  ) 

Set signature from function definition.

The index n refers this function's FunctionDefinition. An exception is thrown if no such FunctionDefinition is set, as it is the case for prototype instances.

Parameters:
n Variant index
Exceptions:
Exception 
  • No function definition available (id 47)

void faudes::Function::Variant ( const std::string &  rVariantName  ) 

Set signature from function definition.

The name refers to this function's FunctionDefinition. An exception is thrown if no such FunctionDefinition is set, as it is the case for prototype instances.

Parameters:
rVariantName Variant name
Exceptions:
Exception 
  • No function definition available (id 47)

const Signature * faudes::Function::Variant ( void   )  const

Return pointer to assigned faudes::Signature.

Returns:
Pointer to faudes::Signature.

int faudes::Function::ParamsSize ( void   )  const

Return number of parameters with current signature.

Returns:
Size of vector.

void faudes::Function::ParamValue ( int  n,
Type param 
)

Set parameter at certain position.

Sets the internal refernce of the parameter value at the spcefied index. The ownership of the value remains with the caller, ie it will not be deleted in the destructor of the function object. You may set the parameter value to any faudes type (classes derived from Type). A type check will be performed before the function is executed.

Parameters:
n Position index of parameter
param Pointer to faudes object.
Exceptions:
Exception 
  • Index out of range (id 47)
  • No variant set (id 47)

Type * faudes::Function::ParamValue ( int  n  )  const

Get parameter value.

Returns a reference to the parameter value at the specified position.

Parameters:
n Position index of parameter.
Exceptions:
Exception 
  • Index out of range (id 47)

void faudes::Function::AllocateValues ( void   ) 

Construct parameter values.

This is a convenience method to allocate faudes objects for parameter values with the type specified by the current signature. Note that the function does not take ownetship of the parameter values and it is the callers responsibility to delete them when no longer required.

void faudes::Function::AllocateValue ( int  i  ) 

void faudes::Function::FreeValues ( void   ) 

Destruct parameter values.

This is a convenience method to delete the assigned paramer values.

void faudes::Function::TypeCheck ( void   ) 

Perform a type check on the current parameter values.

The type check is based on c type cast and should accept any types derived from those given in the signature.

Exceptions:
Exception 
  • No variant specified (id 48)
  • Number of parameters does not match signature (id 48)
  • Type mismatch (id 48)

bool faudes::Function::StrictTypeCheck ( void   )  const

Depreciated / untested.

void faudes::Function::Execute ( void   ) 

Perform operation.

Runs a type cheack and then the actual function.

Exceptions:
Exception 
  • No variant specified (id 48)
  • Parameter position out of range (id 48)
  • Type mismatch (id 48)
  • Any other exception thrown ba the actual function (id xxx)

void faudes::Function::Variant ( const Signature pVar  )  [protected]

Set signature as specified.

This method allows to set any signature. Since the function will only support particular signatures, you should use Variant(int n) whenever possible.

Parameters:
pVar Pointer to faudes::Signature.

template<class T>
void faudes::Function::DoTypeCast ( int  n,
T *&  rTypedRef 
) [inline, protected]

Helper: generate typed reference for parameter.

Parameters:
n Parameter position to cast
rTypedRef Typed reference to generyte
Template Parameters:
T c type to use for cast
Exceptions:
Exception 
  • No variant specified (id 48)
  • Parameter position out of range (id 48)
  • Type mismatch (id 48)

virtual void faudes::Function::DoTypeCheck (  )  [protected, pure virtual]

Method to compare types of arguments with arguments of assigned faudes::Signature (i.e.

their TypeDefinition label).

NOTE: Method is called by Function::Execute().

Exceptions:
Exception 

Implemented in faudes::TSimpleFunction1< FTYPE0, CFNCT >, faudes::TSimpleFunction2< FTYPE0, FTYPE1, CFNCT >, faudes::TSimpleFunction3< FTYPE0, FTYPE1, FTYPE2, CFNCT >, and faudes::TNestedFunction< FTYPE, CFNCT >.

virtual void faudes::Function::DoExecute (  )  [protected, pure virtual]

void faudes::Function::DoWrite ( TokenWriter rTw,
const std::string &  rLabel = "",
const Type pContext = 0 
) const [protected, virtual]

Write function-data (typeid-name of arguments) to TokenWriter.

Parameters:
rTw Reference to Tokenwriter.
rLabel Label of section to write.
pContext Context pointer, ignored
Exceptions:
Exception 
  • IO Error

Reimplemented from faudes::Type.


Member Data Documentation

corresponding function definition

current variant aka signature

std::vector<Type*> faudes::Function::mParameterValues [protected]

Vector of arguments.


The documentation for this class was generated from the following files:

libFAUDES 2.13a c++ source docu by doxygen 1.5.6