[4591] | 1 | /*! |
---|
[5039] | 2 | * @file base_object.h |
---|
[9406] | 3 | * @brief Definition of the BaseObject class. |
---|
| 4 | * |
---|
| 5 | * This is a global handler for all classes Object and Class names |
---|
| 6 | * |
---|
| 7 | * BaseObject is the class, that handles object registration and |
---|
| 8 | * is the only write-access member of ClassList, where the Objects |
---|
| 9 | * References are stored. |
---|
| 10 | */ |
---|
[4470] | 11 | |
---|
[3302] | 12 | |
---|
[9406] | 13 | #ifndef __BASE_OBJECT_H_ |
---|
| 14 | #define __BASE_OBJECT_H_ |
---|
[3302] | 15 | |
---|
[9684] | 16 | #include "new_object_list.h" |
---|
[9406] | 17 | #include "sigslot/slot.h" |
---|
[3302] | 18 | |
---|
[8035] | 19 | #include <string> |
---|
[3302] | 20 | |
---|
[6517] | 21 | class TiXmlNode; |
---|
[4436] | 22 | class TiXmlElement; |
---|
[6280] | 23 | class ClassList; |
---|
[4436] | 24 | |
---|
[4382] | 25 | //! A class all other classes are derived from |
---|
[9406] | 26 | class BaseObject : public sigslot::has_slots<> |
---|
[8350] | 27 | { |
---|
[3302] | 28 | |
---|
[8350] | 29 | public: |
---|
| 30 | BaseObject (const std::string& objectName = ""); |
---|
[7779] | 31 | |
---|
[3531] | 32 | virtual ~BaseObject (); |
---|
[3302] | 33 | |
---|
[6512] | 34 | virtual void loadParams(const TiXmlElement* root); |
---|
[7221] | 35 | void setName (const std::string& newName); |
---|
[5113] | 36 | /** returns the Name of this Object */ |
---|
[9406] | 37 | inline const std::string& getName() const { return this->objectName; }; |
---|
| 38 | /** returns the Name of this Object as a C-compliant string (const char*) */ |
---|
| 39 | inline const char* getCName() const { return this->objectName.c_str(); }; |
---|
[6587] | 40 | /** @returns the XML-Element with whicht this Object was loaded */ |
---|
| 41 | inline TiXmlNode* getXmlElem() const { return this->xmlElem; }; |
---|
[4318] | 42 | |
---|
[9684] | 43 | // /** @returns the className of the corresponding Object */ |
---|
| 44 | //inline const std::string& getClassName() const { return this->className; } |
---|
[9406] | 45 | /** @returns the className of the corresponding Object as a C-compliant string (const char*) */ |
---|
| 46 | inline const char* getClassCName() const { return this->className.c_str(); }; |
---|
[9684] | 47 | /** @returns the ClassName of the Topmost Object of the ClassStack */ |
---|
| 48 | inline const std::string& getClassName() const { return _classes.front()._objectList->name(); } |
---|
[3302] | 49 | |
---|
[9684] | 50 | /** @returns the ID of the Topmost object of the ClassStack */ |
---|
| 51 | inline int getLeafClassID() const { return _classes.front()._objectList->id(); } |
---|
[4470] | 52 | |
---|
[9684] | 53 | bool isA(const NewObjectListBase& objectList) const; |
---|
| 54 | bool isA(int classID) const; |
---|
| 55 | bool isA(const std::string& className) const; |
---|
| 56 | |
---|
| 57 | void listInheritance() const; |
---|
| 58 | |
---|
[6077] | 59 | /** @param classID comparer for a ClassID @returns true on match, false otherwise */ |
---|
[9684] | 60 | bool operator==(int classID) const { return this->isA(classID); }; |
---|
| 61 | /** @param objectName: the name to check. * @returns true on match, false otherwise. */ |
---|
| 62 | bool operator==(const std::string& objectName) const { return this->objectName == objectName;}; |
---|
[5626] | 63 | |
---|
[8350] | 64 | protected: |
---|
[9684] | 65 | template<class T> void registerObject(T* object, NewObjectList<T>& list); |
---|
[4539] | 66 | |
---|
[8350] | 67 | protected: |
---|
| 68 | std::string objectName; //!< The name of this object |
---|
[6280] | 69 | |
---|
[8350] | 70 | private: |
---|
| 71 | |
---|
[9684] | 72 | TiXmlNode* xmlElem; //!< The XML Element with wich this Object was loaded(saved). |
---|
[8350] | 73 | |
---|
[9684] | 74 | ////////////////////////////// |
---|
| 75 | //// Type Definition Part //// |
---|
| 76 | ////////////////////////////// |
---|
| 77 | //! A ClassEntry so we can store Classes inside of Objects |
---|
| 78 | struct ClassEntry |
---|
| 79 | { |
---|
| 80 | /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */ |
---|
| 81 | inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {} |
---|
| 82 | NewObjectListBase* _objectList; //!< A ObjectList this Object is part of |
---|
| 83 | NewObjectListBase::IteratorBase* _iterator; //!< An iterator pointing to the position of the Object inside of the List. |
---|
| 84 | }; |
---|
| 85 | typedef std::list<ClassEntry> ClassList; //!< Type definition for the List. |
---|
| 86 | |
---|
| 87 | std::string className; //!< the name of the class |
---|
| 88 | ClassList _classes; //!< All Classes this object is part of. |
---|
| 89 | |
---|
[3302] | 90 | }; |
---|
| 91 | |
---|
[9684] | 92 | |
---|
| 93 | /** |
---|
| 94 | * @brief Registeres an Object of Type T to objectList |
---|
| 95 | * @param object The Object to append to the objectList. |
---|
| 96 | * @param objectList The ObjectList to append the Object to. |
---|
| 97 | * |
---|
| 98 | * This function is essential to integrate objects into their designated ObjectList. |
---|
| 99 | * Remember if you do not want objects to be stored in Lists (less overhead), |
---|
| 100 | * do not attempt to call this function. |
---|
| 101 | */ |
---|
| 102 | template<class T> |
---|
| 103 | inline void BaseObject::registerObject(T* object, NewObjectList<T>& objectList) |
---|
| 104 | { |
---|
| 105 | this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object))); |
---|
| 106 | } |
---|
| 107 | |
---|
[9406] | 108 | #endif /* __BASE_OBJECT_H_ */ |
---|