Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

BaseObject

This is an archived page!
This page is very old and the content is not up to date.
Not everything (if any) which is written here will be in the final game!

The BaseObject is the top-most SuperClass of (most but not) all Classes in orxonox.

source:orxonox.OLD/trunk/src/lib/lang/base_object.h#HEAD
Derived From:

  • nothing

Description

BaseObject is a container for

  • The Name of the Object (how the object is called)
  • The Class' Name of the Object (in what class this object is)
  • The ClassID of the Object (what is the Identity of the class (see ClassID)

Usage

  • Registration:
    Each class, that extends BaseObject must implement the following function:
    1. In the Class-Declaration use the following syntax (taken your class is named OrxClass)
        class OrxClass : public !BaseObject // here you could also specify any class derived from !BaseObject
        {
          ObjectListDeclaration(OrxClass);
          /// ... rest of the Declaration;
        };
      
    2. At the top of the cc-file of the Class (in the definiton) write:
        ObjectListDefinition(OrxClass);
      
    3. In the constructor of each class implementing BaseObject write the following:
      this->registerObject(this, OrxClass::_objectList);
      
    4. you can then set a Name to the Object using
      this->setName("the name");
      
  • isA:
    isA is a function, that queries, if the Object is of a Specified type. e.g. given a class Player that is derived from BaseObject and PNode one can do the following check :
     Player* player = new Player();
     if (player->isA(PNode::staticClassID()) {
       /* do something terrible with it */ }
    

Advanced Topics

An interessting Function, that BaseObject provides is the ObjectList. With it, one can retrieve lists of any one kind of derived classes from BaseObject.

Last modified 7 years ago Last modified on Apr 15, 2017, 3:30:00 PM