[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 | |
---|
[9869] | 16 | #include "object_list.h" |
---|
| 17 | #include "util/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 | { |
---|
[9869] | 28 | //! Declare an ObjectList for this Class. |
---|
| 29 | ObjectListDeclaration(BaseObject); |
---|
[8350] | 30 | public: |
---|
| 31 | BaseObject (const std::string& objectName = ""); |
---|
[10114] | 32 | BaseObject( const BaseObject& bo ); |
---|
[7779] | 33 | |
---|
[3531] | 34 | virtual ~BaseObject (); |
---|
[3302] | 35 | |
---|
[6512] | 36 | virtual void loadParams(const TiXmlElement* root); |
---|
[7221] | 37 | void setName (const std::string& newName); |
---|
[5113] | 38 | /** returns the Name of this Object */ |
---|
[9406] | 39 | inline const std::string& getName() const { return this->objectName; }; |
---|
| 40 | /** returns the Name of this Object as a C-compliant string (const char*) */ |
---|
| 41 | inline const char* getCName() const { return this->objectName.c_str(); }; |
---|
[6587] | 42 | /** @returns the XML-Element with whicht this Object was loaded */ |
---|
| 43 | inline TiXmlNode* getXmlElem() const { return this->xmlElem; }; |
---|
[4318] | 44 | |
---|
[9869] | 45 | // /** @returns the className of the corresponding Object */ |
---|
| 46 | //inline const std::string& getClassName() const { return this->className; } |
---|
[9406] | 47 | /** @returns the className of the corresponding Object as a C-compliant string (const char*) */ |
---|
[9869] | 48 | inline const char* getClassCName() const { return _classes.front()._objectList->name().c_str(); }; |
---|
| 49 | /** @returns the ClassName of the Topmost Object of the ClassStack */ |
---|
| 50 | inline const std::string& getClassName() const { return _classes.front()._objectList->name(); }; |
---|
[3302] | 51 | |
---|
[9869] | 52 | /** @returns the ClassID of this Object */ |
---|
| 53 | inline const ClassID& getClassID() const { return _classes.front()._objectList->identity(); } |
---|
[4470] | 54 | |
---|
[9869] | 55 | bool isA(const ObjectListBase& objectList) const; |
---|
| 56 | bool isA(const ClassID& classID) const; |
---|
| 57 | bool isA(int classID) const; |
---|
| 58 | bool isA(const std::string& className) const; |
---|
| 59 | |
---|
| 60 | void listInheritance() const; |
---|
| 61 | |
---|
[6077] | 62 | /** @param classID comparer for a ClassID @returns true on match, false otherwise */ |
---|
[9869] | 63 | bool operator==(int classID) const { return this->isA(classID); }; |
---|
| 64 | /** @param objectName: the name to check. * @returns true on match, false otherwise. */ |
---|
| 65 | bool operator==(const std::string& objectName) const { return this->objectName == objectName;}; |
---|
[5626] | 66 | |
---|
[8350] | 67 | protected: |
---|
[9869] | 68 | template<class T> void registerObject(T* object, ObjectList<T>& list); |
---|
[4539] | 69 | |
---|
[8350] | 70 | protected: |
---|
| 71 | std::string objectName; //!< The name of this object |
---|
[6280] | 72 | |
---|
[8350] | 73 | private: |
---|
| 74 | |
---|
[9869] | 75 | TiXmlNode* xmlElem; //!< The XML Element with wich this Object was loaded(saved). |
---|
[8350] | 76 | |
---|
[9869] | 77 | ////////////////////////////// |
---|
| 78 | //// Type Definition Part //// |
---|
| 79 | ////////////////////////////// |
---|
| 80 | //! A ClassEntry so we can store Classes inside of Objects |
---|
| 81 | struct ClassEntry |
---|
| 82 | { |
---|
| 83 | /** Simple Constuctor @param objectList the ObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */ |
---|
| 84 | inline ClassEntry (ObjectListBase* objectList, ObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {} |
---|
| 85 | ObjectListBase* _objectList; //!< An ObjectList this Object is part of |
---|
| 86 | ObjectListBase::IteratorBase* _iterator; //!< An iterator pointing to the position of the Object inside of the List. |
---|
| 87 | }; |
---|
| 88 | typedef std::list<ClassEntry> ClassEntries; //!< Type definition for the List. |
---|
| 89 | |
---|
| 90 | std::string className; //!< the name of the class |
---|
| 91 | ClassEntries _classes; //!< All Classes this object is part of. |
---|
[3302] | 92 | }; |
---|
| 93 | |
---|
[9869] | 94 | |
---|
| 95 | /** |
---|
| 96 | * @brief Registeres an Object of Type T to objectList |
---|
| 97 | * @param object The Object to append to the objectList. |
---|
| 98 | * @param objectList The ObjectList to append the Object to. |
---|
| 99 | * |
---|
| 100 | * This function is essential to integrate objects into their designated ObjectList. |
---|
| 101 | * Remember if you do not want objects to be stored in Lists (less overhead), |
---|
| 102 | * do not attempt to call this function. |
---|
| 103 | */ |
---|
| 104 | template<class T> |
---|
| 105 | inline void BaseObject::registerObject(T* object, ObjectList<T>& objectList) |
---|
| 106 | { |
---|
| 107 | this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object))); |
---|
| 108 | } |
---|
| 109 | |
---|
[9406] | 110 | #endif /* __BASE_OBJECT_H_ */ |
---|