1 | /*! |
---|
2 | * @file new_class_id.h |
---|
3 | * @brief Definition of a dynamically allocating ClassID |
---|
4 | * |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef _NEW_CLASS_ID_H |
---|
8 | #define _NEW_CLASS_ID_H |
---|
9 | |
---|
10 | #include "new_object_list.h" |
---|
11 | |
---|
12 | #include <string> |
---|
13 | #include <list> |
---|
14 | |
---|
15 | |
---|
16 | //! A class to dynamically allocate ClassID's and support a isA operator |
---|
17 | class NewClassID |
---|
18 | { |
---|
19 | public: |
---|
20 | NewClassID(); |
---|
21 | ~NewClassID(); |
---|
22 | |
---|
23 | int leafClassID() const { return _classes.front()._objectList->id(); } |
---|
24 | |
---|
25 | template<class T> void registerObject(T* object, NewObjectList<T>& list); |
---|
26 | bool isA(const NewObjectListBase& objectList) const; |
---|
27 | bool isA(int classID) const; |
---|
28 | bool isA(const std::string& className) const; |
---|
29 | |
---|
30 | void listInheritance() const; |
---|
31 | |
---|
32 | private: |
---|
33 | ////////////////////////////// |
---|
34 | //// Type Definition Part //// |
---|
35 | ////////////////////////////// |
---|
36 | //! A ClassEntry so we can store Classes inside of Objects |
---|
37 | struct ClassEntry |
---|
38 | { |
---|
39 | /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */ |
---|
40 | inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {} |
---|
41 | NewObjectListBase* _objectList; //!< A ObjectList this Object is part of |
---|
42 | NewObjectListBase::IteratorBase* _iterator; //!< An iterator pointing to the position of the Object inside of the List. |
---|
43 | }; |
---|
44 | typedef std::list<ClassEntry> ClassList; //!< Type definition for the List. |
---|
45 | |
---|
46 | ClassList _classes; //!< All Classes this object is part of. |
---|
47 | }; |
---|
48 | |
---|
49 | |
---|
50 | /** |
---|
51 | * @brief Registeres an Object of Type T to objectList |
---|
52 | * @param object The Object to append to the objectList. |
---|
53 | * @param objectList The ObjectList to append the Object to. |
---|
54 | * |
---|
55 | * This function is essential to integrate objects into their designated ObjectList. |
---|
56 | * Remember if you do not want objects to be stored in Lists (less overhead), |
---|
57 | * do not attempt to call this function. |
---|
58 | */ |
---|
59 | template<class T> |
---|
60 | inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList) |
---|
61 | { |
---|
62 | this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object))); |
---|
63 | } |
---|
64 | |
---|
65 | #endif /* _NEW_CLASS_ID_H */ |
---|