Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9685 in orxonox.OLD for branches/new_class_id/src/lib/lang


Ignore:
Timestamp:
Aug 22, 2006, 1:16:23 PM (18 years ago)
Author:
bensch
Message:

adapted many classes to the new ClassID System, now comes the hard part… Scripting… then Network… wow this will be so bad :/

Location:
branches/new_class_id/src/lib/lang
Files:
4 edited

Legend:

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

    r9681 r9685  
    1717
    1818#include "new_class_id.h"
    19 #include <cassert>
    20 #include "debug.h"
    21 
    22 ///////////////////////////////////////////////////////////
    23 //// CLASS ID definiton. //////////////////////////////////
    24 ///////////////////////////////////////////////////////////
    25 /**
    26  * @brief standard constructor
    27  */
    28 NewClassID::NewClassID ()
    29 {}
    30 
    31 
    32 /**
    33  * @brief standard deconstructor
    34  */
    35 NewClassID::~NewClassID ()
    36 {
    37   ClassList::iterator it;
    38   for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
    39   {
    40     (*it)._objectList->unregisterObject((*it)._iterator);
    41     delete (*it)._iterator;
    42   }
    43 }
    44 
    45 
    46 /**
    47  * @brief Seeks in the Inheritance if it matches objectList.
    48  * @param objectList The ObjectList this should be a member of (by Pointer-comparison).
    49  * @return True if found, false if not.
    50  */
    51 bool NewClassID::isA(const NewObjectListBase& objectList) const
    52 {
    53   ClassList::const_iterator it;
    54   for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
    55     if ((*it)._objectList == &objectList)
    56       return true;
    57   return false;
    58 }
    59 
    60 /**
    61  * @brief Seeks in the Inheritance if it matches objectList.
    62  * @param classID The ClassID of the class this should be a member of.
    63  * @return True if found, false if not.
    64  */
    65 bool NewClassID::isA(int classID) const
    66 {
    67   ClassList::const_iterator it;
    68   for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
    69     if (*(*it)._objectList == classID)
    70       return true;
    71   return false;
    72 }
    73 
    74 /**
    75  * @brief Seeks in the Inheritance if it matches objectList.
    76  * @param className The ClassName of the class this should be a member of.
    77  * @return True if found, false if not.
    78  */
    79 bool NewClassID::isA(const std::string& className) const
    80 {
    81   ClassList::const_iterator it;
    82   for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
    83     if (*(*it)._objectList == className)
    84       return true;
    85   return false;
    86 }
    87 
    88 
    89 void NewClassID::listInheritance() const
    90 {
    91   PRINT(0)("Listing inheritance diagram for ....: ");
    92   ClassList::const_iterator it;
    93   for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
    94     PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id());
    95   PRINT(0)("\n");
    96 
    97 }
  • branches/new_class_id/src/lib/lang/new_class_id.h

    r9682 r9685  
    88#define _NEW_CLASS_ID_H
    99
    10 #include "new_object_list.h"
    11 
    1210#include <string>
    13 #include <list>
    1411
    1512//! A class to dynamically allocate ClassID's and support a isA operator
     
    1714{
    1815public:
    19   NewClassID();
    20   ~NewClassID();
     16  NewClassID() : _id(-1), _name("") { };
     17  NewClassID(int id, const std::string& name) : _id(id), _name(name) { };
     18  // the copy constructor is also defined.
     19  int id() const { return _id; };
     20  const std::string& name() const { return _name; };
    2121
    22   /** @returns the ClassName of the Topmost Object of the ClassStack */
    23   inline const std::string& getClassName() const { return _classes.front()._objectList->name(); }
    24   /** @returns the ID of the Topmost object of the ClassStack */
    25   inline int leafClassID() const { return _classes.front()._objectList->id(); }
    26 
    27   template<class T> void registerObject(T* object, NewObjectList<T>& list);
    28   bool isA(const NewObjectListBase& objectList) const;
    29   bool isA(int classID) const;
    30   bool isA(const std::string& className) const;
    31 
    32   void listInheritance() const;
     22  bool operator==(NewClassID id) const { return _id == id._id || _name == id._name; };
     23  bool operator==(int id) const { return _id == id; };
     24  bool operator==(const std::string& name) const { return _name == name; };
    3325
    3426private:
    35   //////////////////////////////
    36   //// Type Definition Part ////
    37   //////////////////////////////
    38   //! A ClassEntry so we can store Classes inside of Objects
    39   struct ClassEntry
    40   {
    41     /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */
    42     inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {}
    43     NewObjectListBase*                _objectList;  //!< A ObjectList this Object is part of
    44     NewObjectListBase::IteratorBase*  _iterator;    //!< An iterator pointing to the position of the Object inside of the List.
    45   };
    46   typedef std::list<ClassEntry>        ClassList;   //!< Type definition for the List.
    47 
    48   ClassList                           _classes;     //!< All Classes this object is part of.
     27  int            _id;
     28  std::string    _name;
    4929};
    50 
    51 
    52 /**
    53  * @brief Registeres an Object of Type T to objectList
    54  * @param object The Object to append to the objectList.
    55  * @param objectList The ObjectList to append the Object to.
    56  *
    57  * This function is essential to integrate objects into their designated ObjectList.
    58  * Remember if you do not want objects to be stored in Lists (less overhead),
    59  * do not attempt to call this function.
    60  */
    61 template<class T>
    62 inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList)
    63 {
    64   this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object)));
    65 }
    66 
    6730#endif /* _NEW_CLASS_ID_H */
  • branches/new_class_id/src/lib/lang/new_object_list.cc

    r9681 r9685  
    2727 */
    2828NewObjectListBase::NewObjectListBase(const std::string& className, int id)
    29     : _name(className)
    3029{
    3130  if (NewObjectListBase::_classesByID == NULL)
     
    3736  assert(!NewObjectListBase::classNameExists(className) && "Classes should only be included once, and no two classes should have the same name (key value)");
    3837
    39   if (id != -1)
     38  if (id == -1)
    4039  {
    41     this->_id = id;
    42   }
    43   else
    44   {
    45     this->_id = NewObjectListBase::_classesByID->size();
     40    id = NewObjectListBase::_classesByID->size();
    4641    // searching for a free ID
    47     while (NewObjectListBase::classIDExists(_id)) ++id;
     42    while (NewObjectListBase::classIDExists(id)) ++id;
    4843  }
    4944  assert(!NewObjectListBase::classIDExists(id) && "Classes should only be included once, and no two classes should have the same ID (key value)");
     
    5247  //std::cout << "register new ObjectList " << className << " ID: " << this->_id << std::endl;
    5348
    54   (*NewObjectListBase::_classesByID)[this->_id] = this;
    55   (*NewObjectListBase::_classesByName)[this->_name] = this;
     49  this->_identity = NewClassID(id, className);
     50  (*NewObjectListBase::_classesByID)[this->_identity.id()] = this;
     51  (*NewObjectListBase::_classesByName)[this->_identity.name()] = this;
    5652}
    5753
     
    7066  std::cout << "SIZE OF _classByName: " << NewObjectListBase::_classesByName->size() << std::endl;
    7167  */
    72   NewObjectListBase::_classesByName->erase(this->_name);
    73   NewObjectListBase::_classesByID->erase(this->_id);
     68  NewObjectListBase::_classesByID->erase(this->_identity.id());
     69  NewObjectListBase::_classesByName->erase(this->_identity.name());
    7470
    7571  if (NewObjectListBase::_classesByID->empty())
  • branches/new_class_id/src/lib/lang/new_object_list.h

    r9684 r9685  
    88#define _NEW_OBJECT_LIST_H
    99
    10 #include "type_info.h"
     10#include "new_class_id.h"
    1111#include <map>
    1212#include <list>
     
    4040
    4141public:
    42   inline int id() const { return _id; };
    43   inline const std::string& name() const { return _name; };
    44   bool operator==(int id) const { return _id == id; };
    45   bool operator==(const std::string& name) const { return _name == name; };
     42  inline int id() const { return _identity.id(); };
     43  inline const std::string& name() const { return _identity.name(); };
     44  bool operator==(int id) const { return _identity == id; };
     45  bool operator==(const std::string& name) const { return _identity == name; };
    4646
    4747  virtual void debug() const = 0;
     
    6969  typedef std::map<std::string, NewObjectListBase*> classNameMap;//!< The Generic Map.
    7070
    71   int                           _id;                //!< The ID of the class.
    72   std::string                   _name;              //!< The Name of the Class.
     71  NewClassID                    _identity;          //!< The Identity of the Class (ID and Name).
    7372
    7473private:
     
    114113  inline const list&      objects() const { return _objects; };
    115114
     115  inline iterator begin() { return _objects.begin(); };
     116  inline const_iterator begin() const { return _objects.begin(); };
     117  inline iterator  end() { return _objects.end(); };
     118  inline const_iterator  end() const { return _objects.end(); };
     119
     120  inline bool empty() const { return _objects.empty(); };
     121  inline int size() const { return _objects.size(); };
     122  inline T* front() const { return _objects.front(); };
     123  inline T* back() const { return _objects.back(); };
     124
    116125  NewObjectListBase::IteratorBase* registerObject(T* object);
    117126  void unregisterObject(IteratorBase* iterator);
Note: See TracChangeset for help on using the changeset viewer.