| 1 | /*! |
|---|
| 2 | * @file class_list.h |
|---|
| 3 | * Definition of the Class List, that handles a Class-Specific-Control structure |
|---|
| 4 | |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #ifndef _CLASS_LIST_H |
|---|
| 8 | #define _CLASS_LIST_H |
|---|
| 9 | |
|---|
| 10 | #include "class_id.h" |
|---|
| 11 | #include <list> |
|---|
| 12 | #include <string> |
|---|
| 13 | #ifndef NULL |
|---|
| 14 | #define NULL 0 //!< NULL |
|---|
| 15 | #endif |
|---|
| 16 | |
|---|
| 17 | // FORWARD DECLARATION |
|---|
| 18 | class BaseObject; |
|---|
| 19 | |
|---|
| 20 | //! A class that handles Pointers to Objects of all type. |
|---|
| 21 | /** |
|---|
| 22 | * here all the Pointers to all the Object of orxonox are stored, that implement BaseObject |
|---|
| 23 | * for now. |
|---|
| 24 | * You can get Any Object's Reference to BaseObject with dynamic_cast<T>(ClassList::getObject(name, CL_T_NAME)); |
|---|
| 25 | * where: T: is the Class to cast to, |
|---|
| 26 | * name: the name of the Object (not className) |
|---|
| 27 | * CL_T_NAME: the class Identifier, (if CL_NULL or nothing it will take longer, because all BaseObject's are searched through) |
|---|
| 28 | * |
|---|
| 29 | * There is also the exists-function, that just checks, if a Reference is still in existence. |
|---|
| 30 | * |
|---|
| 31 | * @see ClassID, BaseObject, dynamic_cast |
|---|
| 32 | */ |
|---|
| 33 | class ClassList { |
|---|
| 34 | public: |
|---|
| 35 | ClassList(ClassID classID, unsigned long classIDFull, const std::string& className); |
|---|
| 36 | virtual ~ClassList(); |
|---|
| 37 | |
|---|
| 38 | /* MAINTENANCE FUNCTIONS THESE ARE !!ONLY FOR BASEOBJECT !! */ |
|---|
| 39 | static ClassList* addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const std::string& className); |
|---|
| 40 | static void removeFromClassList(BaseObject* objectPointer); |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | static const std::list<BaseObject*>* getList(ClassID classID = CL_NULL);// { return (ClassList* fl = ClassList::getClassList(classID) != NULL)? &(fl->objectList) : NULL; }; |
|---|
| 45 | static const std::list<BaseObject*>* getList(const std::string& className); // { return (ClassList* fl = ClassList::getClassList(className) != NULL)? &(fl->objectList) : NULL; }; |
|---|
| 46 | static const std::list<std::string>* getClassNames(); |
|---|
| 47 | static BaseObject* getObject(const std::string& name, ClassID classID = CL_NULL); |
|---|
| 48 | static bool exists(const BaseObject* object, ClassID classID = CL_NULL); |
|---|
| 49 | static bool exists(const std::string& className, const std::string& objectName); |
|---|
| 50 | |
|---|
| 51 | void sendBack(std::list<BaseObject*>::const_iterator it); |
|---|
| 52 | |
|---|
| 53 | static void whatIs(const BaseObject* object); |
|---|
| 54 | |
|---|
| 55 | static const std::string& IDToString(ClassID classID = CL_NULL); |
|---|
| 56 | static ClassID StringToID(const std::string& className); |
|---|
| 57 | static void debug(unsigned int debugLevel = 0, ClassID classID = CL_NULL); |
|---|
| 58 | static void debugS(const std::string& className = "", unsigned int debugLevel = 0); |
|---|
| 59 | |
|---|
| 60 | inline bool operator==(ClassID classID) { return (this->classID == classID); }; |
|---|
| 61 | bool operator==(const std::string& className); |
|---|
| 62 | inline ClassID getLeafClassID() const { return this->classID; }; |
|---|
| 63 | |
|---|
| 64 | private: |
|---|
| 65 | static ClassList* getClassList(ClassID classID); |
|---|
| 66 | static ClassList* getClassList(const std::string& className); |
|---|
| 67 | |
|---|
| 68 | private: |
|---|
| 69 | ClassID classID; //!< ClassID stored in this ClassList |
|---|
| 70 | unsigned long classIDFull; //!< The Full ClassID of this Class. |
|---|
| 71 | |
|---|
| 72 | const std::string className; //!< Name of the Class Stored here |
|---|
| 73 | |
|---|
| 74 | std::list<BaseObject*> objectList; //!< A list of Objects belonging to this Class |
|---|
| 75 | |
|---|
| 76 | // STATIC MEMBERS |
|---|
| 77 | static std::list<ClassList>* classList; //!< The first Class in the List |
|---|
| 78 | static std::list<std::string> classNames; //!< a List of all Names of all classes, that have registered so far. |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | #endif /* _CLASS_LIST_H */ |
|---|