24 | | * '''Comparison''': |
25 | | * ''myidentifier'''''->isA('''''other''''')''': Compares the Identifier (''myidentifier'') with another Identifier (''other''). If ''myidentifier'' represents exactly the same or an inheriting class, the function returns true. |
26 | | * ''myidentifier'''''->isExactlyA('''''other''''')''': If ''myidentifier'' and ''other'' represent both the same class, the function returns true. |
27 | | * ''myidentifier'''''->isChildOf('''''other''''')''': If the class represented by ''myidentifier'' is a child of the class represented by ''other'', the function returns true. |
28 | | * ''myidentifier'''''->isDirectChildOf('''''other''''')''': Like isChildOf(...), but the class represented by ''myidentifier'' must be inherited directly without other classes between (class ''myidentifierclass'' : public ''otherclass''). |
29 | | * ''myidentifier'''''->isParentOf('''''other''''')''': If the class represented by ''myidentifier'' is a parent of the class represented by ''other'', meaning the other class is a child, the function returns true. |
30 | | * ''myidentifier'''''->isDirectParentOf('''''other''''')''': Like isParentOf(...), but the class represented by ''myidentifier'' must be a direct parent without other classes between (class ''otherclass'' : public ''myidentifierclass''). |
| 40 | === New classes === |
| 41 | A new class that wants an Identifier must call RegisterObject(classname) in the constructor. A new interface has to inherit virtually from [wiki:OrxonoxClass] and call RegisterRootObject(interfacename) from in the constructor. Both macros are located in [wiki:CoreIncludes]. Read the related Wiki-page for more information. |
38 | | * '''Class-hierarchy''': You can retrieve lists and iterators (begin and end) of: |
39 | | * '''parents''': getParents(), getParentsBegin(), getParentsEnd() |
40 | | * '''directParents''': getDirectParents(), getDirectParentsBegin(), getDirectParentsEnd() |
41 | | * '''children''': getChildren(), getChildrenBegin(), getChildrenEnd() |
42 | | * '''directChildren''': getDirectChildren(), getDirectChildrenBegin(), getDirectChildrenEnd() |
| 53 | === Creating an object with fabricate() === |
| 54 | You can create an object of a class represented by an Identifier by calling fabricate(). This function creates a new instance and returns a [wiki:BaseObject] pointer. |
| 55 | |
| 56 | '''Important''': If you have to cast the BaseObject-pointer to the real class, use '''dynamic_cast'''. |
| 57 | {{{ |
| 58 | Identifier* identifier = Class(MyClass); |
| 59 | |
| 60 | // Create an instance of MyClass: |
| 61 | BaseObject* object = identifier->fabricate(); |
| 62 | |
| 63 | // Cast the pointer from BaseObject to MyClass: |
| 64 | MyClass* object2 = dynamic_cast<MyClass*>(object); |
| 65 | }}} |
| 66 | |
| 67 | === Comparison === |
| 68 | Different Identifiers can be compared by using functions like isA(...) or isChildOf(...) to retrieve information about the class-hierarchy: |
| 69 | |
| 70 | * ''myidentifier'''''->isA('''''other''''')''': Compares the Identifier (''myidentifier'') with another Identifier (''other''). If ''myidentifier'' represents exactly the same or an inheriting class, the function returns true. |
| 71 | * ''myidentifier'''''->isExactlyA('''''other''''')''': If ''myidentifier'' and ''other'' represent both the same class, the function returns true. |
| 72 | * ''myidentifier'''''->isChildOf('''''other''''')''': If the class represented by ''myidentifier'' is a child of the class represented by ''other'', the function returns true. |
| 73 | * ''myidentifier'''''->isDirectChildOf('''''other''''')''': Like isChildOf(...), but the class represented by ''myidentifier'' must be inherited directly without other classes between (class ''myidentifierclass'' : public ''otherclass''). |
| 74 | * ''myidentifier'''''->isParentOf('''''other''''')''': If the class represented by ''myidentifier'' is a parent of the class represented by ''other'', meaning the other class is a child, the function returns true. |
| 75 | * ''myidentifier'''''->isDirectParentOf('''''other''''')''': Like isParentOf(...), but the class represented by ''myidentifier'' must be a direct parent without other classes between (class ''otherclass'' : public ''myidentifierclass''). |
| 76 | |
| 77 | A more graphical explanation: |
| 78 | {{{ |
| 79 | #!html |
| 80 | <span style="color:#008000;">Green:</span> If you call <b>comparisonFunction(Class(MyClass))</b> on a <span style="color:#008000;">green</span> class, the function returns true.<br /> |
| 81 | <span style="color:#A00000;">Red:</span> If you call <b>comparisonFunction(Class(MyClass))</b> on a <span style="color:#A00000;">red</span> class, the function returns false.<br /> |
| 82 | <br /> |
| 83 | comparisionFunction is either isA, isExactlyA, isChildOf, isDirectChildOf, isParentOf or isDirectParentOf.<br /> |
| 84 | <br /> |
| 85 | <table><tr><td> |
| 86 | <b>isA</b>(MyClass):</td><td> |
| 87 | <span style="color:#A00000;">ParentOfParent</span> | <span style="color:#A00000;">Parent</span> | <b>[</b><span style="color:#008000;">MyClass</span> | <span style="color:#008000;">Child</span> | <span style="color:#008000;">ChildOfChild</span><b>]</b><br /> |
| 88 | </td></tr><tr><td> |
| 89 | <b>isExactlyA</b>(MyClass):</td><td> |
| 90 | <span style="color:#A00000;">ParentOfParent</span> | <span style="color:#A00000;">Parent</span> | <b>[</b><span style="color:#008000;">MyClass</span><b>]</b> | <span style="color:#A00000;">Child</span> | <span style="color:#A00000;">ChildOfChild</span><br /> |
| 91 | </td></tr><tr><td> |
| 92 | <b>isChildOf</b>(MyClass):</td><td> |
| 93 | <span style="color:#A00000;">ParentOfParent</span> | <span style="color:#A00000;">Parent</span> | <span style="color:#A00000;">MyClass</span> | <b>[</b><span style="color:#008000;">Child</span> | <span style="color:#008000;">ChildOfChild</span><b>]</b><br /> |
| 94 | </td></tr><tr><td> |
| 95 | <b>isDirectChildOf</b>(MyClass):</td><td> |
| 96 | <span style="color:#A00000;">ParentOfParent</span> | <span style="color:#A00000;">Parent</span> | <span style="color:#A00000;">MyClass</span> | <b>[</b><span style="color:#008000;">Child</span><b>]</b> | <span style="color:#A00000;">ChildOfChild</span><br /> |
| 97 | </td></tr><tr><td> |
| 98 | <b>isParentOf</b>(MyClass):</td><td> |
| 99 | <b>[</b><span style="color:#008000;">ParentOfParent</span> | <span style="color:#008000;">Parent</span><b>]</b> | <span style="color:#A00000;">MyClass</span> | <span style="color:#A00000;">Child</span> | <span style="color:#A00000;">ChildOfChild</span><br /> |
| 100 | </td></tr><tr><td> |
| 101 | <b>isDirectParentOf</b>(MyClass):</td><td> |
| 102 | <span style="color:#A00000;">ParentOfParent</span> | <b>[</b><span style="color:#008000;">Parent</span><b>]</b> | <span style="color:#A00000;">MyClass</span> | <span style="color:#A00000;">Child</span> | <span style="color:#A00000;">ChildOfChild</span><br /> |
| 103 | </td></tr></table> |
| 104 | }}} |
| 105 | |
| 106 | === More Functions === |
| 107 | '''Hierarchy''': Every Identifier provides sets of all parents and children: |
| 108 | * getParents() |
| 109 | * getChildren() |
| 110 | * getDirectParents() |
| 111 | * getDirectChildren() |
| 112 | |
| 113 | '''Identifiers''': There is also a static map containg all existing Identifiers: |
| 114 | * Identifier::getIdentifierMap() |
| 115 | * Identifier::getLowercaseIdentifierMap() |
| 116 | |
| 117 | '''ConfigValues''': Every Identifier stores the [wiki:ConfigValueContainer config-values] of the class: |
| 118 | * getConfigValueMap() |
| 119 | * getLowercaseConfigValueMap() |
| 120 | * hasConfigValues() |
| 121 | |
| 122 | '''ConsoleCommands''': Also, Identifiers store the [wiki:ConsoleCommand console-commands] of the class: |
| 123 | * getConsoleCommandMap() |
| 124 | * getLowercaseConsoleCommandMap() |
| 125 | * hasConsoleCommands() |
| 126 | |
| 127 | '''XMLPort Params''': The same for [wiki:XMLPort XMLPort params]: |
| 128 | * getXMLPortParamMap |
| 129 | |
| 130 | '''XMLPort Objects''': And [wiki:XMLPort XMLPort objects]: |
| 131 | * getXMLPortObjectMap |
| 132 | |
| 133 | == Class Identifier == |
| 134 | Every Identifier is in fact a [wiki:ClassIdentifier]. Identifier itself is the abstract baseclass of !ClassIdentifier. ClassIdentifier is a template. This is needed to take care of the class-specific parts of the Identifier. Read the related Wiki-page for more information. |
| 135 | |
| 136 | == Subclass Identifier == |
| 137 | The [wiki:SubclassIdentifier] is a class, that can act like an Identifier, but has a given base-class. Read the related Wiki-page for more information. |