Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 2 and Version 3 of code/doc/Identifier


Ignore:
Timestamp:
Feb 24, 2008, 10:52:42 PM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/Identifier

    v2 v3  
    44
    55The [wiki:Identifier] is a construct to identify the class of an object. All classes derived from OrxonoxClass have an Identifier, representing the class in the running game. The Identifier additionally stores all objects of its class in a [wiki:ObjectList list], knows the name of the class, can have a [wiki:ClassFactory], knows all parents and children, stores [wiki:ConfigValueContainer config-values] and shell-functions and provides several other functionalities.
     6
     7You can get the Identifier of a given class with the macro Class(classname). You have to include [wiki:CoreIncludes CoreIncludes.h] to use it.
    68
    79A new class that wants an Identifier must use a macro (!RegisterObject(classname) or !RegisterRootObject(interfacename)) from [wiki:CoreIncludes]. Read the related Wiki-page for more informations.
     
    1416
    1517== Functions ==
     18
     19 * '''Macro''': (Include [wiki:CoreIncludes CoreIncludes.h] to use this)
     20   * Identifier* myidentifier = Class(BaseObject);
    1621
    1722 * '''Comparison''':
     
    3742== Examples ==
    3843
     44The following examples use the class-tree below.
     45
     46{{{
     47#!cpp
     48Identifier* myidentifier = Class(A1);            // Assigns the Identifier of A1
     49
     50myidentifier->isA(Class(BaseObject));            // returns true
     51myidentifier->isA(Class(A1));                    // returns true
     52myidentifier->isA(Class(A1B1));                  // returns false
     53myidentifier->isA(Class(A2));                    // returns false
     54Class(A3)->isA(Class(Interface1));               // returns true
     55
     56Class(A1B1)->isChildOf(Class(BaseObject));       // returns true
     57Class(A1B1)->isChildOf(Class(A1));               // returns true
     58
     59Class(A1B1)->isDirectChildOf(Class(BaseObject)); // returns false
     60Class(A1B1)->isDirectChildOf(Class(A1));         // returns true
     61}}}
     62
     63{{{
     64#!cpp
     65// Creates a new instance of A1
     66BaseObject* newobject = Class(A1)->fabricate();
     67
     68// Creates a new instance of A1 and casts it to Interface1
     69Identifier* myidentifier = Class(A3);
     70Interface1* newobject = (Interface1)(myidentifier->fabricate());
     71}}}
     72
     73{{{
     74#!cpp
     75Identifier* myidentifier = Class(BaseObject);
     76for (std::list<const Identifier*>::const_iterator it = myidentifier->getDirectParentsBegin(); it != myidentifier->getDirectParentsEnd(); ++it)
     77  cout << (*it)->getName() << std::endl;
     78
     79/*
     80returns:
     81A1
     82A2
     83A3
     84*/
     85}}}
     86
     87[[Image(Core:testclass_interface_tree.gif)]]
     88
    3989== Networking ==
    4090