Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 8 and Version 9 of code/doc/ClassIdentifier


Ignore:
Timestamp:
Sep 29, 2008, 2:24:31 AM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/ClassIdentifier

    v8 v9  
    1717== Description ==
    1818
    19 The ClassIdentifier is a [wiki:template], inherited from [wiki:Identifier], containing all class-specific functions for the class represented by the [wiki:Identifier]. In fact this is only the [wiki:ObjectList].
     19The !ClassIdentifier is a [wiki:template] and a [wiki:singleton], derived from [wiki:Identifier], with two important tasks:
     20 * Doing some class-specific stuff
     21 * Fast and easy link to the Identifier of a class
    2022
    21 The constructor of ClassIdentifier is private. Only [wiki:IdentifierDistributor] is allowed to create and distribute new instances. (In fact only '''one''' instance per [wiki:template]-class. This is '''very''' important.)
     23== Uniqueness ==
     24Specially the second point is of major importance: !ClassIdentifier is a singleton, meaning there's only one instance of !ClassIdentifier<T> for every T. This allows you to get the Identifier of any class by calling !ClassIdentifier<classname>::getIdentifier():
     25{{{
     26Identifier* identifier = ClassIdentifier<SomeClass>::getIdentifier();
     27}}}
     28This is in fact just what the Class(classname) macro in [wiki:CoreIncludes] does.
    2229
    23 You can't access the ClassIdentifier of a class directly. Use [wiki:ClassManager]<!ClassName>::getIdentifier() instead. A shorter version of this command is the macro Class(classname) (include [wiki:CoreIncludes CoreIncludes.h] to use it) that returns the ClassIdentifier of the given class.
    24 
    25 == The !ObjectList ==
    26 
    27 Every class that uses the !RegisterObject(classname) or !RegisterRootObject(interfacename) macro (see [wiki:CoreIncludes]) is represented by an [wiki:Identifier], that stores all objects of this class (and of all inherited classes) in a [wiki:ObjectList]. The object gets removed from the list if it gets deleted. This is handled by the destructor of [wiki:OrxonoxClass] and the [wiki:MetaObjectList].
    28 
    29 You can iterate through all objects in a [wiki:ObjectList] by using an [wiki:Iterator]. Read the related Wiki-page to get more information.
    30 
    31 == Example ==
    32 
    33 {{{
    34 #!cpp
    35 MyClass.h:
    36 
    37 class MyClass : public BaseObject
    38 {
    39   MyClass();
    40 };
    41 
    42 }}}
    43 
    44 {{{
    45 #!cpp
    46 MyClass.cc:
    47 
    48 #include "CoreIncludes.h"
    49 #include "MyClass.h"
    50 
    51 MyClass::MyClass()
    52 {
    53   RegisterObject(MyClass);
    54 }
    55 }}}
    56 
    57 {{{
    58 #!cpp
    59 SomeOtherFile.cc:
    60 
    61 #include "CoreIncludes.h"
    62 #include "MyClass.h"
    63 
    64 Identifier* myidentifier = Class(MyClass);
    65 std::cout << myidentifier->getName() << std::endl;
    66 
    67 /*
    68 returns:
    69 MyClass
    70 */
    71 }}}
     30To assure uniqueness even in different libraries, a !ClassIdentifier has to register in a map. If the Identifier for a specific class already exists, the second !ClassIdentifier will just refer to the first one.