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

#include <cfl_functions.h>

Public Member Functions

 Function (const FunctionDefinition *fdef)
 
 ~Function ()
 
virtual FunctionNew () const =0
 
virtual void Definition (const FunctionDefinition *fdef)
 
const FunctionDefinitionDefinition (void) const
 
int VariantsSize (void) const
 
void Variant (int n)
 
void Variant (const std::string &rVariantName)
 
const SignatureVariant (void) const
 
int ParamsSize (void) const
 
void ParamValue (int n, Type *param)
 
TypeParamValue (int n) const
 
void AllocateValues (void)
 
void AllocateValue (int i)
 
void FreeValues (void)
 
bool TypeCheck (int n)
 
bool TypeCheck (void)
 
void Execute (void)
 
Typeoperator= (const Type &rSrc)
 
Typeoperator= (Type &&rSrc)
 
- Public Member Functions inherited from faudes::Type
 Type (void)
 
 Type (const Type &rType)
 
virtual ~Type (void)
 
virtual TypeNewCpy (void) const
 
virtual const TypeCast (const Type *pOther) const
 
virtual void Clear (void)
 
virtual bool IsDefault (void) const
 
virtual TypeCopy (const Type &rSrc)
 
virtual TypeMove (Type &rSrc)
 
Typeoperator= (const Type &rSrc)
 
Typeoperator= (Type &&rSrc)
 
virtual bool Equal (const Type &rOther) const
 
bool operator== (const Type &rOther) const
 
bool operator!= (const Type &rOther) const
 
virtual void Name (const std::string &rName)
 
virtual const std::string & Name (void) const
 
virtual const std::string & TypeName (void) const
 
void Write (const Type *pContext=0) const
 
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
 
void Write (const std::string &pFileName, std::ios::openmode openmode) const
 
void Write (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void XWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
 
void XWrite (const Type *pContext=0) const
 
void XWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
std::string ToString (const std::string &rLabel="", const Type *pContext=0) const
 
std::string ToText (const std::string &rLabel="", const Type *pContext=0) const
 
void DWrite (const Type *pContext=0) const
 
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
 
void DWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
void SWrite (TokenWriter &rTw) const
 
void SWrite (void) const
 
std::string ToSText (void) const
 
void Read (const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
 
void FromString (const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
 
void Read (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 

Protected Member Functions

template<class T >
bool DoTypeCast (int n, T *&rTypedRef)
 
virtual void DoVariant (int n)
 
virtual bool DoTypeCheck (int n)=0
 
virtual void DoExecute ()=0
 
void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
- Protected Member Functions inherited from faudes::Type
void DoCopy (const Type &rSrc)
 
void DoMove (Type &rSrc)
 
bool DoEqual (const Type &rOther) const
 
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 
virtual void DoXWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoDWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoSWrite (TokenWriter &rTw) const
 
virtual const TypeDefinitionTypeDefinitionp (void) const
 
virtual Token XBeginTag (const std::string &rLabel="", const std::string &rFallbackLabel="") const
 

Protected Attributes

const FunctionDefinitionpFuncDef
 
int mVariantIndex
 
std::vector< Type * > mParameterValues
 

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 569 of file cfl_functions.cpp.

◆ ~Function()

faudes::Function::~Function ( )
inline

Destructor

Definition at line 734 of file cfl_functions.h.

Member Function Documentation

◆ AllocateValue()

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

Definition at line 697 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 713 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 586 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 602 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 950 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 620 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 783 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 762 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 720 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.

◆ operator=() [1/2]

Type & faudes::Type::operator= ( const Type rSrc)

Copy configuration data from other object. Derived classes should implement at least the signature with matching source and destination types via the DoCopy method. Additionally, one may implement variants with a base class as source, as mong as meaningul assigment is possible.

Re-implementation can be done via the convenience macros FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.

Parameters
rSrcSource to copy from
Returns
Reference to this object.

Definition at line 368 of file cfl_types.cpp.

◆ operator=() [2/2]

Type & faudes::Type::operator= ( Type &&  rSrc)

Copy configuration data from other object (destructive) Derived classes should implement at least the signature with matching source and destination types via the DoCopy method. Additionally, one may implement variants with a base class as source, as mong as meaningul assigment is possible.

Re-implementation can be done via the convenience macros FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.

Parameters
rSrcSource to copy from
Returns
Reference to this object.

Definition at line 383 of file cfl_types.cpp.

◆ ParamsSize()

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

Return number of parameters with current signature.

Returns
Size of vector.

Definition at line 671 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 686 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 676 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 730 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 748 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 644 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 614 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 664 of file cfl_functions.cpp.

◆ VariantsSize()

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

Return number of variants.

Returns
Size of vector.

Definition at line 608 of file cfl_functions.cpp.

Member Data Documentation

◆ mParameterValues

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

Vector of arguments.

Definition at line 1027 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 1024 of file cfl_functions.h.

◆ pFuncDef

const FunctionDefinition* faudes::Function::pFuncDef
protected

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.34d --- 2026.03.11 --- c++ api documentaion by doxygen