Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9701 in orxonox.OLD for branches/new_class_id/src/lib


Ignore:
Timestamp:
Aug 25, 2006, 11:20:21 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: new safer concept for NewClassID

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

    r9698 r9701  
    1717
    1818#include "new_class_id.h"
    19 
     19#include "new_object_list.h"
    2020
    2121NewClassID::NewClassID()
     
    2424};
    2525
     26NewClassID::NewClassID(const NewObjectListBase* objList)
     27{
     28
     29  objList->acquireID(_id, _name);
     30
     31}
     32
     33
    2634NewClassID NullClass::_classID;
  • branches/new_class_id/src/lib/lang/new_class_id.h

    r9698 r9701  
    1010#include <string>
    1111
     12class NewObjectListBase;
     13
    1214//! A class to dynamically allocate ClassID's and support a isA operator
    1315class NewClassID
     
    1517public:
    1618  NewClassID();
    17   NewClassID(int id, const std::string& name) : _id(id), _name(name) { };
     19  NewClassID(const NewObjectListBase* id);
    1820  // the copy constructor is also defined.
    19   const int& id() const { return _id; };
    20   const std::string& name() const { return _name; };
     21  const int& id() const { return *_id; };
     22  const std::string& name() const { return *_name; };
    2123
    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; };
    25   bool operator!=(NewClassID id) const { return _id != id._id && _name != id._name; };
    26   bool operator!=(int id) const { return _id != id; };
    27   bool operator!=(const std::string& name) const { return _name != name; };
     24  bool operator==(const NewClassID& id) const { return *_id == *id._id /* || _name == id._name */; };
     25  bool operator==(int id) const { return *_id == id; };
     26  bool operator==(const std::string& name) const { return *_name == name; };
     27  bool operator!=(const NewClassID& id) const { return *_id != *id._id /* && _name != id._name*/; };
     28  bool operator!=(int id) const { return *_id != id; };
     29  bool operator!=(const std::string& name) const { return *_name != name; };
    2830
    2931private:
    30   int                _id;
    31   std::string        _name;
     32  const int*                _id;
     33  const std::string*        _name;
    3234};
    3335
  • branches/new_class_id/src/lib/lang/new_object_list.cc

    r9696 r9701  
    2727 */
    2828NewObjectListBase::NewObjectListBase(const std::string& className, int id)
     29  : _name(className)
    2930{
    3031  if (NewObjectListBase::_classesByID == NULL)
     
    4445  assert(!NewObjectListBase::classIDExists(id) && "Classes should only be included once, and no two classes should have the same ID (key value)");
    4546
     47  _id = id;
    4648  /// Some Output, that will fall out later
    4749  //std::cout << "register new ObjectList " << className << " ID: " << this->_id << std::endl;
    4850
    49   this->_identity = NewClassID(id, className);
     51  this->_identity = NewClassID(this);
    5052  (*NewObjectListBase::_classesByID)[this->_identity.id()] = this;
    5153  (*NewObjectListBase::_classesByName)[this->_identity.name()] = this;
     
    157159 * @param objectName the Name of the Object to search for
    158160 */
    159 BaseObject* NewObjectListBase::getObject(int classID, const std::string& objectName)
     161BaseObject* NewObjectListBase::getBaseObject(int classID, const std::string& objectName)
    160162{
    161163  const NewObjectListBase* const base = NewObjectListBase::getObjectList(classID);
     
    172174 * @param objectName the Name of the Object to search for
    173175 */
    174 BaseObject* NewObjectListBase::getObject(const std::string& className, const std::string& objectName)
     176BaseObject* NewObjectListBase::getBaseObject(const std::string& className, const std::string& objectName)
    175177{
    176178  const NewObjectListBase* const base = NewObjectListBase::getObjectList(className);
     
    187189 * @param objectName the Name of the Object to search for
    188190 */
    189 BaseObject* NewObjectListBase::getObject(const NewClassID& classID, const std::string& objectName)
     191BaseObject* NewObjectListBase::getBaseObject(const NewClassID& classID, const std::string& objectName)
    190192{
    191193  const NewObjectListBase* const base = NewObjectListBase::getObjectList(classID);
  • branches/new_class_id/src/lib/lang/new_object_list.h

    r9698 r9701  
    5151
    5252public:
    53   inline const NewClassID& identity() const { return _identity; };
    54   inline int id() const { return _identity.id(); };
    55   inline const std::string& name() const { return _identity.name(); };
    56   bool operator==(int id) const { return _identity == id; };
    57   bool operator==(const NewClassID& id) const { return _identity == id; };
    58   bool operator==(const std::string& name) const { return _identity == name; };
     53  inline const NewClassID& identity() const { return _identity; }
     54  inline int id() const { return _id; };
     55  inline const std::string& name() const { return _name; };
     56  bool operator==(int id) const { return _id == id; };
     57  bool operator==(const NewClassID& id) const { return id == _id; };
     58  bool operator==(const std::string& name) const { return _name == name; };
     59
     60  void acquireID(const int*& id, const std::string*& name) const { id = &_id; name = &_name; };
    5961
    6062  virtual void debug() const = 0;
     
    130132  typedef std::map<std::string, NewObjectListBase*> classNameMap; //!< The Generic Map.
    131133
    132   NewClassID                    _identity;          //!< The Identity of the Class (ID and Name).
     134  int                           _id;
     135  const std::string             _name;              //!< The Name of the Class.
     136  NewClassID                    _identity;          //!< The Identity of the Class. (equal to _id and _name)
    133137
    134138private:
Note: See TracChangeset for help on using the changeset viewer.