Detailed Description

The FunctionRegistry registers faudes-functions.

A faudes-functions operates on faudes objects, eg the parallel composition of two generators is available as faudes-function. The registry maintains a mapping between function names and a coresponding function::Definition. The latter provides signatures, ie parameter types the function can take. The registry provides an interface to inspect TypeDefinitions or to construct function objects by their type name.

Technical note: the class is implemented according to the "Singleton" design pattern, ie, only one global instance of the registry can exist.

Definition at line 496 of file cfl_registry.h.

#include <cfl_registry.h>

Public Types

typedef std::map< std::string, FunctionDefinition * >::const_iterator Iterator
 Convenience typedef to access registry entries. More...
 

Public Member Functions

void Clear ()
 Clear all registered function definitions. More...
 
int Size () const
 Return number of registered function definitions. More...
 
bool Exists (const std::string &rName) const
 Test existence of a faudes-function by its name. More...
 
bool Exists (const Function &rFunction) const
 Test existence of a faudes-function by faudes object. More...
 
Iterator Begin (void) const
 STL interator to the internal function-name map. More...
 
Iterator End (void) const
 STL interator to the internal function-name map. More...
 
void Insert (FunctionDefinition *pFunctionDef)
 Add another function definition to the registry. More...
 
template<class T >
void Insert (const std::string &rFunctionName="")
 Register a faudes-function with specified function name. More...
 
void MergeDocumentation (TokenReader &rTr)
 Scan token input for function documentation. More...
 
void MergeDocumentation (const std::string &rFileName)
 Scan file for function documentation. More...
 
FunctionNewFunction (const std::string &rFunctionName) const
 Construct a faudes object by function name. More...
 
FunctionNewFunction (const Function &rFunction) const
 Construct a faudes object by protofunction object. More...
 
const FunctionDefinitionDefinition (const std::string &rFunctionName) const
 Look up the function definition by faudes-function name. More...
 
const FunctionDefinitionDefinition (const Function &rFunction) const
 Look up the function definition by faudes object. More...
 
const std::string & FunctionName (const Function &rFunction) const
 Look up the function name by faudes object. 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 TypeNew (void) const
 Construct on heap. More...
 
virtual TypeCopy (void) const
 Construct on heap. More...
 
virtual const TypeCast (const Type *pOther) const
 Cast other object to this type. 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...
 

Static Public Member Functions

static FunctionRegistryG ()
 Method to access the single global instance of the registry. More...
 

Protected Types

typedef std::map< std::string, FunctionDefinition * >::iterator iterator
 Convenience typedef to access registry entries. More...
 

Protected Member Functions

virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write registry data of this to TokenWriter. More...
 
 FunctionRegistry ()
 Constructor. More...
 
virtual ~FunctionRegistry ()
 Destructor. 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

std::map< std::string, FunctionDefinition * > mNameToFunctionDef
 Map to associate labels and faudes::FunctionDefinitions. More...
 
std::map< std::string, FunctionDefinition * > mIdToFunctionDef
 

Static Protected Attributes

static FunctionRegistrympInstance = 0
 Singleton instance. More...
 

Member Typedef Documentation

◆ Iterator

typedef std::map<std::string, FunctionDefinition*>::const_iterator faudes::FunctionRegistry::Iterator

Convenience typedef to access registry entries.

Definition at line 501 of file cfl_registry.h.

◆ iterator

typedef std::map<std::string, FunctionDefinition*>::iterator faudes::FunctionRegistry::iterator
protected

Convenience typedef to access registry entries.

Definition at line 720 of file cfl_registry.h.

Constructor & Destructor Documentation

◆ FunctionRegistry()

faudes::FunctionRegistry::FunctionRegistry ( )
inlineprotected

Constructor.

Definition at line 726 of file cfl_registry.h.

◆ ~FunctionRegistry()

virtual faudes::FunctionRegistry::~FunctionRegistry ( )
inlineprotectedvirtual

Destructor.

Definition at line 729 of file cfl_registry.h.

Member Function Documentation

◆ Begin()

FunctionRegistry::Iterator faudes::FunctionRegistry::Begin ( void  ) const

STL interator to the internal function-name map.

Returns
Iterator to the first element.

Definition at line 428 of file cfl_registry.cpp.

◆ Clear()

void faudes::FunctionRegistry::Clear ( void  )
virtual

Clear all registered function definitions.

This will also delete the correponsing prototype objects.

Reimplemented from faudes::Type.

Definition at line 406 of file cfl_registry.cpp.

◆ Definition() [1/2]

const FunctionDefinition & faudes::FunctionRegistry::Definition ( const Function rFunction) const

Look up the function definition by faudes object.

Techcal note: this implementation is slow, we should use a function id map.

Parameters
rFunctionReference to faudes::Function to search for.
Returns
Reference to faudes::FunctionDefinition
Exceptions
Exception
  • Unknown function (id 46)

Definition at line 550 of file cfl_registry.cpp.

◆ Definition() [2/2]

const FunctionDefinition & faudes::FunctionRegistry::Definition ( const std::string &  rFunctionName) const

Look up the function definition by faudes-function name.

Parameters
rFunctionNameLabel of faudes::FunctionDefinition to search for.
Returns
Reference to faudes::FunctionDefinition
Exceptions
Exception
  • Unknown function (id 46)

Definition at line 538 of file cfl_registry.cpp.

◆ DoWrite()

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

Write registry data of this to TokenWriter.

Since the registry cannot reconfigure itself from a token stream, this output is informative only. However, MergeDocumentation will accept the format to insert/extract documentation.

Parameters
rTwReference to TokenWriter
rLabelLabel of section to write
pContextWrite context to provide contextual information
Exceptions
Exception
  • IO errors (id 2)

Reimplemented from faudes::Type.

Definition at line 582 of file cfl_registry.cpp.

◆ End()

FunctionRegistry::Iterator faudes::FunctionRegistry::End ( void  ) const

STL interator to the internal function-name map.

Returns
Iterator to the end of the map.

Definition at line 433 of file cfl_registry.cpp.

◆ Exists() [1/2]

bool faudes::FunctionRegistry::Exists ( const Function rFunction) const

Test existence of a faudes-function by faudes object.

Parameters
rFunctionObject of function to look up
Returns
True, if a corresponding definition is registered.

Definition at line 576 of file cfl_registry.cpp.

◆ Exists() [2/2]

bool faudes::FunctionRegistry::Exists ( const std::string &  rName) const

Test existence of a faudes-function by its name.

Parameters
rNameName of function to look up
Returns
True, if a corresponding definition is registered.

Definition at line 571 of file cfl_registry.cpp.

◆ FunctionName()

const std::string & faudes::FunctionRegistry::FunctionName ( const Function rFunction) const

Look up the function name by faudes object.

Parameters
rFunctionReference to faudes::Function to search for.
Returns
Function name as string or "" if unknown.

Definition at line 561 of file cfl_registry.cpp.

◆ G()

FunctionRegistry * faudes::FunctionRegistry::G ( void  )
static

Method to access the single global instance of the registry.

Definition at line 396 of file cfl_registry.cpp.

◆ Insert() [1/2]

template<class T >
void faudes::FunctionRegistry::Insert ( const std::string &  rFunctionName = "")
inline

Register a faudes-function with specified function name.

This is a convenience function: it uses the template parameter to construct the new instance of FunctionDefinition to be registered. However, no documentation is added. See also MergeDocumentation.

Template Parameters
TTemplate parameter to specify c++ function to register
Parameters
rFunctionNameSpecify the faudes-function name
Exceptions
Exception
  • Identical name found (id 46)

Definition at line 590 of file cfl_registry.h.

◆ Insert() [2/2]

void faudes::FunctionRegistry::Insert ( FunctionDefinition pFunctionDef)

Add another function definition to the registry.

The registry takes the ownership pf the provided function definition. It will be deleted either in Clear() or when the registry is destructed.

Parameters
pFunctionDefFunction definition to insert
Exceptions
Exception
  • Identical name found (id 46)

Definition at line 438 of file cfl_registry.cpp.

◆ MergeDocumentation() [1/2]

void faudes::FunctionRegistry::MergeDocumentation ( const std::string &  rFileName)

Scan file for function documentation.

Convenience method, see also MergeDocumentation(TokenReader& rTr)

Parameters
rFileNameName of file to scan.
Exceptions
Exception
  • Token mismatch (id 50, 51, 52)
  • IO Error (id 1)

Definition at line 500 of file cfl_registry.cpp.

◆ MergeDocumentation() [2/2]

void faudes::FunctionRegistry::MergeDocumentation ( TokenReader rTr)

Scan token input for function documentation.

This function scans the entire token stream for sections with label "FunctionDefinition". Any such section that refers to a function name which is known to the registry, will be applied to the corresponding registry entry.

Parameters
rTrToken stream.
Exceptions
Exception
  • Token mismatch (id 50, 51, 52)
  • IO Error (id 1)

Definition at line 467 of file cfl_registry.cpp.

◆ NewFunction() [1/2]

Function * faudes::FunctionRegistry::NewFunction ( const Function rFunction) const

Construct a faudes object by protofunction object.

Depreciated: use new on the faudes object instead.

Parameters
rFunctionProtofunction object.
Returns
Pointer to new faudes::Function instance
Exceptions
Exception
  • Unknown function (id 47)

Definition at line 525 of file cfl_registry.cpp.

◆ NewFunction() [2/2]

Function * faudes::FunctionRegistry::NewFunction ( const std::string &  rFunctionName) const

Construct a faudes object by function name.

Uses the internal prototype object to construct an object of the same c function on the heap.

Parameters
rFunctionNameLabel of FunctionDefinition to search for.
Returns
Pointer to new faudes::Function instance
Exceptions
Exception
  • Unknown function (id 47)

Definition at line 507 of file cfl_registry.cpp.

◆ Size()

int faudes::FunctionRegistry::Size ( void  ) const

Return number of registered function definitions.

Returns
Size of map.

Definition at line 423 of file cfl_registry.cpp.

Member Data Documentation

◆ mIdToFunctionDef

std::map<std::string, FunctionDefinition*> faudes::FunctionRegistry::mIdToFunctionDef
protected

Definition at line 735 of file cfl_registry.h.

◆ mNameToFunctionDef

std::map<std::string, FunctionDefinition*> faudes::FunctionRegistry::mNameToFunctionDef
protected

Map to associate labels and faudes::FunctionDefinitions.

Definition at line 734 of file cfl_registry.h.

◆ mpInstance

FunctionRegistry * faudes::FunctionRegistry::mpInstance = 0
staticprotected

Singleton instance.

Definition at line 723 of file cfl_registry.h.


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

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