Changeset 9660 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Aug 20, 2006, 11:50:41 AM (18 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/Makefile.am
r9659 r9660 8 8 lang/class_list.cc \ 9 9 lang/new_class_id.cc \ 10 lang/new_class_list.cc \ 10 11 \ 11 12 coord/p_node.cc \ … … 16 17 lang/base_object.h \ 17 18 lang/class_list.h \ 19 lang/new_class_id.h \ 20 lang/new_class_list.h \ 18 21 \ 19 22 coord/p_node.h \ -
trunk/src/lib/lang/new_class_id.cc
r9659 r9660 19 19 #include <cassert> 20 20 21 ClassIDDeclaration::ClassIDDeclaration(const std::string& name)22 : _id(-1), _name(name)23 {24 NewClassID::registerClass(this);25 }26 27 ClassIDDeclaration::~ClassIDDeclaration()28 {29 NewClassID::unregisterClass(this);30 }31 32 33 34 21 /////////////////////////////////////////////////////////// 35 22 //// CLASS ID definiton. ////////////////////////////////// … … 39 26 */ 40 27 NewClassID::NewClassID () 41 : _className("") 42 { 43 } 28 : _className("") 29 {} 44 30 45 31 … … 53 39 54 40 55 int NewClassID::_idCounter = 0;56 57 //! TODO make access to the idCounter ThreadSafe!58 void NewClassID::registerClass(ClassIDDeclaration* namer)59 {60 assert (namer->id() != -1 && "Do not register any ClassID's for yourself.");61 62 namer->_id = NewClassID::_idCounter++;63 }64 65 void NewClassID::unregisterClass(ClassIDDeclaration* namer)66 {67 // here nothing is done, because Classes cannot be realigned fast.68 } -
trunk/src/lib/lang/new_class_id.h
r9659 r9660 12 12 #include <string> 13 13 14 #define DeclareClass(ClassName) \15 ClassIDDeclaration ClassID_##ClassName(ClassName)16 17 class ClassIDDeclaration18 {19 friend class NewClassID;20 public:21 ClassIDDeclaration(const std::string& name);22 ~ClassIDDeclaration();23 24 int id() const { return _id; };25 const std::string& name() const { return _name; };26 27 private:28 //! the copy constructor will be hidden.29 ClassIDDeclaration(const ClassIDDeclaration& definer) {};30 31 private:32 int _id;33 std::string _name;34 };35 36 37 14 //! A class to dynamically allocate ClassID's and support a isA operator 38 15 class NewClassID … … 42 19 ~NewClassID(); 43 20 44 45 46 static int classCount() { return _idCounter; };47 static void registerClass(ClassIDDeclaration* namer);48 static void unregisterClass(ClassIDDeclaration* namer);49 50 21 private: 51 std::set<ClassIDDeclaration> _types;52 22 std::string _className; 53 23 54 static int _idCounter; //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe.55 24 }; 56 25 -
trunk/src/lib/lang/new_class_list.cc
r9659 r9660 16 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 17 17 18 #include "new_class_ id.h"18 #include "new_class_list.h" 19 19 #include <cassert> 20 20 21 ClassIDDeclaration::ClassIDDeclaration(const std::string& name) 22 : _id(-1), _name(name) 21 22 NewClassListBase::NewClassListBase(const std::string& className) 23 : _id(-1), _name(className) 23 24 { 24 NewClassID::registerClass(this); 25 25 26 } 26 27 ClassIDDeclaration::~ClassIDDeclaration()28 {29 NewClassID::unregisterClass(this);30 }31 32 33 34 ///////////////////////////////////////////////////////////35 //// CLASS ID definiton. //////////////////////////////////36 ///////////////////////////////////////////////////////////37 /**38 * @brief standard constructor39 */40 NewClassID::NewClassID ()41 : _className("")42 {43 }44 45 46 /**47 * @brief standard deconstructor48 */49 NewClassID::~NewClassID ()50 {51 // delete what has to be deleted here52 }53 54 55 int NewClassID::_idCounter = 0;56 57 //! TODO make access to the idCounter ThreadSafe!58 void NewClassID::registerClass(ClassIDDeclaration* namer)59 {60 assert (namer->id() != -1 && "Do not register any ClassID's for yourself.");61 62 namer->_id = NewClassID::_idCounter++;63 }64 65 void NewClassID::unregisterClass(ClassIDDeclaration* namer)66 {67 // here nothing is done, because Classes cannot be realigned fast.68 } -
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.