| 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 | | }}} |
| | 30 | To 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. |