Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 22, 2006, 1:34:31 AM (18 years ago)
Author:
bensch
Message:

orxonox/branches/new_class_id: slowly but surely reimplementing to the new groove… way to go

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/lang/base_object.cc

    r9406 r9684  
    2020
    2121#include "util/loading/load_param.h"
    22 #include "class_list.h"
    2322
    2423/**
     
    2827BaseObject::BaseObject(const std::string& objectName)
    2928{
    30   this->classID = CL_BASE_OBJECT;
    3129  this->className = "BaseObject";
    3230
    3331  this->objectName = objectName;
    34   this->classList = NULL;
    3532  this->xmlElem = NULL;
    3633
     
    4340BaseObject::~BaseObject ()
    4441{
    45   ClassList::removeFromClassList(this);
     42  /// Remove from the NewObjectLists
     43  ClassList::iterator it;
     44  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     45  {
     46    (*it)._objectList->unregisterObject((*it)._iterator);
     47    delete (*it)._iterator;
     48  }
    4649
    4750  if (this->xmlElem != NULL)
     
    6972
    7073/**
    71  * @brief sets the class identifiers
    72  * @param id a number for the class from class_id.h enumeration
    73  * @param className the class name
    74 */
    75 void BaseObject::setClassID(ClassID classID, const std::string& className)
    76 {
    77   //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID);
    78   assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA ));
    79 
    80   this->leafClassID = classID;
    81   this->classID |= (long)classID;
    82   this->className = className;
    83 
    84   this->classList = ClassList::addToClassList(this, classID, this->classID, className);
    85 }
    86 
    87 
    88 /**
    8974 * @brief set the name of the Object
    9075 * @param objectName The new name of the Object.
     
    9782
    9883/**
    99  * @brief queries for the ClassID of the Leaf Class (the last made class of this type
    100  * @returns the ClassID of the Leaf Class (e.g. the ID of the Class)
    101  *
    102  * the returned ID can be used to generate new Objects of the same type through
    103  * Factory::fabricate(Object->getLeafClassID());
     84 * @brief Seeks in the Inheritance if it matches objectList.
     85 * @param objectList The ObjectList this should be a member of (by Pointer-comparison).
     86 * @return True if found, false if not.
    10487 */
    105 const ClassID& BaseObject::getLeafClassID() const
     88bool BaseObject::isA(const NewObjectListBase& objectList) const
    10689{
    107   return this->leafClassID;
     90  ClassList::const_iterator it;
     91  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     92    if ((*it)._objectList == &objectList)
     93      return true;
     94  return false;
    10895}
    10996
    110 
     97/**
     98 * @brief Seeks in the Inheritance if it matches objectList.
     99 * @param classID The ClassID of the class this should be a member of.
     100 * @return True if found, false if not.
     101 */
     102bool BaseObject::isA(int classID) const
     103{
     104  ClassList::const_iterator it;
     105  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     106    if (*(*it)._objectList == classID)
     107      return true;
     108  return false;
     109}
    111110
    112111/**
    113  * @brief checks if the class is a classID
    114  * @param classID the Identifier to check for
    115  * @returns true if it is, false otherwise
    116 */
    117 bool BaseObject::isA (ClassID classID) const
     112 * @brief Seeks in the Inheritance if it matches objectList.
     113 * @param className The ClassName of the class this should be a member of.
     114 * @return True if found, false if not.
     115 */
     116bool BaseObject::isA(const std::string& className) const
    118117{
    119   // if classID is a derivable object from a SUPERCLASS
    120   if (classID & CL_MASK_SUPER_CLASS)
    121   {
    122     if( likely(this->classID & classID))
     118  ClassList::const_iterator it;
     119  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     120    if (*(*it)._objectList == className)
    123121      return true;
    124   }
    125   // if classID is a SubSuperClass, and
    126   else if (classID & CL_MASK_SUBSUPER_CLASS)
    127   {
    128     if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&
    129         this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))
    130       return true;
    131   }
    132   // if classID is a LOWLEVEL-class
    133   else
    134   {
    135     if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
    136       return true;
    137   }
    138122  return false;
    139123}
    140124
    141125
     126void BaseObject::listInheritance() const
     127{
     128  PRINT(0)("Listing inheritance diagram for ....: ");
     129  ClassList::const_iterator it;
     130  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     131    PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id());
     132  PRINT(0)("\n");
    142133
    143 /**
    144  * @brief checks if the class is a classID
    145  * @param classID the Identifier to check for
    146  * @returns true if it is, false otherwise
    147  */
    148 bool BaseObject::isA (const std::string& className) const
    149 {
    150   ClassID classID = ClassList::StringToID(className);
    151   if (classID != CL_NULL)
    152     return this->isA(classID);
    153   else
    154     return false;
    155134}
    156 
    157 
    158 /**
    159  * @brief compares the ObjectName with an external name
    160  * @param objectName: the name to check.
    161  * @returns true on match, false otherwise.
    162  */
    163 bool BaseObject::operator==(const std::string& objectName) const
    164 {
    165   return (this->objectName == objectName);
    166 }
    167 
Note: See TracChangeset for help on using the changeset viewer.