Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6280 in orxonox.OLD


Ignore:
Timestamp:
Dec 25, 2005, 2:46:33 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: ClassList now supports getLeafID() to retriefe the ID on hot to generate an object of the same type

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/class_id.h

    r6279 r6280  
    3535//! list of all classes to be loadable in via the ObjectManager
    3636/**
    37  * inheritance is done in the following way: Classes are identified by
    38  * a HEX-number eg: 0xa0b18a05
    39  * The number has 8^4 entries.
    4037 *
    4138 * -------------------------------------------------------------------------------------------
  • trunk/src/lib/lang/base_object.cc

    r6278 r6280  
    2727
    2828/**
    29  * sets the name from a LoadXML-Element
     29 * @brief sets the name from a LoadXML-Element
    3030 * @param root the element to load from
    3131 */
     
    3636
    3737  this->objectName = NULL;
     38  this->classList = NULL;
    3839
    3940  if (root)
     
    4445
    4546/**
    46  * standard deconstructor
     47 * @brief standard deconstructor
    4748*/
    4849BaseObject::~BaseObject ()
     
    5657
    5758/**
    58  * loads parameters
     59 * @brief loads parameters
    5960 * @param root the element to load from
    6061 */
     
    6768
    6869/**
    69  * sets the class identifiers
     70 * @brief sets the class identifiers
    7071 * @param id a number for the class from class_id.h enumeration
    7172 * @param className the class name
     
    7980  this->className = className;
    8081
    81   ClassList::addToClassList(this, classID, this->classID, className);
     82  this->classList = ClassList::addToClassList(this, classID, this->classID, className);
    8283}
    8384
     85
    8486/**
    85  * @briefbrief set the name of the Object
     87 * @brief set the name of the Object
    8688 */
    8789void BaseObject::setName (const char* objectName)
     
    98100}
    99101
     102/**
     103 * @brief queries for the ClassID of the Leaf Class (the last made class of this type
     104 * @returns the ClassID of the Leaf Class (e.g. the ID of the Class)
     105 *
     106 * the returned ID can be used to generate new Objects of the same type through
     107 * Factory::fabricate(Object->getLeafClassID());
     108 */
     109ClassID BaseObject::getLeafClassID() const
     110{
     111  assert (this->classList != NULL);
     112  return this->classList->getLeafClassID();
     113}
     114
     115
    100116
    101117/**
    102  * checks if the class is a classID
     118 * @brief checks if the class is a classID
    103119 * @param classID the Identifier to check for
    104120 * @returns true if it is, false otherwise
     
    128144}
    129145
     146
     147
    130148/**
    131  * checks if the class is a classID
     149 * @brief checks if the class is a classID
    132150 * @param classID the Identifier to check for
    133151 * @returns true if it is, false otherwise
     
    140158}
    141159
     160
    142161/**
    143  * compares the ObjectName with an external name
     162 * @brief compares the ObjectName with an external name
    144163 * @param objectName: the name to check.
    145164 * @returns true on match, false otherwise.
     
    153172
    154173/**
    155  * displays everything this class is
     174 * @brief displays everything this class is
    156175 * @TODO REIMPLEMENT WITH SENSE.
    157176 */
    158177void BaseObject::whatIs() const
    159178{
    160   PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName());
    161   if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON)
    162     PRINT(0)("is a Singleton-Class ");
    163   if (this->classID & CL_MASK_SUPER_CLASS)
    164   {
    165     PRINT(0)(" ->is a derived from the following superclasses:");
    166     if (this->isA(CL_BASE_OBJECT))
    167       PRINT(0)(" =BaseObject=");
    168     if (this->isA(CL_PARENT_NODE))
    169       PRINT(0)(" =PNode=");
    170     if (this->isA(CL_WORLD_ENTITY))
    171       PRINT(0)(" =WorldEntity=");
    172     if (this->isA(CL_PHYSICS_INTERFACE))
    173       PRINT(0)(" =PhysicsInterface=");
    174     if (this->isA(CL_EVENT_LISTENER))
    175       PRINT(0)(" =EventListener=");
    176     if (this->isA(CL_STORY_ENTITY))
    177       PRINT(0)(" =StoryEntity=");
    178     if (this->isA(CL_ELEMENT_2D))
    179       PRINT(0)(" =Element2D=");
    180     PRINT(0)("\n");
    181   }
    182   // subsuper-classes
    183   if (this->classID & CL_MASK_SUBSUPER_CLASS)
    184   {
    185     PRINT(0)(" ->further derivations: ");
    186     if (this->isA(CL_PLAYER))
    187       PRINT(0)(" -Player-");
    188     if (this->isA(CL_NPC))
    189       PRINT(0)(" -NPC-");
    190     if (this->isA(CL_POWER_UP))
    191       PRINT(0)(" -PowerUp-");
    192     if (this->isA(CL_FIELD))
    193       PRINT(0)(" -Field-");
    194     if (this->isA(CL_PROJECTILE))
    195       PRINT(0)(" -Projectile-");
    196     if (this->isA(CL_WEAPON))
    197       PRINT(0)(" -Weapon-");
    198     PRINT(0)("\n");
     179
    199180}
    200 }
  • trunk/src/lib/lang/base_object.h

    r6077 r6280  
    1717
    1818class TiXmlElement;
     19class ClassList;
    1920
    2021//! A class all other classes are derived from
     
    3435  /** @returns the classID of the corresponding Object */
    3536  inline int getClassID() const { return this->classID; };
     37  ClassID    getLeafClassID() const;
    3638
    3739  bool isA (ClassID classID) const;
     
    5052    long               classID;          //!< this is the id from the class_id.h enumeration
    5153    char*              objectName;       //!< The name of this object
     54
     55    ClassList*         classList;        //!< Pointer to the ClassList this Object is inside of
    5256};
    5357
  • trunk/src/lib/lang/class_list.cc

    r6278 r6280  
    5959
    6060/**
    61  * Adds a new Object to the ClassList (and if necessary a new Class)
     61 * @brief Adds a new Object to the ClassList (and if necessary a new Class)
    6262 * @param objectPointer Pointer to the Object at hand
    6363 * @param classID ID of the Given ObjectType \see ClassID
     
    6767 * !! Before unsing the ClassList, as it creates the ClassLits
    6868 */
    69 void ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char* className)
     69ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char* className)
    7070{
    7171  if (unlikely(classList == NULL))
     
    7676  ClassList* regClass = ClassList::getClassList(classID);
    7777  if (regClass != NULL)
     78  {
    7879    regClass->objectList.push_back(objectPointer);
     80    return regClass;
     81  }
    7982  else
    8083  {
    8184    ClassList::classList->push_back(ClassList(classID, classIDFull, className));
    8285    ClassList::classList->back().objectList.push_back(objectPointer);
     86    return &ClassList::classList->back();
    8387  }
    8488}
  • trunk/src/lib/lang/class_list.h

    r6278 r6280  
    3636
    3737    /* MAINTENANCE FUNCTIONS THESE ARE !!ONLY FOR BASEOBJECT !! */
    38     static void                           addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char* className);
     38    static ClassList*                     addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char* className);
    3939    static void                           removeFromClassList(BaseObject* objectPointer);
    4040
     
    5858    inline bool                           operator==(ClassID classID) { return (this->classID == classID); };
    5959    bool                                  operator==(const char* className);
     60    inline ClassID                        getLeafClassID() const { return this->classID; };
    6061
    6162  private:
Note: See TracChangeset for help on using the changeset viewer.