| 10 | | Usage: !SubclassIdentifier<!BaseClass> name = Class(!SubClass); where !SubClass isA !BaseClass. |
| | 10 | == Usage == |
| | 11 | === Assignment === |
| | 12 | You can assign an Identifier either through the constructor or by using the assignment operator=: |
| | 13 | {{{ |
| | 14 | // SubClass isA BaseClass: |
| | 15 | SubclassIdentifier<BaseClass> identifier = Class(SubClass); |
| | 16 | }}} |
| | 17 | |
| | 18 | === Function calls === |
| | 19 | the operator-> is overloaded an returns the assigned Identifier. That way you can just call functions of the assigned Identifier by using ->function(): |
| | 20 | {{{ |
| | 21 | SubclassIdentifier<BaseClass> identifier = Class(SubClass); |
| | 22 | identifier->getName(); // returns "SubClass" |
| | 23 | }}} |
| | 24 | |
| | 25 | === fabricate() === |
| | 26 | There are two possibilities to create an object out of a !SubclassIdentifier. Either you just use the fabricate() function of the assigned Identifier through the overloaded operator->. Remember: This function returns a BaseObject* pointer: |
| | 27 | {{{ |
| | 28 | // creates a SubClass, returns a BaseObject* pointer |
| | 29 | identifier->fabricate(); |
| | 30 | }}} |
| | 31 | |
| | 32 | Or you use the function of !SubclassIdentifier, this time by using operator., which returns a BaseClass* pointer (BaseClass is the baseclass specified by the template argument): |
| | 33 | {{{ |
| | 34 | // creates a SubClass, returns a BaseClass* pointer |
| | 35 | identifier.fabricate(); |
| | 36 | }}} |
| 18 | | SubclassIdentifier<A1> myidentifier = Class(A1); // This works |
| 19 | | SubclassIdentifier<A1> myidentifier = Class(A1B1); // This works |
| 20 | | SubclassIdentifier<A1> myidentifier = Class(A1B1C1); // This works |
| 21 | | SubclassIdentifier<A1> myidentifier = Class(BaseObject); // This doesn't work |
| 22 | | SubclassIdentifier<A1> myidentifier = Class(A3); // This doesn't work |
| | 44 | SubclassIdentifier<A1> myidentifier = Class(A1); // This works |
| | 45 | SubclassIdentifier<A1> myidentifier = Class(A1B1); // This works |
| | 46 | SubclassIdentifier<A1> myidentifier = Class(A1B1C1); // This works |
| | 47 | SubclassIdentifier<A1> myidentifier = Class(BaseObject); // This doesn't work |
| | 48 | SubclassIdentifier<A1> myidentifier = Class(A3); // This doesn't work |
| 29 | | SubclassIdentifier<A1> myidentifier = Class(A1B1); |
| 30 | | myidentifier.isExactlyA(Class(A1)); // Returns false |
| 31 | | myidentifier.isExactlyA(Class(A1B1)); // Returns true |
| 32 | | (*myidentifier)->getName(); // Returns "A1B1" |
| 33 | | myidentifier->getName(); // Returns "A1B1" (Yes, the "->" is correct. It's overloaded.) |
| | 58 | myidentifier->isExactlyA(Class(A1)); // Returns false |
| | 59 | myidentifier->isExactlyA(Class(A1B1)); // Returns true |
| | 60 | (*myidentifier)->getName(); // Returns "A1B1" |
| | 61 | myidentifier->getName(); // Returns "A1B1" |