Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 4 (modified by landauf, 16 years ago) (diff)

Identifier

Description

The Identifier is a construct to identify the class of an object. All classes derived from OrxonoxClass have an Identifier, representing the class in the running game. The Identifier additionally stores all objects of its class in a list, knows the name of the class, can have a ClassFactory, knows all parents and children, stores config-values and shell-functions and provides several other functionalities.

You can get the Identifier of a given class with the macro Class(classname). You have to include CoreIncludes.h to use it.

A new class that wants an Identifier must use a macro (RegisterObject(classname) or RegisterRootObject(interfacename)) from CoreIncludes. Read the related Wiki-page for more informations.

Identifiers can be compared by using functions like isA(…) or isChildOf(…) to retrieve informations about the class-hierarchy.

You can't create an Identifier directly, because it's an abstract class. There only exist ClassIdentifiers, but you can't create them too, because they have private constructors. Identifiers are created by IdentifierDistributor?, a helper class to warrant the uniqueness of an Identifier for a class.

The SubclassIdentifier is a class, that can store and act like an Identifier, but has a given base-class. Read the related Wiki-page for more informations.

Functions

  • Comparison:
    • 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.
    • myidentifier→isExactlyA(other): If myidentifier and other represent both the same class, the function returns true.
    • myidentifier→isChildOf(other): If the class represented by myidentifier is a child of the class represented by other, the function returns true.
    • myidentifier→isDirectChildOf(other): Like isChildOf(…), but the class represented by myidentifier must be inherited directly without other classes between (class myidentifierclass : public otherclass).
    • 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.
    • myidentifier→isDirectParentOf(other): Like isParentOf(…), but the class represented by myidentifier must be a direct parent without other classes between (class otherclass : public myidentifierclass).
  • Fabricate:
    • fabricate() returns a new object of the class represented by the Identifier (see ClassFactory).
  • Name:
    • getName() returns the name of the represented class.
  • Class-hierarchy: You can retrieve lists and iterators (begin and end) of:
    • parents: getParents(), getParentsBegin(), getParentsEnd()
    • directParents: getDirectParents(), getDirectParentsBegin(), getDirectParentsEnd()
    • children: getChildren(), getChildrenBegin(), getChildrenEnd()
    • directChildren: getDirectChildren(), getDirectChildrenBegin(), getDirectChildrenEnd()

Examples

The following examples use the class-tree below.

Identifier* myidentifier = Class(A1);            // Assigns the Identifier of A1

myidentifier->isA(Class(BaseObject));            // returns true
myidentifier->isA(Class(A1));                    // returns true
myidentifier->isA(Class(A1B1));                  // returns false
myidentifier->isA(Class(A2));                    // returns false
Class(A3)->isA(Class(Interface1));               // returns true

Class(A1B1)->isChildOf(Class(BaseObject));       // returns true
Class(A1B1)->isChildOf(Class(A1));               // returns true

Class(A1B1)->isDirectChildOf(Class(BaseObject)); // returns false
Class(A1B1)->isDirectChildOf(Class(A1));         // returns true
// Creates a new instance of A1
BaseObject* newobject = Class(A1)->fabricate();

// Creates a new instance of A1 and casts it to Interface1
Identifier* myidentifier = Class(A3);
Interface1* newobject = (Interface1)(myidentifier->fabricate());
Identifier* myidentifier = Class(BaseObject);
for (std::list<const Identifier*>::const_iterator it = myidentifier->getDirectChildrenBegin(); it != myidentifier->getDirectChildrenEnd(); ++it)
  cout << (*it)->getName() << std::endl;

/*
returns all direct children of BaseObject:
A1
A2
A3
*/

No image "testclass_interface_tree.gif" attached to Core

Networking

Technical informations