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

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

#include <cfl_functions.h>

List of all members.

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.
virtual 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 (void) 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.
bool TypeCheck (int n)
 Perform a type check one parameter value.
bool TypeCheck (void)
 Perform a type check on the list of current parameter values.
void Execute (void)
 Perform operation.

Protected Member Functions

template<class T >
bool DoTypeCast (int n, T *&rTypedRef)
 Helper: generate typed reference for parameter.
virtual void DoVariant (int n)
virtual bool DoTypeCheck (int n)=0
 Method to test the type of an assigned parameter with the specified 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
int mVariantIndex
 current variant aka signature as index w.r.t.
std::vector< Type * > mParameterValues
 Vector of arguments.

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

  • select a variant signature, see Variant();
  • set and get parameter values of any faudes type, see ParamValue();
  • type check the provided parameter values, see TypeCheck();
  • perform the operation, see Execute().

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:

See IntegerSum in the autogenerated ./include/rtiautoload.h" 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 must be aware of its signature(s). You must not delete the FunctionDefinition object during the lifetime of a faudes-function.

Definition at line 722 of file cfl_functions.h.


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.

Definition at line 567 of file cfl_functions.cpp.

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

Destructor.

Definition at line 734 of file cfl_functions.h.


Member Function Documentation

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

Definition at line 695 of file cfl_functions.cpp.

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.

Definition at line 711 of file cfl_functions.cpp.

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

Get function definition.

Returns:
Function definition used by this function.

Reimplemented in faudes::LuaFunction.

Definition at line 600 of file cfl_functions.cpp.

void faudes::Function::Definition ( const FunctionDefinition fdef  )  [virtual]

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.

Reimplemented in faudes::LuaFunction.

Definition at line 584 of file cfl_functions.cpp.

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

Executes code of reimplemented method of child class(es).

Implemented in faudes::LuaFunction.

template<class T >
bool 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
Returns:
True if cast succeeded.
Exceptions:
Exception 
  • No variant specified (id 48)
  • Parameter position out of range (id 48)

Definition at line 950 of file cfl_functions.h.

virtual bool faudes::Function::DoTypeCheck ( int  n  )  [protected, pure virtual]

Method to test the type of an assigned parameter with the specified faudes::Signature (i.e.

their TypeDefinition label).

Note: this method is called by Function::Execute() before actual function execution via DoExecute(). It may be used to perform a dynamic cast in preparation of DoExecute(). The latter is only called, if all types match.

Parameters:
n Position of parameter to check
Returns:
True if type matches signature.
Exceptions:
Exception 

Implemented in faudes::LuaFunction.

void faudes::Function::DoVariant ( int  n  )  [protected, virtual]

Reimplemented in faudes::LuaFunction.

Definition at line 618 of file cfl_functions.cpp.

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.

Definition at line 781 of file cfl_functions.cpp.

void faudes::Function::Execute ( void   ) 

Perform operation.

Runs a type check 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)

Definition at line 760 of file cfl_functions.cpp.

void faudes::Function::FreeValues ( void   ) 

Destruct parameter values.

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

Definition at line 718 of file cfl_functions.cpp.

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::LuaFunction.

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

Return number of parameters with current signature.

Returns:
Size of vector.

Definition at line 669 of file cfl_functions.cpp.

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)

Definition at line 684 of file cfl_functions.cpp.

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)

Definition at line 674 of file cfl_functions.cpp.

bool faudes::Function::TypeCheck ( void   ) 

Perform a type check on the list of current parameter values.

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

Returns:
True if all parameter types matche the signature
Exceptions:
Exception 
  • No variant specified (id 48)
  • Number of parameters does not match signature (id 48)

Definition at line 746 of file cfl_functions.cpp.

bool faudes::Function::TypeCheck ( int  n  ) 

Perform a type check one parameter value.

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

Parameters:
n Position of parameter to check
Returns:
True if type matches
Exceptions:
Exception 
  • No variant specified (id 48)
  • Number of parameter is outside the specified signature (id 48)

Definition at line 728 of file cfl_functions.cpp.

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

Return pointer to assigned faudes::Signature.

Returns:
Pointer to faudes::Signature.

Definition at line 662 of file cfl_functions.cpp.

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)
  • No such variant (id 48)

Definition at line 642 of file cfl_functions.cpp.

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)
  • No such variant (id 48)

Definition at line 612 of file cfl_functions.cpp.

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

Return number of variants.

Returns:
Size of vector.

Definition at line 606 of file cfl_functions.cpp.


Member Data Documentation

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

Vector of arguments.

Definition at line 1027 of file cfl_functions.h.

current variant aka signature as index w.r.t.

the function definition

Definition at line 1024 of file cfl_functions.h.

corresponding function definition

Definition at line 1021 of file cfl_functions.h.


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

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen