Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Sep 1, 2006, 8:06:39 PM (18 years ago)
Author:
bensch
Message:

renamed newclassid to classid and newobjectlist to objectlist

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

Legend:

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

    r9691 r9715  
    2121#include "util/loading/load_param.h"
    2222
    23 NewObjectListDefinition(BaseObject);
     23ObjectListDefinition(BaseObject);
    2424
    2525/**
     
    4343BaseObject::~BaseObject ()
    4444{
    45   /// Remove from the NewObjectLists
     45  /// Remove from the ObjectLists
    4646  ClassList::iterator it;
    4747  for (it = this->_classes.begin(); it != this->_classes.end(); ++it)
     
    8989 * @return True if found, false if not.
    9090 */
    91 bool BaseObject::isA(const NewObjectListBase& objectList) const
     91bool BaseObject::isA(const ObjectListBase& objectList) const
    9292{
    9393  ClassList::const_iterator it;
     
    104104 * @return True if found, false if not.
    105105 */
    106 bool BaseObject::isA(const NewClassID& classID) const
     106bool BaseObject::isA(const ClassID& classID) const
    107107{
    108108  ClassList::const_iterator it;
  • branches/new_class_id/src/lib/lang/base_object.h

    r9709 r9715  
    2626class BaseObject : public sigslot::has_slots<>
    2727{
    28   NewObjectListDeclaration(BaseObject);
     28  ObjectListDeclaration(BaseObject);
    2929public:
    3030  BaseObject (const std::string& objectName = "");
     
    4848  inline const std::string& getClassName() const { return _classes.front()._objectList->name(); };
    4949
    50   inline const NewClassID& getClassID() const { return *_leafClassID; }
     50  inline const ClassID& getClassID() const { return *_leafClassID; }
    5151  /** @returns the ID of the Topmost object of the ClassStack */
    5252  inline const int& getLeafClassID() const { return _leafClassID->id(); }
    5353
    54   bool isA(const NewObjectListBase& objectList) const;
    55   bool isA(const NewClassID& classID) const;
     54  bool isA(const ObjectListBase& objectList) const;
     55  bool isA(const ClassID& classID) const;
    5656  bool isA(int classID) const;
    5757  bool isA(const std::string& className) const;
     
    6565
    6666protected:
    67   template<class T> void registerObject(T* object, NewObjectList<T>& list);
     67  template<class T> void registerObject(T* object, ObjectList<T>& list);
    6868
    6969protected:
     
    8080  struct ClassEntry
    8181  {
    82     /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */
    83     inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {}
    84     NewObjectListBase*                _objectList;  //!< A ObjectList this Object is part of
    85     NewObjectListBase::IteratorBase*  _iterator;    //!< An iterator pointing to the position of the Object inside of the List.
     82    /** Simple Constuctor @param objectList the ObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */
     83    inline ClassEntry (ObjectListBase* objectList, ObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {}
     84    ObjectListBase*                _objectList;  //!< A ObjectList this Object is part of
     85    ObjectListBase::IteratorBase*  _iterator;    //!< An iterator pointing to the position of the Object inside of the List.
    8686  };
    8787  typedef std::list<ClassEntry>        ClassList;   //!< Type definition for the List.
     
    8989  std::string                         className;    //!< the name of the class
    9090  ClassList                           _classes;     //!< All Classes this object is part of.
    91   const NewClassID*                       _leafClassID;  //!< Topmost ClassID.
     91  const ClassID*                       _leafClassID;  //!< Topmost ClassID.
    9292};
    9393
     
    103103 */
    104104template<class T>
    105 inline void BaseObject::registerObject(T* object, NewObjectList<T>& objectList)
     105inline void BaseObject::registerObject(T* object, ObjectList<T>& objectList)
    106106{
    107107  this->_leafClassID = &objectList.identity();
  • branches/new_class_id/src/lib/lang/new_class_id.cc

    r9709 r9715  
    2323 * this Always points to the ID of the NullClass.
    2424 */
    25 NewClassID::NewClassID()
     25ClassID::ClassID()
    2626{
    2727  NullClass::acquireID(this->_id, this->_name);
     
    3030/**
    3131 * @brief Acquiring the ID of a objectList.
    32  * @param objList The NewObjectList to acquire the ID from.
     32 * @param objList The ObjectList to acquire the ID from.
    3333 */
    34 NewClassID::NewClassID(const NewObjectListBase* const objList)
     34ClassID::ClassID(const ObjectListBase* const objList)
    3535{
    3636  objList->acquireID(this->_id, this->_name);
     
    3838
    3939
    40 NewClassID NullClass::_classID;
     40ClassID NullClass::_classID;
    4141
    4242int NullClass::_nullID;
  • branches/new_class_id/src/lib/lang/new_class_id.h

    r9709 r9715  
    1010#include <string>
    1111
    12 class NewObjectListBase;
     12class ObjectListBase;
    1313
    1414//! A class to dynamically allocate ClassID's and to support a isA operator
    1515/**
    16  * A NewClassID can only be aquired over a NewObjectList,
     16 * A ClassID can only be aquired over a ObjectList,
    1717 * thus enabling the developer to have permanent access to the correct ID and ClassName
    1818 *
    19  * The Idea behind this concept is, that storing a NewClassID that changes its internal state
    20  * all NewClassID's will be updated correctly.
     19 * The Idea behind this concept is, that storing a ClassID that changes its internal state
     20 * all ClassID's will be updated correctly.
    2121 *
    22  * Since the Existance of any NewObjectList is a requirement during the working process all
     22 * Since the Existance of any ObjectList is a requirement during the working process all
    2323 * ID's should reference a valid ID and ClassName
    2424 */
    25 class NewClassID
     25class ClassID
    2626{
    2727public:
    28   NewClassID();
    29   NewClassID(const NewObjectListBase* const id);
     28  ClassID();
     29  ClassID(const ObjectListBase* const id);
    3030  /// the copy constructor is also defined implicitely.
    3131
     
    3636
    3737  /** @param id the id to compare @returns true on match (match is same ID) @brief compares two id's */
    38   bool operator==(const NewClassID& id) const { return *_id == *id._id /* || _name == id._name */; };
     38  bool operator==(const ClassID& id) const { return *_id == *id._id /* || _name == id._name */; };
    3939  /** @param id the id to compare @returns true on match (match is same ID) @brief compares two id's */
    4040  bool operator==(int id) const { return *_id == id; };
     
    4242  bool operator==(const std::string& name) const { return *_name == name; };
    4343  /** @param id the id to compare @returns false on match (match is same ID) @brief compares two id's */
    44   bool operator!=(const NewClassID& id) const { return *_id != *id._id /* && _name != id._name*/;  };
     44  bool operator!=(const ClassID& id) const { return *_id != *id._id /* && _name != id._name*/;  };
    4545  /** @param id the id to compare @returns false on match (match is same ID) @brief compares two id's */
    4646  bool operator!=(int id) const { return *_id != id; };
     
    6161public:
    6262  /** @returns the NullClass' ID. */
    63   static const NewClassID& classID() { return NullClass::_classID; }
     63  static const ClassID& classID() { return NullClass::_classID; }
    6464  /** @param id the ID to acquire @param name the name to acquire @brief acquires the ID of this Class */
    6565  static void acquireID(const int*& id, const std::string*& name) { id = &_nullID; name = &_nullName; };
     
    6969
    7070private:
    71   static NewClassID         _classID;      //!< The NullClass' ID
     71  static ClassID         _classID;      //!< The NullClass' ID
    7272  static const std::string  _nullName;     //!< The NullClass' Name ("NullClass")
    7373  static int                _nullID;       //!< The NullClass' ID
  • branches/new_class_id/src/lib/lang/new_object_list.cc

    r9709 r9715  
    2828 * @return a new NewObejctList
    2929 */
    30 NewObjectListBase::NewObjectListBase(const std::string& className, int id)
     30ObjectListBase::ObjectListBase(const std::string& className, int id)
    3131    : _name(className)
    3232{
    33   printf("NewObjectList, Registered %s::%d\n", className.c_str(), id);
    34   if (NewObjectListBase::_classesByID == NULL)
    35   {
    36     NewObjectListBase::_classesByID = new classIDMap;
    37     assert (NewObjectListBase::_classesByName == NULL);
    38     NewObjectListBase::_classesByName = new classNameMap;
    39   }
    40   assert(!NewObjectListBase::classNameExists(className) && "Classes should only be included once, and no two classes should have the same name (key value)");
     33  printf("ObjectList, Registered %s::%d\n", className.c_str(), id);
     34  if (ObjectListBase::_classesByID == NULL)
     35  {
     36    ObjectListBase::_classesByID = new classIDMap;
     37    assert (ObjectListBase::_classesByName == NULL);
     38    ObjectListBase::_classesByName = new classNameMap;
     39  }
     40  assert(!ObjectListBase::classNameExists(className) && "Classes should only be included once, and no two classes should have the same name (key value)");
    4141
    4242  if (id == -1)
    4343  {
    44     id = NewObjectListBase::_classesByID->size();
     44    id = ObjectListBase::_classesByID->size();
    4545    // searching for a free ID
    46     while (NewObjectListBase::classIDExists(id)) ++id;
    47   }
    48   assert(!NewObjectListBase::classIDExists(id) && "Classes should only be included once, and no two classes should have the same ID (key value)");
     46    while (ObjectListBase::classIDExists(id)) ++id;
     47  }
     48  assert(!ObjectListBase::classIDExists(id) && "Classes should only be included once, and no two classes should have the same ID (key value)");
    4949
    5050  _id = id;
     
    5252  std::cout << "register new ObjectList " << className << " ID: " << this->_id << std::endl;
    5353
    54   this->_identity = NewClassID(this);
    55   (*NewObjectListBase::_classesByID)[this->_identity.id()] = this;
    56   (*NewObjectListBase::_classesByName)[this->_identity.name()] = this;
     54  this->_identity = ClassID(this);
     55  (*ObjectListBase::_classesByID)[this->_identity.id()] = this;
     56  (*ObjectListBase::_classesByName)[this->_identity.name()] = this;
    5757}
    5858
     
    6161 * Destructor.
    6262 *
    63  * This destructor deletes the NewObjectList, and cleans up the NewObjectList sorted Maps.
    64  */
    65 NewObjectListBase::~NewObjectListBase()
    66 {
    67   assert (NewObjectListBase::_classesByName != NULL && NewObjectListBase::_classesByID != NULL);
     63 * This destructor deletes the ObjectList, and cleans up the ObjectList sorted Maps.
     64 */
     65ObjectListBase::~ObjectListBase()
     66{
     67  assert (ObjectListBase::_classesByName != NULL && ObjectListBase::_classesByID != NULL);
    6868  /*
    6969  std::cout << "Erasing: " << this->_name << " "<< this->_id  << std::endl;
    70   std::cout << "SIZE OF _classByID: " << NewObjectListBase::_classesByID->size() << std::endl;
    71   std::cout << "SIZE OF _classByName: " << NewObjectListBase::_classesByName->size() << std::endl;
     70  std::cout << "SIZE OF _classByID: " << ObjectListBase::_classesByID->size() << std::endl;
     71  std::cout << "SIZE OF _classByName: " << ObjectListBase::_classesByName->size() << std::endl;
    7272  */
    73   NewObjectListBase::_classesByID->erase(this->_identity.id());
    74   NewObjectListBase::_classesByName->erase(this->_identity.name());
    75 
    76   if (NewObjectListBase::_classesByID->empty())
    77   {
    78     delete NewObjectListBase::_classesByID;
    79     NewObjectListBase::_classesByID = NULL;
    80     assert(NewObjectListBase::_classesByName != NULL);
    81     delete NewObjectListBase::_classesByName;
    82     NewObjectListBase::_classesByName = NULL;
    83   }
    84 }
    85 
    86 NewObjectListBase::classIDMap* NewObjectListBase::_classesByID = NULL;
    87 NewObjectListBase::classNameMap* NewObjectListBase::_classesByName = NULL;
     73  ObjectListBase::_classesByID->erase(this->_identity.id());
     74  ObjectListBase::_classesByName->erase(this->_identity.name());
     75
     76  if (ObjectListBase::_classesByID->empty())
     77  {
     78    delete ObjectListBase::_classesByID;
     79    ObjectListBase::_classesByID = NULL;
     80    assert(ObjectListBase::_classesByName != NULL);
     81    delete ObjectListBase::_classesByName;
     82    ObjectListBase::_classesByName = NULL;
     83  }
     84}
     85
     86ObjectListBase::classIDMap* ObjectListBase::_classesByID = NULL;
     87ObjectListBase::classNameMap* ObjectListBase::_classesByName = NULL;
    8888
    8989/**
    9090 * @returns the Registered Class Count.
    9191 */
    92 unsigned int NewObjectListBase::classCount()
    93 {
    94   assert (NewObjectListBase::_classesByID != NULL);
    95   return NewObjectListBase::_classesByID->size();
     92unsigned int ObjectListBase::classCount()
     93{
     94  assert (ObjectListBase::_classesByID != NULL);
     95  return ObjectListBase::_classesByID->size();
    9696};
    9797
     
    101101 * @return true if such a class already exists.
    102102 */
    103 bool NewObjectListBase::classIDExists(int id)
    104 {
    105   return (NewObjectListBase::_classesByID->find(id) != NewObjectListBase::_classesByID->end());
     103bool ObjectListBase::classIDExists(int id)
     104{
     105  return (ObjectListBase::_classesByID->find(id) != ObjectListBase::_classesByID->end());
    106106}
    107107
     
    111111 * @return true if such a class already exists.
    112112 */
    113 bool NewObjectListBase::classNameExists(const std::string& name)
    114 {
    115   return (NewObjectListBase::_classesByName->find(name) != NewObjectListBase::_classesByName->end());
    116 }
    117 
    118 /**
    119  * @brief searches for a NewClassID in the list of all NewObjectLists, and returns its Identity
     113bool ObjectListBase::classNameExists(const std::string& name)
     114{
     115  return (ObjectListBase::_classesByName->find(name) != ObjectListBase::_classesByName->end());
     116}
     117
     118/**
     119 * @brief searches for a ClassID in the list of all ObjectLists, and returns its Identity
    120120 * @param id: The Id to search for
    121121 * @returns the ClassID if found and NullClass' identity if not.
    122122 */
    123 const NewClassID& NewObjectListBase::retrieveIdentity(int id)
    124 {
    125   const NewObjectListBase* const base = NewObjectListBase::getObjectList(id);
     123const ClassID& ObjectListBase::retrieveIdentity(int id)
     124{
     125  const ObjectListBase* const base = ObjectListBase::getObjectList(id);
    126126
    127127  if (base != NULL)
     
    133133
    134134/**
    135  * @brief searches for a NewClassID in the list of all NewObjectLists, and returns its Identity
     135 * @brief searches for a ClassID in the list of all ObjectLists, and returns its Identity
    136136 * @param name: The Name to search for
    137137 * @returns the ClassID if found and NullClass' identity if not.
    138138 */
    139 const NewClassID& NewObjectListBase::retrieveIdentity(const std::string& name)
    140 {
    141   const NewObjectListBase* const base = NewObjectListBase::getObjectList(name);
     139const ClassID& ObjectListBase::retrieveIdentity(const std::string& name)
     140{
     141  const ObjectListBase* const base = ObjectListBase::getObjectList(name);
    142142
    143143  if (base != NULL)
     
    151151 * @brief Searches for a ObjectList with the ID classID
    152152 * @param classID the ID to search for.
    153  * @return The NewObjectList if found, NULL otherwise.
    154  */
    155 const NewObjectListBase* const NewObjectListBase::getObjectList(int classID)
    156 {
    157   assert (NewObjectListBase::_classesByID != NULL);
    158   NewObjectListBase::classIDMap::iterator it = NewObjectListBase::_classesByID->find(classID);
    159   if (it != NewObjectListBase::_classesByID->end())
     153 * @return The ObjectList if found, NULL otherwise.
     154 */
     155const ObjectListBase* const ObjectListBase::getObjectList(int classID)
     156{
     157  assert (ObjectListBase::_classesByID != NULL);
     158  ObjectListBase::classIDMap::iterator it = ObjectListBase::_classesByID->find(classID);
     159  if (it != ObjectListBase::_classesByID->end())
    160160    return (*it).second;
    161161  else
     
    166166 * @brief Searches for a ObjectList with the Name className
    167167 * @param className the Name to search for.
    168  * @return The NewObjectList if found, NULL otherwise.
    169  */
    170 const NewObjectListBase* const NewObjectListBase::getObjectList(const std::string& className)
    171 {
    172   assert (NewObjectListBase::_classesByName != NULL);
    173   NewObjectListBase::classNameMap::iterator it = NewObjectListBase::_classesByName->find(className);
    174   if (it != NewObjectListBase::_classesByName->end())
     168 * @return The ObjectList if found, NULL otherwise.
     169 */
     170const ObjectListBase* const ObjectListBase::getObjectList(const std::string& className)
     171{
     172  assert (ObjectListBase::_classesByName != NULL);
     173  ObjectListBase::classNameMap::iterator it = ObjectListBase::_classesByName->find(className);
     174  if (it != ObjectListBase::_classesByName->end())
    175175    return (*it).second;
    176176  else
     
    179179
    180180/**
    181  * @brief Searches for a ObjectList with the NewClassID classID
     181 * @brief Searches for a ObjectList with the ClassID classID
    182182 * @param classID the ID to search for.
    183  * @return The NewObjectList if found, NULL otherwise.
    184  */
    185 const NewObjectListBase* const NewObjectListBase::getObjectList(const NewClassID& classID)
    186 {
    187   return NewObjectListBase::getObjectList(classID.id());
     183 * @return The ObjectList if found, NULL otherwise.
     184 */
     185const ObjectListBase* const ObjectListBase::getObjectList(const ClassID& classID)
     186{
     187  return ObjectListBase::getObjectList(classID.id());
    188188}
    189189
     
    193193 * @param objectName the Name of the Object to search for
    194194 */
    195 BaseObject* NewObjectListBase::getBaseObject(int classID, const std::string& objectName)
    196 {
    197   const NewObjectListBase* const base = NewObjectListBase::getObjectList(classID);
     195BaseObject* ObjectListBase::getBaseObject(int classID, const std::string& objectName)
     196{
     197  const ObjectListBase* const base = ObjectListBase::getObjectList(classID);
    198198
    199199  if (base != NULL)
     
    208208 * @param objectName the Name of the Object to search for
    209209 */
    210 BaseObject* NewObjectListBase::getBaseObject(const std::string& className, const std::string& objectName)
    211 {
    212   const NewObjectListBase* const base = NewObjectListBase::getObjectList(className);
     210BaseObject* ObjectListBase::getBaseObject(const std::string& className, const std::string& objectName)
     211{
     212  const ObjectListBase* const base = ObjectListBase::getObjectList(className);
    213213
    214214  if (base != NULL)
     
    220220/**
    221221 * @brief Retrieves the first BaseObject matching the name objectName from the List matching classID.
    222  * @param classID The NewClassID of the List.
     222 * @param classID The ClassID of the List.
    223223 * @param objectName the Name of the Object to search for
    224224 */
    225 BaseObject* NewObjectListBase::getBaseObject(const NewClassID& classID, const std::string& objectName)
    226 {
    227   const NewObjectListBase* const base = NewObjectListBase::getObjectList(classID);
     225BaseObject* ObjectListBase::getBaseObject(const ClassID& classID, const std::string& objectName)
     226{
     227  const ObjectListBase* const base = ObjectListBase::getObjectList(classID);
    228228
    229229  if (base != NULL)
     
    238238 * @brief Prints out some debugging information about a given List.
    239239 */
    240 void NewObjectListBase::debug(unsigned int level) const
     240void ObjectListBase::debug(unsigned int level) const
    241241{
    242242  base_list list;
     
    259259
    260260
    261 void NewObjectListBase::debugAll(unsigned int level)
    262 {
    263   printf("Listing all %d ObjectLists \n", NewObjectListBase::_classesByID->size());
    264 
    265   for (classNameMap::const_iterator it = NewObjectListBase::_classesByName->begin();
    266        it != NewObjectListBase::_classesByName->end();
     261void ObjectListBase::debugAll(unsigned int level)
     262{
     263  printf("Listing all %d ObjectLists \n", ObjectListBase::_classesByID->size());
     264
     265  for (classNameMap::const_iterator it = ObjectListBase::_classesByName->begin();
     266       it != ObjectListBase::_classesByName->end();
    267267       ++it)
    268268  {
     
    280280 * @return The ClassName or an empty string if the ID was not found.
    281281 */
    282 const std::string& NewObjectListBase::IDToString(int classID)
    283 {
    284   const NewObjectListBase* const base = NewObjectListBase::getObjectList(classID);
     282const std::string& ObjectListBase::IDToString(int classID)
     283{
     284  const ObjectListBase* const base = ObjectListBase::getObjectList(classID);
    285285
    286286  if (base != NULL)
     
    299299 * @return The Classes ID if found, -1 otherwise.
    300300 */
    301 int NewObjectListBase::StringToID(const std::string& className)
    302 {
    303   const NewObjectListBase* const base = NewObjectListBase::getObjectList(className);
     301int ObjectListBase::StringToID(const std::string& className)
     302{
     303  const ObjectListBase* const base = ObjectListBase::getObjectList(className);
    304304
    305305  if (base != NULL)
  • branches/new_class_id/src/lib/lang/new_object_list.h

    r9713 r9715  
    2121 * two new functions objectList() and classID().
    2222 */
    23 #define NewObjectListDeclaration(ClassName) \
     23#define ObjectListDeclaration(ClassName) \
    2424  public: \
    25    static inline const NewObjectList<ClassName>& objectList() { return ClassName::_objectList; }; \
    26    static inline const NewClassID& classID() { return ClassName::_objectList.identity(); }; \
     25   static inline const ObjectList<ClassName>& objectList() { return ClassName::_objectList; }; \
     26   static inline const ClassID& classID() { return ClassName::_objectList.identity(); }; \
    2727  private: \
    28    static NewObjectList<ClassName> _objectList
    29 
    30 #define NewObjectListDefinitionID(ClassName, ID) \
    31    NewObjectList<ClassName> ClassName::_objectList(#ClassName, ID)
    32 
    33 
    34 #define NewObjectListDefinition(ClassName) \
    35     NewObjectListDefinitionID(ClassName, -1)
     28   static ObjectList<ClassName> _objectList
     29
     30#define ObjectListDefinitionID(ClassName, ID) \
     31   ObjectList<ClassName> ClassName::_objectList(#ClassName, ID)
     32
     33
     34#define ObjectListDefinition(ClassName) \
     35    ObjectListDefinitionID(ClassName, -1)
    3636
    3737class BaseObject;
    38 //! The superclass that all NewObjectLists follow.
    39 /**
    40  * @see template<class T> NewObjectList<T>
    41  */
    42 class NewObjectListBase
     38//! The superclass that all ObjectLists follow.
     39/**
     40 * @see template<class T> ObjectList<T>
     41 */
     42class ObjectListBase
    4343{
    4444public:
     
    5656public:
    5757  /** @returns The Identity of the Class stored within. */
    58   inline const NewClassID&              identity() const { return _identity; }
     58  inline const ClassID&              identity() const { return _identity; }
    5959  /** @returns the ID of the Identity of the ObjectList */
    6060  inline int                            id() const { return _id; };
     
    6464  inline bool                           operator==(int id) const { return _id == id; };
    6565  /** @param id The id to compare @returns true on match, false otherwise */
    66   inline bool                           operator==(const NewClassID& id) const { return id == _id; };
     66  inline bool                           operator==(const ClassID& id) const { return id == _id; };
    6767  /** @param name The name to compare @returns true on match, false otherwise */
    6868  inline bool                           operator==(const std::string& name) const { return _name == name; };
     
    7272  virtual void                          getBaseObjectList(base_list* list) const = 0;
    7373
    74   static const NewClassID&              retrieveIdentity(int id);
    75   static const NewClassID&              retrieveIdentity(const std::string& name);
    76 
    77   static const NewObjectListBase* const getObjectList(int classID);
    78   static const NewObjectListBase* const getObjectList(const std::string& className);
    79   static const NewObjectListBase* const getObjectList(const NewClassID& classID);
     74  static const ClassID&              retrieveIdentity(int id);
     75  static const ClassID&              retrieveIdentity(const std::string& name);
     76
     77  static const ObjectListBase* const getObjectList(int classID);
     78  static const ObjectListBase* const getObjectList(const std::string& className);
     79  static const ObjectListBase* const getObjectList(const ClassID& classID);
    8080
    8181  static BaseObject*                    getBaseObject(int classID, const std::string& objectName);
    8282  static BaseObject*                    getBaseObject(const std::string& className, const std::string& objectName);
    83   static BaseObject*                    getBaseObject(const NewClassID& classID, const std::string& objectName);
     83  static BaseObject*                    getBaseObject(const ClassID& classID, const std::string& objectName);
    8484
    8585  /** @returns an Object with Name name out of this List @param name the name of the Object. */
     
    100100
    101101protected:
    102   NewObjectListBase(const std::string& className, int id = -1);
    103   virtual ~NewObjectListBase();
    104 
    105 private:
    106   NewObjectListBase(const NewObjectListBase&);
     102  ObjectListBase(const std::string& className, int id = -1);
     103  virtual ~ObjectListBase();
     104
     105private:
     106  ObjectListBase(const ObjectListBase&);
    107107
    108108  static bool                         classIDExists(int id);
     
    111111
    112112protected:
    113   typedef std::map<int, NewObjectListBase*>         classIDMap;   //!< The Generic Map.
    114   typedef std::map<std::string, NewObjectListBase*> classNameMap; //!< The Generic Map.
     113  typedef std::map<int, ObjectListBase*>         classIDMap;   //!< The Generic Map.
     114  typedef std::map<std::string, ObjectListBase*> classNameMap; //!< The Generic Map.
    115115
    116116private:
    117117  int                           _id;
    118118  const std::string             _name;              //!< The Name of the Class.
    119   NewClassID                    _identity;          //!< The Identity of the Class. (equal to _id and _name)
     119  ClassID                    _identity;          //!< The Identity of the Class. (equal to _id and _name)
    120120
    121121private:
     
    135135 *  as with normal std::list.
    136136 *
    137  * Furthermore the linkage over the single Lists is given over the Superclass NewObjectListBase.
     137 * Furthermore the linkage over the single Lists is given over the Superclass ObjectListBase.
    138138 *
    139139 *
     
    141141 *
    142142 * To define a Class with a ObjectList, you have to:
    143  *  1. Include 'NewObjectListDeclaration(T);' in its Declaration (at the beginning)
    144  *  2. Include 'NewObjectListDefinition(T);' in some Definition file (cc-file)
     143 *  1. Include 'ObjectListDeclaration(T);' in its Declaration (at the beginning)
     144 *  2. Include 'ObjectListDefinition(T);' in some Definition file (cc-file)
    145145 *  3. In the constructor add 'registerObject(this, objectList);'
    146146 *
     
    154154 *
    155155 * @example Iterating: Iteration is made easy, and fast as follows:
    156  *   for (NewObjectList<PlayerStats>::const_iterator it = PlayerStats::objectList().begin();
     156 *   for (ObjectList<PlayerStats>::const_iterator it = PlayerStats::objectList().begin();
    157157 *      it != PlayerStats::objectList().end();
    158158 *     ++it)
     
    166166 */
    167167template<class T>
    168 class NewObjectList : public NewObjectListBase
     168class ObjectList : public ObjectListBase
    169169{
    170170public:
     
    174174
    175175
    176 class Iterator : public NewObjectListBase::IteratorBase
     176class Iterator : public ObjectListBase::IteratorBase
    177177  {
    178178  public:
    179179    Iterator(iterator it) { _it = it; }
    180180    inline iterator& it() { return _it; }
    181     typename NewObjectList::iterator _it;
     181    typename ObjectList::iterator _it;
    182182  };
    183183
    184184public:
    185   NewObjectList(const std::string& name, int id = -1);
    186   ~NewObjectList();
     185  ObjectList(const std::string& name, int id = -1);
     186  ~ObjectList();
    187187
    188188  virtual BaseObject*                getBaseObject(const std::string& name) const;
     
    210210
    211211
    212   NewObjectListBase::IteratorBase*   registerObject(T* object);
     212  ObjectListBase::IteratorBase*   registerObject(T* object);
    213213  virtual void                       unregisterObject(IteratorBase* iterator);
    214214
    215215protected:
    216   virtual void                       getBaseObjectList(NewObjectListBase::base_list* list) const;
     216  virtual void                       getBaseObjectList(ObjectListBase::base_list* list) const;
    217217
    218218
    219219private:
    220220  //! the copy constructor will be hidden.
    221   NewObjectList(const NewObjectList& definer) {};
     221  ObjectList(const ObjectList& definer) {};
    222222
    223223private:
     
    233233/////////////////////////
    234234/**
    235  * @brief creates a new NewObjectList
     235 * @brief creates a new ObjectList
    236236 * @param name The name of the Class.
    237237 * @param id The ID of the class if desired, or -1 if an id should be assigned automatically.
    238238 */
    239239template <class T>
    240 NewObjectList<T>::NewObjectList(const std::string& name, int id)
    241     : NewObjectListBase(name, id)
     240ObjectList<T>::ObjectList(const std::string& name, int id)
     241    : ObjectListBase(name, id)
    242242{}
    243243
    244244/**
    245  * @brief deletes the NewObjectList.
    246  */
    247 template <class T>
    248 NewObjectList<T>::~NewObjectList()
     245 * @brief deletes the ObjectList.
     246 */
     247template <class T>
     248ObjectList<T>::~ObjectList()
    249249{
    250250  if (!_objects.empty())
     
    260260 */
    261261template <class T>
    262 BaseObject* NewObjectList<T>::getBaseObject(const std::string& name) const
     262BaseObject* ObjectList<T>::getBaseObject(const std::string& name) const
    263263{
    264264  return this->getObject(name);
     
    273273 */
    274274template <class T>
    275 T* NewObjectList<T>::getObject(const std::string& name) const
     275T* ObjectList<T>::getObject(const std::string& name) const
    276276{
    277277  const_iterator it;
     
    288288 */
    289289template <class T>
    290     bool NewObjectList<T>::exists(const T* const object) const
     290    bool ObjectList<T>::exists(const T* const object) const
    291291{
    292292  return (std::find(_objects.begin(), _objects.end(), object) != _objects.end());
     
    299299 */
    300300template <class T>
    301 void NewObjectList<T>::getBaseObjectList(NewObjectListBase::base_list* list) const
     301void ObjectList<T>::getBaseObjectList(ObjectListBase::base_list* list) const
    302302{
    303303  assert (list != NULL);
     
    309309
    310310/**
    311  * @brief registers an Object to the NewObjectList.
     311 * @brief registers an Object to the ObjectList.
    312312 * @param T object the Object to register.
    313313 * @returns a pointer to the iterator inside of the list.
    314314 */
    315315template <class T>
    316 NewObjectListBase::IteratorBase* NewObjectList<T>::registerObject(T* object)
     316ObjectListBase::IteratorBase* ObjectList<T>::registerObject(T* object)
    317317{
    318318  this->_objects.push_back(object);
     
    325325 */
    326326template <class T>
    327 void NewObjectList<T>::unregisterObject(IteratorBase* iterator)
     327void ObjectList<T>::unregisterObject(IteratorBase* iterator)
    328328{
    329329  this->_objects.erase(static_cast<Iterator*>(iterator)->it());
  • branches/new_class_id/src/lib/lang/test_object_list.cc

    r9682 r9715  
    1212  //   bool operator==(const std::string& name) const { return _objectName == name; };
    1313
    14     NewObjectListDeclaration(NewBaseObject);
     14    ObjectListDeclaration(NewBaseObject);
    1515
    1616protected:
     
    2020  };
    2121  template<class T>
    22   inline void registerObject(T* object, NewObjectList<T>& objectList) { _id.registerObject(object, objectList); };
     22  inline void registerObject(T* object, ObjectList<T>& objectList) { _id.registerObject(object, objectList); };
    2323protected:
    24   NewClassID    _id;
     24  ClassID    _id;
    2525  std::string   _objectName;
    2626
    2727
    2828};
    29 NewObjectListDefinition(NewBaseObject);
     29ObjectListDefinition(NewBaseObject);
    3030
    3131
     
    4040
    4141
    42   NewObjectListDeclaration(Test);
     42  ObjectListDeclaration(Test);
    4343  //ObjectListDeclaration(Test);
    4444};
    45 NewObjectListDefinitionID(Test, -1);
     45ObjectListDefinitionID(Test, -1);
    4646
    4747Test::Test()
     
    7373    //  std::cout << "~Bone()\n";
    7474  };
    75   NewObjectListDeclaration(Bone);
     75  ObjectListDeclaration(Bone);
    7676};
    77 NewObjectListDefinitionID(Bone, -1);
     77ObjectListDefinitionID(Bone, -1);
    7878
    7979int main()
Note: See TracChangeset for help on using the changeset viewer.