Detailed Description

The TypeRegistry registers faudes-types.

A faudes-type may be any class derived from faudes::Type, e.g. EventSet and generator. The registry maintains a mapping from faudes-type names to registred faudes::TypeDefinition. It provides an interface to inspect TypeDefinitions or to construct faudes-type 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 47 of file cfl_registry.h.

#include <cfl_registry.h>

Public Types

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

Public Member Functions

void Clear ()
 Clear all registered type definitions. More...
 
void ClearAll ()
 Clear all registered type definitions. More...
 
int Size () const
 Return number of registered type definitions. More...
 
bool Exists (const std::string &rName) const
 Test existence of a faudes-type by its name. More...
 
bool Exists (const Type &rType) const
 Test existence of a faudes-type by faudes object. More...
 
Iterator Begin (void) const
 STL interator to the internal type-name map. More...
 
Iterator End (void) const
 STL interator to the internal type-name map. More...
 
void Insert (TypeDefinition *pTypeDef)
 Add another type definition to the registry. More...
 
template<class T >
void Insert (const std::string &rTypeName="")
 Register a faudes-type with specified type name. More...
 
void Insert (Type *pProto, const std::string &rTypeName)
 Register a faudes-type with specified type name. More...
 
void MergeDocumentation (TokenReader &rTr)
 Scan token input for type documentation. More...
 
void MergeDocumentation (const std::string &rFileName)
 Scan file for type documentation. More...
 
void XElementTag (const std::string &rTypeName, const std::string &rTag)
 Set Xml element tag for given faudes-type. More...
 
const std::string & XElementTag (const std::string &rTypeName) const
 Get Xml element tag for given faudes-type. More...
 
bool AutoRegistered (const std::string &rTypeName) const
 Get AutoRegister flag for given faudes-type. More...
 
void AutoRegistered (const std::string &rTypeName, bool flag)
 Set AutoRegistered flag for given faudes-type. More...
 
TypeNewObject (const std::string &rTypeName) const
 Construct a faudes object by type name. More...
 
TypeNewObject (const Type &rType) const
 Construct a faudes object by prototype object. More...
 
const TypeDefinitionDefinition (const std::string &rTypeName) const
 Look up the type definition by faudes-type name. More...
 
const TypeDefinitionDefinition (const Type &rType) const
 Look up the type definition by faudes object. More...
 
const TypeDefinitionDefinitionp (const std::string &rTypeName) const
 Look up the type definition by faudes-type name. More...
 
const TypeDefinitionDefinitionp (const Type &rType) const
 Look up the type definition by faudes object. More...
 
const TypePrototype (const std::string &rTypeName) const
 Look up the prototype object by faudes-type name. More...
 
const std::string & TypeName (const Type &rType) const
 Look up the type name by faudes object. More...
 
bool TypeTest (const std::string &rTypeName, const Type &rObject) const
 Test type compatibility. More...
 
virtual const std::string & TypeName (void) const
 Cosmetic: fix compile warning for recent LLVM/clang++. 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...
 
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 TypeRegistryG ()
 Method to access the single global instance of the registry. More...
 

Protected Types

typedef std::map< std::string, TypeDefinition * >::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...
 
 TypeRegistry ()
 Constructor. More...
 
virtual ~TypeRegistry ()
 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, TypeDefinition * > mNameToTypeDef
 Map to associate labels and faudes::TypeDefinitions. More...
 
std::map< std::string, TypeDefinition * > mIdToTypeDef
 

Static Protected Attributes

static TypeRegistrympInstance = 0
 Singleton instance. More...
 

Member Typedef Documentation

◆ Iterator

typedef std::map<std::string, TypeDefinition*>::const_iterator faudes::TypeRegistry::Iterator

Convenience typedef to access registry entries.

Definition at line 52 of file cfl_registry.h.

◆ iterator

typedef std::map<std::string, TypeDefinition*>::iterator faudes::TypeRegistry::iterator
protected

Convenience typedef to access registry entries.

Definition at line 421 of file cfl_registry.h.

Constructor & Destructor Documentation

◆ TypeRegistry()

faudes::TypeRegistry::TypeRegistry ( )
inlineprotected

Constructor.

Definition at line 427 of file cfl_registry.h.

◆ ~TypeRegistry()

virtual faudes::TypeRegistry::~TypeRegistry ( )
inlineprotectedvirtual

Destructor.

Definition at line 430 of file cfl_registry.h.

Member Function Documentation

◆ AutoRegistered() [1/2]

bool faudes::TypeRegistry::AutoRegistered ( const std::string &  rTypeName) const

Get AutoRegister flag for given faudes-type.

Access the AutoRegister flag of a type definition. The flag is true for entries which were instantiated automatically by static constructor objects. AutoRegistered flags will not be cleared.

Parameters
rTypeNameName of faudes-type
Returns
AutoRegister flag

Definition at line 239 of file cfl_registry.cpp.

◆ AutoRegistered() [2/2]

void faudes::TypeRegistry::AutoRegistered ( const std::string &  rTypeName,
bool  flag 
)

Set AutoRegistered flag for given faudes-type.

Access the AutoRegister flag of a type definition. The flag is true for entries with were instantiated by automatically by static constructor objects. AutoRegistered flags will not be cleared.

Parameters
rTypeNameName of faudes-type
flagNew value of flag

Definition at line 229 of file cfl_registry.cpp.

◆ Begin()

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

STL interator to the internal type-name map.

Returns
Iterator to the first element.

Definition at line 127 of file cfl_registry.cpp.

◆ Clear()

void faudes::TypeRegistry::Clear ( void  )
virtual

Clear all registered type definitions.

This will also delete the correponsing prototype objects. It will, however, not delete C++-autoregistered registry entries.

Reimplemented from faudes::Type.

Definition at line 72 of file cfl_registry.cpp.

◆ ClearAll()

void faudes::TypeRegistry::ClearAll ( void  )

Clear all registered type definitions.

This will also delete the correponsing prototype objects. This version will also delete C++-autoregistered registry entries.

Definition at line 106 of file cfl_registry.cpp.

◆ Definition() [1/2]

const TypeDefinition & faudes::TypeRegistry::Definition ( const std::string &  rTypeName) const

Look up the type definition by faudes-type name.

Parameters
rTypeNameFaudes-tyep name to search for.
Returns
Reference to faudes::TypeDefinition
Exceptions
Exception
  • Unknown type (id 46)

Definition at line 278 of file cfl_registry.cpp.

◆ Definition() [2/2]

const TypeDefinition & faudes::TypeRegistry::Definition ( const Type rType) const

Look up the type definition by faudes object.

Parameters
rTypeReference to faudes::Type to search for.
Returns
Reference to faudes::TypeDefinition
Exceptions
Exception
  • Unknown type (id 46)

Definition at line 290 of file cfl_registry.cpp.

◆ Definitionp() [1/2]

const TypeDefinition * faudes::TypeRegistry::Definitionp ( const std::string &  rTypeName) const

Look up the type definition by faudes-type name.

Parameters
rTypeNameFaudes-tyep name to search for.
Returns
Pointer to faudes::TypeDefinition, NULL for unknoen type.

Definition at line 301 of file cfl_registry.cpp.

◆ Definitionp() [2/2]

const TypeDefinition * faudes::TypeRegistry::Definitionp ( const Type rType) const

Look up the type definition by faudes object.

Parameters
rTypeReference to faudes::Type to search for.
Returns
Pointer to faudes::TypeDefinition, NULL for unknoen type.

Definition at line 309 of file cfl_registry.cpp.

◆ DoWrite()

void faudes::TypeRegistry::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 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 358 of file cfl_registry.cpp.

◆ End()

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

STL interator to the internal type-name map.

Returns
Iterator to the end of the map.

Definition at line 132 of file cfl_registry.cpp.

◆ Exists() [1/2]

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

Test existence of a faudes-type by its name.

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

Definition at line 347 of file cfl_registry.cpp.

◆ Exists() [2/2]

bool faudes::TypeRegistry::Exists ( const Type rType) const

Test existence of a faudes-type by faudes object.

Parameters
rTypeObject of type to look up
Returns
True, if a corresponding definition is registered.

Definition at line 352 of file cfl_registry.cpp.

◆ G()

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

Method to access the single global instance of the registry.

Definition at line 62 of file cfl_registry.cpp.

◆ Insert() [1/3]

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

Register a faudes-type with specified type name.

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

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

Definition at line 151 of file cfl_registry.h.

◆ Insert() [2/3]

void faudes::TypeRegistry::Insert ( Type pProto,
const std::string &  rTypeName 
)
inline

Register a faudes-type with specified type name.

This is a convenience function: it uses the specified object as a a prototype and registers it under the given name. The registry takes ownership of the prototype. However, no documentation is added. See also MergeDocumentation.

Parameters
pProtoPrototype object
rTypeNameSpecify the faudes-type name
Exceptions
Exception
  • Identical name found (id 46)

Definition at line 172 of file cfl_registry.h.

◆ Insert() [3/3]

void faudes::TypeRegistry::Insert ( TypeDefinition pTypeDef)

Add another type definition to the registry.

The registry takes the ownership pf the provided type definition. It will be deleted either in Clear() or when the registry is destructed. The insertion of an allready registered type is ignored as long as the ctype matches. If the ctype fails to match, an exception is thrown.

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

Definition at line 137 of file cfl_registry.cpp.

◆ MergeDocumentation() [1/2]

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

Scan file for type 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 206 of file cfl_registry.cpp.

◆ MergeDocumentation() [2/2]

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

Scan token input for type documentation.

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

TypeRegistry::G()->Insert<Generator>("Generator");
TypeRegistry::G()->MergeDocumentation("alldocufile.rti");
void MergeDocumentation(TokenReader &rTr)
Scan token input for type documentation.
static TypeRegistry * G()
Method to access the single global instance of the registry.
void Insert(TypeDefinition *pTypeDef)
Add another type definition to the registry.
NameSet EventSet
Convenience typedef for plain event sets.
Definition: cfl_nameset.h:531
vGenerator Generator
Plain generator, api typedef for generator with no attributes.
Parameters
rTrToken stream.
Exceptions
Exception
  • Token mismatch (id 50, 51, 52)
  • IO Error (id 1)

Definition at line 178 of file cfl_registry.cpp.

◆ NewObject() [1/2]

Type * faudes::TypeRegistry::NewObject ( const std::string &  rTypeName) const

Construct a faudes object by type name.

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

Parameters
rTypeNameLabel of TypeDefinition to search for.
Returns
Pointer to new faudes::Type instance
Exceptions
Exception
  • Unknown type (id 47)

Definition at line 247 of file cfl_registry.cpp.

◆ NewObject() [2/2]

Type * faudes::TypeRegistry::NewObject ( const Type rType) const

Construct a faudes object by prototype object.

Depreciated: use new on the faudes object instead.

Parameters
rTypePrototype object.
Returns
Pointer to new faudes::Type instance
Exceptions
Exception
  • Unknown type (id 47)

Definition at line 265 of file cfl_registry.cpp.

◆ Prototype()

const Type * faudes::TypeRegistry::Prototype ( const std::string &  rTypeName) const

Look up the prototype object by faudes-type name.

Parameters
rTypeNameLabel of faudes::TypeDefinition to search for.
Returns
Reference to faudes::Type object, Null for unknown type

Definition at line 318 of file cfl_registry.cpp.

◆ Size()

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

Return number of registered type definitions.

Returns
Size of map.

Definition at line 122 of file cfl_registry.cpp.

◆ TypeName() [1/2]

const std::string & faudes::TypeRegistry::TypeName ( const Type rType) const

Look up the type name by faudes object.

Parameters
rTypeReference to faudes::Type to search for.
Returns
Type name as string or "" if unknown.

Definition at line 326 of file cfl_registry.cpp.

◆ TypeName() [2/2]

const std::string & faudes::Type::TypeName ( void  )
virtual

Cosmetic: fix compile warning for recent LLVM/clang++.

Reimplemented from faudes::Type.

Definition at line 425 of file cfl_types.cpp.

◆ TypeTest()

bool faudes::TypeRegistry::TypeTest ( const std::string &  rTypeName,
const Type rObject 
) const

Test type compatibility.

Test whether the provided object can be casted to the specified type name,

Parameters
rTypeNameFaudes type name
rObjectFaudes object instance
Returns
True, if object can be casted to specified faudes type.

Definition at line 336 of file cfl_registry.cpp.

◆ XElementTag() [1/2]

const std::string & faudes::TypeRegistry::XElementTag ( const std::string &  rTypeName) const

Get Xml element tag for given faudes-type.

Access to the XElementTag of a type definition. The latter is used for Xml token IO of sets and vectors. Unregistered types return the empty string.

Parameters
rTypeNameName of faudes-type
Returns
Xml element tag

Definition at line 220 of file cfl_registry.cpp.

◆ XElementTag() [2/2]

void faudes::TypeRegistry::XElementTag ( const std::string &  rTypeName,
const std::string &  rTag 
)

Set Xml element tag for given faudes-type.

Access to the XElementTag of a type definition. The latter is used for Xml token IO of sets and vectors. Unregistered types are silently ignored.

Parameters
rTypeNameName of faudes-type
rTagNew value of tag

Definition at line 213 of file cfl_registry.cpp.

Member Data Documentation

◆ mIdToTypeDef

std::map<std::string, TypeDefinition*> faudes::TypeRegistry::mIdToTypeDef
protected

Definition at line 436 of file cfl_registry.h.

◆ mNameToTypeDef

std::map<std::string, TypeDefinition*> faudes::TypeRegistry::mNameToTypeDef
protected

Map to associate labels and faudes::TypeDefinitions.

Definition at line 435 of file cfl_registry.h.

◆ mpInstance

TypeRegistry * faudes::TypeRegistry::mpInstance = 0
staticprotected

Singleton instance.

Definition at line 424 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