1 | /*! |
---|
2 | * @file new_class_list.h |
---|
3 | * @brief Definition of a dynamically allocating ClassID |
---|
4 | * |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef _NEW_CLASS_LIST_H |
---|
8 | #define _NEW_CLASS_LIST_H |
---|
9 | |
---|
10 | #include "type_info.h" |
---|
11 | #include <set> |
---|
12 | #include <string> |
---|
13 | |
---|
14 | #define DeclareClass(ClassName) \ |
---|
15 | NewObjectList ClassID_##ClassName(ClassName) |
---|
16 | |
---|
17 | #define DeclareInClass(ClassName) \ |
---|
18 | NewObjectList classList(ClassName) |
---|
19 | |
---|
20 | class NewObjectListBase |
---|
21 | { |
---|
22 | public: |
---|
23 | int id() const { return _id; }; |
---|
24 | const std::string& name() const { return _name; }; |
---|
25 | |
---|
26 | static int classCount() { return _idCounter; }; |
---|
27 | |
---|
28 | bool compareName(const NewObjectListBase& more) { return this->_name < more.name(); }; |
---|
29 | bool compareID(const NewObjectListBase& more) { return this->_id < more.id(); }; |
---|
30 | |
---|
31 | protected: |
---|
32 | NewObjectListBase(const std::string& className); |
---|
33 | ~NewObjectListBase(); |
---|
34 | private: |
---|
35 | NewObjectListBase(const NewObjectListBase&); |
---|
36 | |
---|
37 | static bool exists(const std::string& className); |
---|
38 | |
---|
39 | private: |
---|
40 | int _id; |
---|
41 | std::string _name; |
---|
42 | |
---|
43 | private: |
---|
44 | typedef std::set<NewObjectListBase*> cList; |
---|
45 | |
---|
46 | static int _idCounter; //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe. |
---|
47 | static cList* _classes; //!< A Set of all the classes in existance. |
---|
48 | }; |
---|
49 | |
---|
50 | |
---|
51 | ///////////////////////// |
---|
52 | //// TEMPLATISATION ///// |
---|
53 | ///////////////////////// |
---|
54 | template<class T> class NewObjectList : public NewObjectListBase |
---|
55 | { |
---|
56 | public: |
---|
57 | NewObjectList(const std::string& name); |
---|
58 | ~NewObjectList(); |
---|
59 | |
---|
60 | private: |
---|
61 | //! the copy constructor will be hidden. |
---|
62 | NewObjectList(const NewObjectList& definer) {}; |
---|
63 | }; |
---|
64 | |
---|
65 | template <class T> |
---|
66 | NewObjectList<T>::NewObjectList(const std::string& name) |
---|
67 | : NewObjectListBase(name) |
---|
68 | {} |
---|
69 | |
---|
70 | template <class T> |
---|
71 | NewObjectList<T>::~NewObjectList() |
---|
72 | {} |
---|
73 | |
---|
74 | |
---|
75 | #endif /* _NEW_CLASS_LIST_H */ |
---|