Changeset 9715 in orxonox.OLD for branches/new_class_id/src/lib/lang
- Timestamp:
- Sep 1, 2006, 8:06:39 PM (18 years ago)
- 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 21 21 #include "util/loading/load_param.h" 22 22 23 NewObjectListDefinition(BaseObject);23 ObjectListDefinition(BaseObject); 24 24 25 25 /** … … 43 43 BaseObject::~BaseObject () 44 44 { 45 /// Remove from the NewObjectLists45 /// Remove from the ObjectLists 46 46 ClassList::iterator it; 47 47 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) … … 89 89 * @return True if found, false if not. 90 90 */ 91 bool BaseObject::isA(const NewObjectListBase& objectList) const91 bool BaseObject::isA(const ObjectListBase& objectList) const 92 92 { 93 93 ClassList::const_iterator it; … … 104 104 * @return True if found, false if not. 105 105 */ 106 bool BaseObject::isA(const NewClassID& classID) const106 bool BaseObject::isA(const ClassID& classID) const 107 107 { 108 108 ClassList::const_iterator it; -
branches/new_class_id/src/lib/lang/base_object.h
r9709 r9715 26 26 class BaseObject : public sigslot::has_slots<> 27 27 { 28 NewObjectListDeclaration(BaseObject);28 ObjectListDeclaration(BaseObject); 29 29 public: 30 30 BaseObject (const std::string& objectName = ""); … … 48 48 inline const std::string& getClassName() const { return _classes.front()._objectList->name(); }; 49 49 50 inline const NewClassID& getClassID() const { return *_leafClassID; }50 inline const ClassID& getClassID() const { return *_leafClassID; } 51 51 /** @returns the ID of the Topmost object of the ClassStack */ 52 52 inline const int& getLeafClassID() const { return _leafClassID->id(); } 53 53 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; 56 56 bool isA(int classID) const; 57 57 bool isA(const std::string& className) const; … … 65 65 66 66 protected: 67 template<class T> void registerObject(T* object, NewObjectList<T>& list);67 template<class T> void registerObject(T* object, ObjectList<T>& list); 68 68 69 69 protected: … … 80 80 struct ClassEntry 81 81 { 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 of85 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. 86 86 }; 87 87 typedef std::list<ClassEntry> ClassList; //!< Type definition for the List. … … 89 89 std::string className; //!< the name of the class 90 90 ClassList _classes; //!< All Classes this object is part of. 91 const NewClassID* _leafClassID; //!< Topmost ClassID.91 const ClassID* _leafClassID; //!< Topmost ClassID. 92 92 }; 93 93 … … 103 103 */ 104 104 template<class T> 105 inline void BaseObject::registerObject(T* object, NewObjectList<T>& objectList)105 inline void BaseObject::registerObject(T* object, ObjectList<T>& objectList) 106 106 { 107 107 this->_leafClassID = &objectList.identity(); -
branches/new_class_id/src/lib/lang/new_class_id.cc
r9709 r9715 23 23 * this Always points to the ID of the NullClass. 24 24 */ 25 NewClassID::NewClassID()25 ClassID::ClassID() 26 26 { 27 27 NullClass::acquireID(this->_id, this->_name); … … 30 30 /** 31 31 * @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. 33 33 */ 34 NewClassID::NewClassID(const NewObjectListBase* const objList)34 ClassID::ClassID(const ObjectListBase* const objList) 35 35 { 36 36 objList->acquireID(this->_id, this->_name); … … 38 38 39 39 40 NewClassID NullClass::_classID;40 ClassID NullClass::_classID; 41 41 42 42 int NullClass::_nullID; -
branches/new_class_id/src/lib/lang/new_class_id.h
r9709 r9715 10 10 #include <string> 11 11 12 class NewObjectListBase;12 class ObjectListBase; 13 13 14 14 //! A class to dynamically allocate ClassID's and to support a isA operator 15 15 /** 16 * A NewClassID can only be aquired over a NewObjectList,16 * A ClassID can only be aquired over a ObjectList, 17 17 * thus enabling the developer to have permanent access to the correct ID and ClassName 18 18 * 19 * The Idea behind this concept is, that storing a NewClassID that changes its internal state20 * 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. 21 21 * 22 * Since the Existance of any NewObjectList is a requirement during the working process all22 * Since the Existance of any ObjectList is a requirement during the working process all 23 23 * ID's should reference a valid ID and ClassName 24 24 */ 25 class NewClassID25 class ClassID 26 26 { 27 27 public: 28 NewClassID();29 NewClassID(const NewObjectListBase* const id);28 ClassID(); 29 ClassID(const ObjectListBase* const id); 30 30 /// the copy constructor is also defined implicitely. 31 31 … … 36 36 37 37 /** @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 */; }; 39 39 /** @param id the id to compare @returns true on match (match is same ID) @brief compares two id's */ 40 40 bool operator==(int id) const { return *_id == id; }; … … 42 42 bool operator==(const std::string& name) const { return *_name == name; }; 43 43 /** @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*/; }; 45 45 /** @param id the id to compare @returns false on match (match is same ID) @brief compares two id's */ 46 46 bool operator!=(int id) const { return *_id != id; }; … … 61 61 public: 62 62 /** @returns the NullClass' ID. */ 63 static const NewClassID& classID() { return NullClass::_classID; }63 static const ClassID& classID() { return NullClass::_classID; } 64 64 /** @param id the ID to acquire @param name the name to acquire @brief acquires the ID of this Class */ 65 65 static void acquireID(const int*& id, const std::string*& name) { id = &_nullID; name = &_nullName; }; … … 69 69 70 70 private: 71 static NewClassID _classID; //!< The NullClass' ID71 static ClassID _classID; //!< The NullClass' ID 72 72 static const std::string _nullName; //!< The NullClass' Name ("NullClass") 73 73 static int _nullID; //!< The NullClass' ID -
branches/new_class_id/src/lib/lang/new_object_list.cc
r9709 r9715 28 28 * @return a new NewObejctList 29 29 */ 30 NewObjectListBase::NewObjectListBase(const std::string& className, int id)30 ObjectListBase::ObjectListBase(const std::string& className, int id) 31 31 : _name(className) 32 32 { 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)"); 41 41 42 42 if (id == -1) 43 43 { 44 id = NewObjectListBase::_classesByID->size();44 id = ObjectListBase::_classesByID->size(); 45 45 // 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)"); 49 49 50 50 _id = id; … … 52 52 std::cout << "register new ObjectList " << className << " ID: " << this->_id << std::endl; 53 53 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; 57 57 } 58 58 … … 61 61 * Destructor. 62 62 * 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 */ 65 ObjectListBase::~ObjectListBase() 66 { 67 assert (ObjectListBase::_classesByName != NULL && ObjectListBase::_classesByID != NULL); 68 68 /* 69 69 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; 72 72 */ 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 86 ObjectListBase::classIDMap* ObjectListBase::_classesByID = NULL; 87 ObjectListBase::classNameMap* ObjectListBase::_classesByName = NULL; 88 88 89 89 /** 90 90 * @returns the Registered Class Count. 91 91 */ 92 unsigned int NewObjectListBase::classCount()93 { 94 assert ( NewObjectListBase::_classesByID != NULL);95 return NewObjectListBase::_classesByID->size();92 unsigned int ObjectListBase::classCount() 93 { 94 assert (ObjectListBase::_classesByID != NULL); 95 return ObjectListBase::_classesByID->size(); 96 96 }; 97 97 … … 101 101 * @return true if such a class already exists. 102 102 */ 103 bool NewObjectListBase::classIDExists(int id)104 { 105 return ( NewObjectListBase::_classesByID->find(id) != NewObjectListBase::_classesByID->end());103 bool ObjectListBase::classIDExists(int id) 104 { 105 return (ObjectListBase::_classesByID->find(id) != ObjectListBase::_classesByID->end()); 106 106 } 107 107 … … 111 111 * @return true if such a class already exists. 112 112 */ 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 Identity113 bool 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 120 120 * @param id: The Id to search for 121 121 * @returns the ClassID if found and NullClass' identity if not. 122 122 */ 123 const NewClassID& NewObjectListBase::retrieveIdentity(int id)124 { 125 const NewObjectListBase* const base = NewObjectListBase::getObjectList(id);123 const ClassID& ObjectListBase::retrieveIdentity(int id) 124 { 125 const ObjectListBase* const base = ObjectListBase::getObjectList(id); 126 126 127 127 if (base != NULL) … … 133 133 134 134 /** 135 * @brief searches for a NewClassID in the list of all NewObjectLists, and returns its Identity135 * @brief searches for a ClassID in the list of all ObjectLists, and returns its Identity 136 136 * @param name: The Name to search for 137 137 * @returns the ClassID if found and NullClass' identity if not. 138 138 */ 139 const NewClassID& NewObjectListBase::retrieveIdentity(const std::string& name)140 { 141 const NewObjectListBase* const base = NewObjectListBase::getObjectList(name);139 const ClassID& ObjectListBase::retrieveIdentity(const std::string& name) 140 { 141 const ObjectListBase* const base = ObjectListBase::getObjectList(name); 142 142 143 143 if (base != NULL) … … 151 151 * @brief Searches for a ObjectList with the ID classID 152 152 * @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 */ 155 const 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()) 160 160 return (*it).second; 161 161 else … … 166 166 * @brief Searches for a ObjectList with the Name className 167 167 * @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 */ 170 const 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()) 175 175 return (*it).second; 176 176 else … … 179 179 180 180 /** 181 * @brief Searches for a ObjectList with the NewClassID classID181 * @brief Searches for a ObjectList with the ClassID classID 182 182 * @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 */ 185 const ObjectListBase* const ObjectListBase::getObjectList(const ClassID& classID) 186 { 187 return ObjectListBase::getObjectList(classID.id()); 188 188 } 189 189 … … 193 193 * @param objectName the Name of the Object to search for 194 194 */ 195 BaseObject* NewObjectListBase::getBaseObject(int classID, const std::string& objectName)196 { 197 const NewObjectListBase* const base = NewObjectListBase::getObjectList(classID);195 BaseObject* ObjectListBase::getBaseObject(int classID, const std::string& objectName) 196 { 197 const ObjectListBase* const base = ObjectListBase::getObjectList(classID); 198 198 199 199 if (base != NULL) … … 208 208 * @param objectName the Name of the Object to search for 209 209 */ 210 BaseObject* NewObjectListBase::getBaseObject(const std::string& className, const std::string& objectName)211 { 212 const NewObjectListBase* const base = NewObjectListBase::getObjectList(className);210 BaseObject* ObjectListBase::getBaseObject(const std::string& className, const std::string& objectName) 211 { 212 const ObjectListBase* const base = ObjectListBase::getObjectList(className); 213 213 214 214 if (base != NULL) … … 220 220 /** 221 221 * @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. 223 223 * @param objectName the Name of the Object to search for 224 224 */ 225 BaseObject* NewObjectListBase::getBaseObject(const NewClassID& classID, const std::string& objectName)226 { 227 const NewObjectListBase* const base = NewObjectListBase::getObjectList(classID);225 BaseObject* ObjectListBase::getBaseObject(const ClassID& classID, const std::string& objectName) 226 { 227 const ObjectListBase* const base = ObjectListBase::getObjectList(classID); 228 228 229 229 if (base != NULL) … … 238 238 * @brief Prints out some debugging information about a given List. 239 239 */ 240 void NewObjectListBase::debug(unsigned int level) const240 void ObjectListBase::debug(unsigned int level) const 241 241 { 242 242 base_list list; … … 259 259 260 260 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();261 void 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(); 267 267 ++it) 268 268 { … … 280 280 * @return The ClassName or an empty string if the ID was not found. 281 281 */ 282 const std::string& NewObjectListBase::IDToString(int classID)283 { 284 const NewObjectListBase* const base = NewObjectListBase::getObjectList(classID);282 const std::string& ObjectListBase::IDToString(int classID) 283 { 284 const ObjectListBase* const base = ObjectListBase::getObjectList(classID); 285 285 286 286 if (base != NULL) … … 299 299 * @return The Classes ID if found, -1 otherwise. 300 300 */ 301 int NewObjectListBase::StringToID(const std::string& className)302 { 303 const NewObjectListBase* const base = NewObjectListBase::getObjectList(className);301 int ObjectListBase::StringToID(const std::string& className) 302 { 303 const ObjectListBase* const base = ObjectListBase::getObjectList(className); 304 304 305 305 if (base != NULL) -
branches/new_class_id/src/lib/lang/new_object_list.h
r9713 r9715 21 21 * two new functions objectList() and classID(). 22 22 */ 23 #define NewObjectListDeclaration(ClassName) \23 #define ObjectListDeclaration(ClassName) \ 24 24 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(); }; \ 27 27 private: \ 28 static NewObjectList<ClassName> _objectList29 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) 36 36 37 37 class BaseObject; 38 //! The superclass that all NewObjectLists follow.39 /** 40 * @see template<class T> NewObjectList<T>41 */ 42 class NewObjectListBase38 //! The superclass that all ObjectLists follow. 39 /** 40 * @see template<class T> ObjectList<T> 41 */ 42 class ObjectListBase 43 43 { 44 44 public: … … 56 56 public: 57 57 /** @returns The Identity of the Class stored within. */ 58 inline const NewClassID& identity() const { return _identity; }58 inline const ClassID& identity() const { return _identity; } 59 59 /** @returns the ID of the Identity of the ObjectList */ 60 60 inline int id() const { return _id; }; … … 64 64 inline bool operator==(int id) const { return _id == id; }; 65 65 /** @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; }; 67 67 /** @param name The name to compare @returns true on match, false otherwise */ 68 68 inline bool operator==(const std::string& name) const { return _name == name; }; … … 72 72 virtual void getBaseObjectList(base_list* list) const = 0; 73 73 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); 80 80 81 81 static BaseObject* getBaseObject(int classID, const std::string& objectName); 82 82 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); 84 84 85 85 /** @returns an Object with Name name out of this List @param name the name of the Object. */ … … 100 100 101 101 protected: 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 105 private: 106 ObjectListBase(const ObjectListBase&); 107 107 108 108 static bool classIDExists(int id); … … 111 111 112 112 protected: 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. 115 115 116 116 private: 117 117 int _id; 118 118 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) 120 120 121 121 private: … … 135 135 * as with normal std::list. 136 136 * 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. 138 138 * 139 139 * … … 141 141 * 142 142 * 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) 145 145 * 3. In the constructor add 'registerObject(this, objectList);' 146 146 * … … 154 154 * 155 155 * @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(); 157 157 * it != PlayerStats::objectList().end(); 158 158 * ++it) … … 166 166 */ 167 167 template<class T> 168 class NewObjectList : public NewObjectListBase168 class ObjectList : public ObjectListBase 169 169 { 170 170 public: … … 174 174 175 175 176 class Iterator : public NewObjectListBase::IteratorBase176 class Iterator : public ObjectListBase::IteratorBase 177 177 { 178 178 public: 179 179 Iterator(iterator it) { _it = it; } 180 180 inline iterator& it() { return _it; } 181 typename NewObjectList::iterator _it;181 typename ObjectList::iterator _it; 182 182 }; 183 183 184 184 public: 185 NewObjectList(const std::string& name, int id = -1);186 ~ NewObjectList();185 ObjectList(const std::string& name, int id = -1); 186 ~ObjectList(); 187 187 188 188 virtual BaseObject* getBaseObject(const std::string& name) const; … … 210 210 211 211 212 NewObjectListBase::IteratorBase* registerObject(T* object);212 ObjectListBase::IteratorBase* registerObject(T* object); 213 213 virtual void unregisterObject(IteratorBase* iterator); 214 214 215 215 protected: 216 virtual void getBaseObjectList( NewObjectListBase::base_list* list) const;216 virtual void getBaseObjectList(ObjectListBase::base_list* list) const; 217 217 218 218 219 219 private: 220 220 //! the copy constructor will be hidden. 221 NewObjectList(const NewObjectList& definer) {};221 ObjectList(const ObjectList& definer) {}; 222 222 223 223 private: … … 233 233 ///////////////////////// 234 234 /** 235 * @brief creates a new NewObjectList235 * @brief creates a new ObjectList 236 236 * @param name The name of the Class. 237 237 * @param id The ID of the class if desired, or -1 if an id should be assigned automatically. 238 238 */ 239 239 template <class T> 240 NewObjectList<T>::NewObjectList(const std::string& name, int id)241 : NewObjectListBase(name, id)240 ObjectList<T>::ObjectList(const std::string& name, int id) 241 : ObjectListBase(name, id) 242 242 {} 243 243 244 244 /** 245 * @brief deletes the NewObjectList.246 */ 247 template <class T> 248 NewObjectList<T>::~NewObjectList()245 * @brief deletes the ObjectList. 246 */ 247 template <class T> 248 ObjectList<T>::~ObjectList() 249 249 { 250 250 if (!_objects.empty()) … … 260 260 */ 261 261 template <class T> 262 BaseObject* NewObjectList<T>::getBaseObject(const std::string& name) const262 BaseObject* ObjectList<T>::getBaseObject(const std::string& name) const 263 263 { 264 264 return this->getObject(name); … … 273 273 */ 274 274 template <class T> 275 T* NewObjectList<T>::getObject(const std::string& name) const275 T* ObjectList<T>::getObject(const std::string& name) const 276 276 { 277 277 const_iterator it; … … 288 288 */ 289 289 template <class T> 290 bool NewObjectList<T>::exists(const T* const object) const290 bool ObjectList<T>::exists(const T* const object) const 291 291 { 292 292 return (std::find(_objects.begin(), _objects.end(), object) != _objects.end()); … … 299 299 */ 300 300 template <class T> 301 void NewObjectList<T>::getBaseObjectList(NewObjectListBase::base_list* list) const301 void ObjectList<T>::getBaseObjectList(ObjectListBase::base_list* list) const 302 302 { 303 303 assert (list != NULL); … … 309 309 310 310 /** 311 * @brief registers an Object to the NewObjectList.311 * @brief registers an Object to the ObjectList. 312 312 * @param T object the Object to register. 313 313 * @returns a pointer to the iterator inside of the list. 314 314 */ 315 315 template <class T> 316 NewObjectListBase::IteratorBase* NewObjectList<T>::registerObject(T* object)316 ObjectListBase::IteratorBase* ObjectList<T>::registerObject(T* object) 317 317 { 318 318 this->_objects.push_back(object); … … 325 325 */ 326 326 template <class T> 327 void NewObjectList<T>::unregisterObject(IteratorBase* iterator)327 void ObjectList<T>::unregisterObject(IteratorBase* iterator) 328 328 { 329 329 this->_objects.erase(static_cast<Iterator*>(iterator)->it()); -
branches/new_class_id/src/lib/lang/test_object_list.cc
r9682 r9715 12 12 // bool operator==(const std::string& name) const { return _objectName == name; }; 13 13 14 NewObjectListDeclaration(NewBaseObject);14 ObjectListDeclaration(NewBaseObject); 15 15 16 16 protected: … … 20 20 }; 21 21 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); }; 23 23 protected: 24 NewClassID _id;24 ClassID _id; 25 25 std::string _objectName; 26 26 27 27 28 28 }; 29 NewObjectListDefinition(NewBaseObject);29 ObjectListDefinition(NewBaseObject); 30 30 31 31 … … 40 40 41 41 42 NewObjectListDeclaration(Test);42 ObjectListDeclaration(Test); 43 43 //ObjectListDeclaration(Test); 44 44 }; 45 NewObjectListDefinitionID(Test, -1);45 ObjectListDefinitionID(Test, -1); 46 46 47 47 Test::Test() … … 73 73 // std::cout << "~Bone()\n"; 74 74 }; 75 NewObjectListDeclaration(Bone);75 ObjectListDeclaration(Bone); 76 76 }; 77 NewObjectListDefinitionID(Bone, -1);77 ObjectListDefinitionID(Bone, -1); 78 78 79 79 int main()
Note: See TracChangeset
for help on using the changeset viewer.