Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9678 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Aug 21, 2006, 11:59:18 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: implemented isA leafID and listInheritance

Location:
trunk/src/lib/lang
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/lang/new_class_id.cc

    r9674 r9678  
    1818#include "new_class_id.h"
    1919#include <cassert>
     20#include "debug.h"
    2021
    2122///////////////////////////////////////////////////////////
     
    4546
    4647
     48/**
     49 * @brief Seeks in the Inheritance if it matches objectList.
     50 * @param objectList The ObjectList this should be a member of (by Pointer-comparison).
     51 * @return True if found, false if not.
     52 */
     53bool NewClassID::isA(const NewObjectListBase& objectList) const
     54{
     55  ClassList::const_iterator it;
     56  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     57    if ((*it)._objectList == &objectList)
     58      return true;
     59  return false;
     60}
     61
     62/**
     63 * @brief Seeks in the Inheritance if it matches objectList.
     64 * @param classID The ClassID of the class this should be a member of.
     65 * @return True if found, false if not.
     66 */
     67bool NewClassID::isA(int classID) const
     68{
     69  ClassList::const_iterator it;
     70  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     71    if (*(*it)._objectList == classID)
     72      return true;
     73  return false;
     74}
     75
     76/**
     77 * @brief Seeks in the Inheritance if it matches objectList.
     78 * @param className The ClassName of the class this should be a member of.
     79 * @return True if found, false if not.
     80 */
     81bool NewClassID::isA(const std::string& className) const
     82{
     83  ClassList::const_iterator it;
     84  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     85    if (*(*it)._objectList == className)
     86      return true;
     87  return false;
     88}
     89
     90
     91void NewClassID::listInheritance() const
     92{
     93  PRINT(0)("Listing inheritance diagram for ....: ");
     94  ClassList::const_iterator it;
     95  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     96    PRINT(0)(" -> %s", (*it)._objectList->name().c_str());
     97  PRINT(0)("\n");
     98
     99}
  • trunk/src/lib/lang/new_class_id.h

    r9673 r9678  
    2424
    2525
     26  int leafClassID() const { return _classes.front()._objectList->id(); }
     27
    2628  template<class T> void registerObject(T* object, NewObjectList<T>& list);
    2729  bool isA(const NewObjectListBase& objectList) const;
    28   bool isA(int id) const;
     30  bool isA(int classID) const;
    2931  bool isA(const std::string& className) const;
    3032
     33  void listInheritance() const;
     34
    3135private:
    32 
    3336  //////////////////////////////
    3437  //// Type Definition Part ////
    3538  //////////////////////////////
    3639  //! A ClassEntry so we can store Classes inside of Objects
    37   struct ClassEntry{
     40  struct ClassEntry
     41  {
    3842    /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */
    3943    inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {}
     
    4246  };
    4347  typedef std::list<ClassEntry>        ClassList;   //!< Type definition for the List.
     48
    4449  ClassList                           _classes;     //!< All Classes this object is part of.
    4550};
     
    5661 */
    5762template<class T>
    58     inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList)
     63inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList)
    5964{
    60   this->_classes.push_back(ClassEntry(&objectList, objectList.registerObject(object)));
     65  this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object)));
    6166}
    6267
  • trunk/src/lib/lang/test_object_list.cc

    r9677 r9678  
    1212  //   bool operator==(const std::string& name) const { return _objectName == name; };
    1313
    14   //  NewObjectListDeclaration(NewBaseObject);
     14    NewObjectListDeclaration(NewBaseObject);
    1515
    1616protected:
    1717  NewBaseObject(const std::string& objectName = "") : _objectName(objectName)
    1818  {
    19     //    this->registerObject(this, objectList);
     19       this->registerObject(this, objectList);
    2020  };
    2121  template<class T>
    2222  inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); };
    23 private:
     23protected:
    2424  NewClassID    _id;
    2525  std::string   _objectName;
     
    2727
    2828};
    29 //NewObjectListDefinition(NewBaseObject);
     29NewObjectListDefinition(NewBaseObject);
    3030
    3131
     
    4343  //ObjectListDeclaration(Test);
    4444};
    45 NewObjectListDefinitionID(Test, 0);
     45NewObjectListDefinitionID(Test, -1);
    4646
    4747Test::Test()
    4848{
    4949  this->registerObject(this, Test::objectList);
     50
     51  this->_id.listInheritance();
     52
    5053//  this->setClassID(CL_PARENT_NODE, "Test");
    5154  // std::cout << "Test()\n";
Note: See TracChangeset for help on using the changeset viewer.