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 714 of file cfl_functions.h.

#include <cfl_functions.h>

Public Member Functions

 Function (const FunctionDefinition *fdef)
 Constructor For the function to be operational, a valid reference to the corresponding FunctionDefinition is required. More...
 
 ~Function ()
 Destructor. More...
 
virtual FunctionNew () const =0
 Construct on heap. More...
 
virtual void Definition (const FunctionDefinition *fdef)
 Set function definition. More...
 
const FunctionDefinitionDefinition (void) const
 Get function definition. More...
 
int VariantsSize (void) const
 Return number of variants. More...
 
void Variant (int n)
 Set signature from function definition. More...
 
void Variant (const std::string &rVariantName)
 Set signature from function definition. More...
 
const SignatureVariant (void) const
 Return pointer to assigned faudes::Signature. More...
 
int ParamsSize (void) const
 Return number of parameters with current signature. More...
 
void ParamValue (int n, Type *param)
 Set parameter at certain position. More...
 
TypeParamValue (int n) const
 Get parameter value. More...
 
void AllocateValues (void)
 Construct parameter values. More...
 
void AllocateValue (int i)
 
void FreeValues (void)
 Destruct parameter values. More...
 
bool TypeCheck (int n)
 Perform a type check one parameter value. More...
 
bool TypeCheck (void)
 Perform a type check on the list of current parameter values. More...
 
void Execute (void)
 Perform operation. More...
 
- Public Member Functions inherited from faudes::Type
 Type (void)
 Constructor. More...
 
 Type (const Type &rType)
 Copy constructor. More...
 
virtual ~Type (void)
 Destructor. More...
 
virtual TypeCopy (void) const
 Construct on heap. More...
 
virtual const TypeCast (const Type *pOther) const
 Cast other object to this type. More...
 
virtual void Clear (void)
 Clear configuration data. More...
 
virtual TypeAssign (const Type &rSrc)
 Assign configuration data from other object. More...
 
virtual Typeoperator= (const Type &rSrc)
 Assign configurationdata from other object. More...
 
virtual bool Equal (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual bool operator== (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual bool operator!= (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual void Name (const std::string &rName)
 Set the objects's name. More...
 
virtual const std::string & Name (void) const
 Get objects's name. More...
 
virtual const std::string & TypeName (void) const
 Get objects's type name. More...
 
void Write (const Type *pContext=0) const
 Write configuration data to console. More...
 
void Write (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 Write configuration data to a file. More...
 
void Write (const std::string &pFileName, std::ios::openmode openmode) const
 Write configuration data to a file. More...
 
void Write (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to TokenWriter. More...
 
virtual void XWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to an XML file. More...
 
void XWrite (const Type *pContext=0) const
 Write configuration data in XML format to concole Note: this write function uses the virtual function DoXWrite(), to be reimplemented by derived classes. More...
 
void XWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in XML format to TokenWriter. More...
 
std::string ToString (const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to a string. More...
 
std::string ToText (const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to a formated string. More...
 
void DWrite (const Type *pContext=0) const
 Write configuration data to console, debugging format. More...
 
void DWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 Write configuration data to a file, debugging format. More...
 
void DWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in debug format to TokenWriter. More...
 
void SWrite (TokenWriter &rTw) const
 Write statistics comment to TokenWriter. More...
 
void SWrite (void) const
 Write statistics comment to console. More...
 
std::string ToSText (void) const
 Write statistics to a string. More...
 
void Read (const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from file with label specified. More...
 
void FromString (const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from a string. More...
 
void Read (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from TokenReader with label sepcified. More...
 

Protected Member Functions

template<class T >
bool DoTypeCast (int n, T *&rTypedRef)
 Helper: generate typed reference for parameter. More...
 
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. More...
 
virtual void DoExecute ()=0
 Executes code of reimplemented method of child class(es). More...
 
void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write function-data (typeid-name of arguments) to TokenWriter. More...
 
- Protected Member Functions inherited from faudes::Type
void DoAssign (const Type &rSrc)
 Assign configuration data from other object. More...
 
bool DoEqual (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data of this object from TokenReader. More...
 
virtual void DoXWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data of this object to TokenWriter in XML format. More...
 
virtual void DoDWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in debugging format to TokenWriter. More...
 
virtual void DoSWrite (TokenWriter &rTw) const
 Write statistical data as a comment to TokenWriter. More...
 
virtual const TypeDefinitionTypeDefinitionp (void) const
 Get objects's type definition. More...
 
virtual Token XBeginTag (const std::string &rLabel="", const std::string &rFallbackLabel="") const
 

Protected Attributes

const FunctionDefinitionpFuncDef
 corresponding function definition More...
 
int mVariantIndex
 current variant aka signature as index w.r.t. More...
 
std::vector< Type * > mParameterValues
 Vector of arguments. More...
 

Constructor & Destructor Documentation

◆ Function()

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.

◆ ~Function()

faudes::Function::~Function ( )
inline

Destructor.

Definition at line 726 of file cfl_functions.h.

Member Function Documentation

◆ AllocateValue()

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

Definition at line 695 of file cfl_functions.cpp.

◆ AllocateValues()

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.

◆ Definition() [1/2]

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
fdefFunction definition to set.

Reimplemented in faudes::LuaFunction.

Definition at line 584 of file cfl_functions.cpp.

◆ Definition() [2/2]

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

Get function definition.

Returns
Function definition used by this function.

Definition at line 600 of file cfl_functions.cpp.

◆ DoExecute()

virtual void faudes::Function::DoExecute ( )
protectedpure virtual

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

Implemented in faudes::LuaFunction.

◆ DoTypeCast()

template<class T >
bool faudes::Function::DoTypeCast ( int  n,
T *&  rTypedRef 
)
inlineprotected

Helper: generate typed reference for parameter.

Parameters
nParameter position to cast
rTypedRefTyped reference to generyte
Template Parameters
Tc 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 942 of file cfl_functions.h.

◆ DoTypeCheck()

virtual bool faudes::Function::DoTypeCheck ( int  n)
protectedpure 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
nPosition of parameter to check
Returns
True if type matches signature.
Exceptions
Exception

Implemented in faudes::LuaFunction.

◆ DoVariant()

void faudes::Function::DoVariant ( int  n)
protectedvirtual

Reimplemented in faudes::LuaFunction.

Definition at line 618 of file cfl_functions.cpp.

◆ DoWrite()

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

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

Parameters
rTwReference to Tokenwriter.
rLabelLabel of section to write.
pContextContext pointer, ignored
Exceptions
Exception
  • IO Error

Reimplemented from faudes::Type.

Definition at line 781 of file cfl_functions.cpp.

◆ Execute()

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.

◆ FreeValues()

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.

◆ New()

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.

◆ ParamsSize()

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.

◆ ParamValue() [1/2]

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

Get parameter value.

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

Parameters
nPosition index of parameter.
Exceptions
Exception
  • Index out of range (id 47)

Definition at line 684 of file cfl_functions.cpp.

◆ ParamValue() [2/2]

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
nPosition index of parameter
paramPointer 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.

◆ TypeCheck() [1/2]

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
nPosition 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.

◆ TypeCheck() [2/2]

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.

◆ Variant() [1/3]

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
rVariantNameVariant name
Exceptions
Exception
  • No function definition available (id 47)
  • No such variant (id 48)

Definition at line 642 of file cfl_functions.cpp.

◆ Variant() [2/3]

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
nVariant index
Exceptions
Exception
  • No function definition available (id 47)
  • No such variant (id 48)

Definition at line 612 of file cfl_functions.cpp.

◆ Variant() [3/3]

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.

◆ VariantsSize()

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

◆ mParameterValues

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

Vector of arguments.

Definition at line 1019 of file cfl_functions.h.

◆ mVariantIndex

int faudes::Function::mVariantIndex
protected

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

the function definition

Definition at line 1016 of file cfl_functions.h.

◆ pFuncDef

const FunctionDefinition* faudes::Function::pFuncDef
protected

corresponding function definition

Definition at line 1013 of file cfl_functions.h.


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

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen