Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 5 (modified by landauf, 16 years ago) (diff)

Factory

TracNav(TracNav/TOC_Development)?

Description

The Factory is a singleton? that maps Identifiers with their name and their network ID. The Factory is used by the CreateFactory(classname) macro (include CoreIncludes.h to use it) to add new entries and by the ID("classname") and ID(network ID) macros (include CoreIncludes.h to use them) to retrieve an Identifier with a given classname or a given network ID respectively. The ID macro is an abbreviation of the static function Factory::getIdentifier(…). The Factory also handles the change of a network ID to avoid conflicts with ambiguous map-entries.

Because the Factory knows all Identifiers with a ClassFactory, it provides functions to get the map-iterators to iterate through all stored Identifiers.

Functions

  • Identifiers:
    • add(name, identifier) adds an Identifier with a given name (this is usually done by the CreateFactory(classname) macro (read the Wiki-page of CoreIncludes for more information).
    • getIdentifier(name) and getIdentifier(network ID) return the Identifier with the given name or the given network ID respectively.
  • Iterators:
    • getFactoryBegin() returns an iterator to the first Identifier in the map.
    • getFactoryEnd() returns an iterator to the last Identifier in the map.

Examples

Identifier* myidentifier = ID("BaseObject");                     // Assigns the BaseObject-Identifier
Identifier* myidentifier = Factory::getIdentifier("BaseObject"); // This does exactly the same
// Returns a list of the names of all Factories in the map

std::map<std::string, Identifier*>::const_iterator it;
for (it = Factory::getFactoryBegin(); it != Factory::getFactoryEnd(); ++it)
  std::cout << (*it)->getName() << std::endl;