Version 5 (modified by landauf, 17 years ago) (diff) |
---|
SubclassIdentifier
Description
The SubclassIdentifier acts like an Identifier. You can assign a ClassIdentifier and compare it with other Identifiers by using isA(…), isChildOf(…) and other functions.
SubclassIdentifier is a template. The template-class defines the needed base-class of an assigned Identifier. You can only assign Identifiers representing a class which is derived from the given base-class (or the base-class itself). If you try to assign an Identifier that's not derived from the base-class, you get an error.
Usage: SubclassIdentifier<BaseClass> name = Class(SubClass); where SubClass isA BaseClass.
Examples
The following examples use the class-tree below.
SubclassIdentifier<A1> myidentifier = Class(A1); // This works SubclassIdentifier<A1> myidentifier = Class(A1B1); // This works SubclassIdentifier<A1> myidentifier = Class(A1B1C1); // This works SubclassIdentifier<A1> myidentifier = Class(BaseObject); // This doesn't work SubclassIdentifier<A1> myidentifier = Class(A3); // This doesn't work SubclassIdentifier<Interface1> myidentifier = Class(A3); // This works SubclassIdentifier<Interface1> myidentifier = Class(A2B2C1); // This works SubclassIdentifier<A1> myidentifier = Class(A1B1); myidentifier.isExactlyA(Class(A1)); // Returns false myidentifier.isExactlyA(Class(A1B1)); // Returns true (*myidentifier)->getName(); // Returns "A1B1" myidentifier->getName(); // Returns "A1B1" (Yes, the "->" is correct. It's overloaded.) A1* newobject = myidentifier.fabricate(); // Returns a new instance of A1B1, downcasted to A1