- Timestamp:
- Aug 20, 2006, 12:21:18 PM (18 years ago)
- Location:
- trunk/src/lib/lang
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/new_class_list.cc
r9660 r9661 20 20 21 21 22 NewClassListBase::NewClassListBase(const std::string& className) 23 : _id(-1), _name(className) 22 NewObjectListBase::NewObjectListBase(const std::string& className) 23 : _id(-1), _name(className) 24 { 25 if (NewObjectListBase::_classes == NULL) 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)"); 28 29 30 31 } 32 33 NewObjectListBase::~NewObjectListBase() 24 34 { 25 35 26 36 } 37 38 int NewObjectListBase::_idCounter = 0; 39 NewObjectListBase::cList* NewObjectListBase::_classes = NULL; 40 41 42 43 /** 44 * @brief Checks if a Class with name already exists. 45 * @param name The Name of the Class to check. 46 * @return true if such a class already exists. 47 */ 48 bool NewObjectListBase::exists(const std::string& name) 49 { 50 cList::iterator it; 51 for (it = NewObjectListBase::_classes->begin(); it != NewObjectListBase::_classes->end(); it++) 52 if(*it != NULL && (*it)->name() != name) 53 return true; 54 return false; 55 } -
trunk/src/lib/lang/new_class_list.h
r9660 r9661 13 13 14 14 #define DeclareClass(ClassName) \ 15 New ClassList ClassID_##ClassName(ClassName)15 NewObjectList ClassID_##ClassName(ClassName) 16 16 17 17 #define DeclareInClass(ClassName) \ 18 New ClassList classList(ClassName)18 NewObjectList classList(ClassName) 19 19 20 class New ClassListBase20 class NewObjectListBase 21 21 { 22 22 public: … … 26 26 static int classCount() { return _idCounter; }; 27 27 28 bool compareName(const NewObjectListBase& more) { return this->_name < more.name(); }; 29 bool compareID(const NewObjectListBase& more) { return this->_id < more.id(); }; 30 28 31 protected: 29 NewClassListBase(const std::string& className); 32 NewObjectListBase(const std::string& className); 33 ~NewObjectListBase(); 30 34 private: 31 New ClassListBase(const NewClassListBase&);35 NewObjectListBase(const NewObjectListBase&); 32 36 37 static bool exists(const std::string& className); 33 38 34 39 private: … … 37 42 38 43 private: 44 typedef std::set<NewObjectListBase*> cList; 45 39 46 static int _idCounter; //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe. 40 static std::set<NewClassListBase>_classes; //!< A Set of all the classes in existance.47 static cList* _classes; //!< A Set of all the classes in existance. 41 48 }; 42 49 43 template<class T> class NewClassList : public NewClassListBase 50 51 ///////////////////////// 52 //// TEMPLATISATION ///// 53 ///////////////////////// 54 template<class T> class NewObjectList : public NewObjectListBase 44 55 { 45 56 public: 46 New ClassList(const std::string& name);47 ~New ClassList();57 NewObjectList(const std::string& name); 58 ~NewObjectList(); 48 59 49 60 private: 50 61 //! the copy constructor will be hidden. 51 New ClassList(const NewClassList& definer) {};62 NewObjectList(const NewObjectList& definer) {}; 52 63 }; 53 64 54 65 template <class T> 55 New ClassList<T>::NewClassList(const std::string& name)56 : New ClassListBase(name)66 NewObjectList<T>::NewObjectList(const std::string& name) 67 : NewObjectListBase(name) 57 68 {} 58 69 59 70 template <class T> 60 New ClassList<T>::~NewClassList()71 NewObjectList<T>::~NewObjectList() 61 72 {} 62 73
Note: See TracChangeset
for help on using the changeset viewer.