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