Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of code/doc/Factory


Ignore:
Timestamp:
Feb 26, 2008, 6:10:38 PM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/Factory

    v1 v1  
     1= Factory =
     2
     3== Description ==
     4
     5The [wiki:Factory] is a singleton that maps [wiki:Identifier Identifiers] with their name and their network ID. The [wiki:Factory] is used by the !CreateFactory(classname) macro (include [wiki:CoreIncludes CoreIncludes.h] to use it) to add new entries and by the ID("classname") and ID(network ID) macros (include [wiki:CoreIncludes CoreIncludes.h] to use them) to retrieve an [wiki:Identifier] with a given classname or a given network ID respectively. The ID macro is an abbreviation of the static function Factory::getIdentifier(...). The [wiki:Factory] also handles the change of a network ID to avoid conflicts with ambiguous map-entries.
     6
     7Because the [wiki:Factory] knows all Identifiers with a [wiki:ClassFactory], it provides functions to get the map-iterators to iterate through all stored Identifiers.
     8
     9== Functions ==
     10
     11 * '''Identifiers''':
     12   * add(name, identifier) adds an [wiki:Identifier] with a given name (this is usually done by the !CreateFactory(classname) macro (read the Wiki-page of [wiki:CoreIncludes] for more informations).
     13   * getIdentifier(name) and getIdentifier(network ID) return the [wiki:Identifier] with the given name or the given network ID respectively.
     14 * '''Iterators''':
     15   * getFactoryBegin() returns an iterator to the first [wiki:Identifier] in the map.
     16   * getFactoryEnd() returns an iterator to the last [wiki:Identifier] in the map.
     17
     18== Examples ==
     19
     20{{{
     21#!cpp
     22Identifier* myidentifier = ID("BaseObject");                     // Assigns the BaseObject-Identifier
     23Identifier* myidentifier = Factory::getIdentifier("BaseObject"); // This does exactly the same
     24}}}
     25
     26{{{
     27#!cpp
     28// Returns a list of the names of all Factories in the map
     29
     30std::map<std::string, Identifier*>::const_iterator it;
     31for (it = Factory::getFactoryBegin(); it != Factory::getFactoryEnd(); ++it)
     32  std::cout << (*it)->getName() << std::endl;
     33}}}