Changeset 9663 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Aug 20, 2006, 3:07:59 PM (18 years ago)
- Location:
- trunk/src/lib/lang
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/new_class_id.h
r9660 r9663 12 12 #include <string> 13 13 14 #include "new_object_list.h" 15 14 16 //! A class to dynamically allocate ClassID's and support a isA operator 15 17 class NewClassID … … 18 20 NewClassID(); 19 21 ~NewClassID(); 22 23 void registerObject(NewObjectListBase* object); 20 24 21 25 private: -
trunk/src/lib/lang/new_object_list.cc
r9662 r9663 25 25 if (NewObjectListBase::_classes == NULL) 26 26 NewObjectListBase::_classes = new cList; 27 assert(!NewObjectListBase:: exists(className) && "Classes should not be included once, and no two classes should have the same name (key value)");27 assert(!NewObjectListBase::classNameExists(className) && "Classes should not be included once, and no two classes should have the same name (key value)"); 28 28 29 this->_id = NewObjectListBase::_idCounter++; 29 30 30 31 … … 46 47 * @return true if such a class already exists. 47 48 */ 48 bool NewObjectListBase:: exists(const std::string& name)49 bool NewObjectListBase::classNameExists(const std::string& name) 49 50 { 50 51 cList::iterator it; -
trunk/src/lib/lang/new_object_list.h
r9662 r9663 10 10 #include "type_info.h" 11 11 #include <set> 12 #include <list> 12 13 #include <string> 13 14 14 #define DeclareClass(ClassName) \15 NewObjectList ClassID_##ClassName(ClassName)16 15 17 #define DeclareInClass(ClassName) \ 18 NewObjectList objectList(ClassName) 16 #define NewObjectListDeclaration(ClassName) \ 17 static NewObjectList<ClassName> objectList 18 19 #define NewObjectListDefinition(ClassName) \ 20 NewObjectList<ClassName> ClassName::objectList(#ClassName) 19 21 20 22 class NewObjectListBase … … 23 25 int id() const { return _id; }; 24 26 const std::string& name() const { return _name; }; 27 bool operator==(int id) const { return _id == id; }; 28 bool operator==(const std::string& name) const { return _name == name; }; 25 29 26 static int classCount() { return _idCounter; };27 30 31 /// Comparing operators. 28 32 bool compareName(const NewObjectListBase& more) { return this->_name < more.name(); }; 29 33 bool compareID(const NewObjectListBase& more) { return this->_id < more.id(); }; 34 35 36 static unsigned int classCount() { return _idCounter; }; 37 static const std::string& IDToString(int classID); 38 static int StringToID(const std::string& className); 39 40 static const std::list<std::string>& getClassNames(); 30 41 31 42 protected: 32 43 NewObjectListBase(const std::string& className); 33 44 ~NewObjectListBase(); 45 34 46 private: 35 47 NewObjectListBase(const NewObjectListBase&); 36 48 37 static bool exists(const std::string& className);49 static bool classNameExists(const std::string& className); 38 50 39 51 private: … … 46 58 static int _idCounter; //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe. 47 59 static cList* _classes; //!< A Set of all the classes in existance. 60 static std::list<std::string> _classNames; //!< A list of all the registered ClassNames. 48 61 }; 49 62 … … 52 65 //// TEMPLATISATION ///// 53 66 ///////////////////////// 67 //! Defines a ObjectsList handler for objects of type T. 68 /** 69 * @note The Class must define the compare with const std::string& operator for this to work. 70 */ 54 71 template<class T> class NewObjectList : public NewObjectListBase 55 72 { 73 public: 74 typedef std::list<T*> list; 75 typedef typename list::iterator iterator; 76 77 56 78 public: 57 79 NewObjectList(const std::string& name); 58 80 ~NewObjectList(); 59 81 82 T* getObject(const std::string& name) const; 83 inline const list& objects() const { return _objects; }; 84 85 60 86 private: 61 87 //! the copy constructor will be hidden. 62 88 NewObjectList(const NewObjectList& definer) {}; 89 90 list _objects; 63 91 }; 64 92 … … 70 98 template <class T> 71 99 NewObjectList<T>::~NewObjectList() 72 {} 100 { 101 assert(_objects.empty()); 102 } 73 103 104 template <class T> 105 T* NewObjectList<T>::getObject(const std::string& name) const 106 { 107 iterator it = std::find(this->_objects.begin(), this->_objects.end(), name); 108 if (it != this->_objects.end()) 109 return *it; 110 else 111 return NULL; 112 } 74 113 75 114 #endif /* _NEW_OBJECT_LIST_H */
Note: See TracChangeset
for help on using the changeset viewer.