Changeset 9660 in orxonox.OLD for trunk/src/lib/lang/new_class_list.h
- Timestamp:
- Aug 20, 2006, 11:50:41 AM (18 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/new_class_list.h
r9659 r9660 1 1 /*! 2 * @file new_class_ id.h2 * @file new_class_list.h 3 3 * @brief Definition of a dynamically allocating ClassID 4 4 * 5 5 */ 6 6 7 #ifndef _NEW_CLASS_ ID_H8 #define _NEW_CLASS_ ID_H7 #ifndef _NEW_CLASS_LIST_H 8 #define _NEW_CLASS_LIST_H 9 9 10 10 #include "type_info.h" … … 13 13 14 14 #define DeclareClass(ClassName) \ 15 ClassIDDeclarationClassID_##ClassName(ClassName)15 NewClassList ClassID_##ClassName(ClassName) 16 16 17 class ClassIDDeclaration 17 #define DeclareInClass(ClassName) \ 18 NewClassList classList(ClassName) 19 20 class NewClassListBase 18 21 { 19 friend class NewClassID;20 22 public: 21 ClassIDDeclaration(const std::string& name);22 ~ClassIDDeclaration();23 24 23 int id() const { return _id; }; 25 24 const std::string& name() const { return _name; }; 26 25 26 static int classCount() { return _idCounter; }; 27 28 protected: 29 NewClassListBase(const std::string& className); 30 private: 31 NewClassListBase(const NewClassListBase&); 32 33 34 private: 35 int _id; 36 std::string _name; 37 38 private: 39 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. 41 }; 42 43 template<class T> class NewClassList : public NewClassListBase 44 { 45 public: 46 NewClassList(const std::string& name); 47 ~NewClassList(); 48 27 49 private: 28 50 //! the copy constructor will be hidden. 29 ClassIDDeclaration(const ClassIDDeclaration& definer) {}; 30 31 private: 32 int _id; 33 std::string _name; 51 NewClassList(const NewClassList& definer) {}; 34 52 }; 35 53 54 template <class T> 55 NewClassList<T>::NewClassList(const std::string& name) 56 : NewClassListBase(name) 57 {} 36 58 37 //! A class to dynamically allocate ClassID's and support a isA operator 38 class NewClassID 39 { 40 public: 41 NewClassID(); 42 ~NewClassID(); 59 template <class T> 60 NewClassList<T>::~NewClassList() 61 {} 43 62 44 63 45 46 static int classCount() { return _idCounter; }; 47 static void registerClass(ClassIDDeclaration* namer); 48 static void unregisterClass(ClassIDDeclaration* namer); 49 50 private: 51 std::set<ClassIDDeclaration> _types; 52 std::string _className; 53 54 static int _idCounter; //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe. 55 }; 56 57 58 #endif /* _NEW_CLASS_ID_H */ 64 #endif /* _NEW_CLASS_LIST_H */
Note: See TracChangeset
for help on using the changeset viewer.