Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/lib/lang/class_list.h @ 6591

Last change on this file since 6591 was 6280, checked in by bensch, 19 years ago

orxonox/trunk: ClassList now supports getLeafID() to retriefe the ID on hot to generate an object of the same type

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