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