Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 8 and Version 9 of code/doc/SubclassIdentifier


Ignore:
Timestamp:
Sep 29, 2008, 2:44:16 AM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/SubclassIdentifier

    v8 v9  
    44== Description ==
    55
    6 The [wiki:SubclassIdentifier] acts like an [wiki:Identifier]. You can assign a [wiki:ClassIdentifier] and compare it with other [wiki:Identifier Identifiers] by using isA(...), isChildOf(...) and other functions.
     6!SubclassIdentifier acts like a pointer to an [wiki:Identifier] with the difference that you can only assign Identifiers of classes inheriting from a given baseclass.
    77
    8 [wiki:SubclassIdentifier] is a [wiki:template]. The [wiki:template]-class defines the needed base-class of an assigned Identifier. You can only assign [wiki:Identifier 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.
     8!SubclassIdentifier is a [wiki:template]. The template-argument 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.
    99
    10 Usage: !SubclassIdentifier<!BaseClass> name = Class(!SubClass); where !SubClass isA !BaseClass.
     10== Usage ==
     11=== Assignment ===
     12You can assign an Identifier either through the constructor or by using the assignment operator=:
     13{{{
     14// SubClass isA BaseClass:
     15SubclassIdentifier<BaseClass> identifier = Class(SubClass);
     16}}}
     17
     18=== Function calls ===
     19the operator-> is overloaded an returns the assigned Identifier. That way you can just call functions of the assigned Identifier by using ->function():
     20{{{
     21SubclassIdentifier<BaseClass> identifier = Class(SubClass);
     22identifier->getName(); // returns "SubClass"
     23}}}
     24
     25=== fabricate() ===
     26There 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
     29identifier->fabricate();
     30}}}
     31
     32Or 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
     35identifier.fabricate();
     36}}}
    1137
    1238== Examples ==
     
    1642{{{
    1743#!cpp
    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
     44SubclassIdentifier<A1> myidentifier = Class(A1);         // This works
     45SubclassIdentifier<A1> myidentifier = Class(A1B1);       // This works
     46SubclassIdentifier<A1> myidentifier = Class(A1B1C1);     // This works
     47SubclassIdentifier<A1> myidentifier = Class(BaseObject); // This doesn't work
     48SubclassIdentifier<A1> myidentifier = Class(A3);         // This doesn't work
    2349
    2450
    2551SubclassIdentifier<Interface1> myidentifier = Class(A3);     // This works
    2652SubclassIdentifier<Interface1> myidentifier = Class(A2B2C1); // This works
     53}}}
    2754
     55{{{
     56SubclassIdentifier<A1> myidentifier = Class(A1B1);
    2857
    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.)
     58myidentifier->isExactlyA(Class(A1));       // Returns false
     59myidentifier->isExactlyA(Class(A1B1));     // Returns true
     60(*myidentifier)->getName();                // Returns "A1B1"
     61myidentifier->getName();                   // Returns "A1B1"
    3462
    35 A1* newobject = myidentifier.fabricate(); // Returns a new instance of A1B1, downcasted to A1
     63A1* newobject = myidentifier.fabricate();  // Returns a new instance of A1B1, casted to A1
    3664}}}
    3765