Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/lang/base_object.h @ 9691

Last change on this file since 9691 was 9691, checked in by bensch, 18 years ago

new_class_id: adapted Network

File size: 4.3 KB
Line 
1/*!
2 * @file base_object.h
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 */
11
12
13#ifndef __BASE_OBJECT_H_
14#define __BASE_OBJECT_H_
15
16#include "new_object_list.h"
17#include "sigslot/slot.h"
18
19#include <string>
20
21class TiXmlNode;
22class TiXmlElement;
23class ClassList;
24
25//! A class all other classes are derived from
26class BaseObject : public sigslot::has_slots<>
27{
28  NewObjectListDeclaration(BaseObject);
29public:
30  BaseObject (const std::string& objectName = "");
31
32  virtual ~BaseObject ();
33
34  virtual void loadParams(const TiXmlElement* root);
35  void setName (const std::string& newName);
36  /** returns the Name of this Object */
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(); };
40  /** @returns the XML-Element with whicht this Object was loaded */
41  inline TiXmlNode* getXmlElem() const { return this->xmlElem; };
42
43  //  /** @returns the className of the corresponding Object */
44  //inline const std::string& getClassName() const { return this->className; }
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(); };
47  /** @returns the ClassName of the Topmost Object of the ClassStack */
48  inline const std::string& getClassName() const { return _classes.front()._objectList->name(); }
49
50  /** @returns the ID of the Topmost object of the ClassStack */
51  inline const int& getLeafClassID() const { return _leafClassID->id(); }
52
53  bool isA(const NewObjectListBase& objectList) const;
54  bool isA(const NewClassID& classID) const;
55  bool isA(int classID) const;
56  bool isA(const std::string& className) const;
57
58  void listInheritance() const;
59
60  /** @param classID comparer for a ClassID @returns true on match, false otherwise */
61  bool operator==(int classID) const  { return this->isA(classID); };
62  /** @param objectName: the name to check. * @returns true on match, false otherwise. */
63  bool operator==(const std::string& objectName) const { return this->objectName == objectName;};
64
65protected:
66  template<class T> void registerObject(T* object, NewObjectList<T>& list);
67
68protected:
69  std::string        objectName;       //!< The name of this object
70
71private:
72
73  TiXmlNode*         xmlElem;          //!< The XML Element with wich this Object was loaded(saved).
74
75  //////////////////////////////
76  //// Type Definition Part ////
77  //////////////////////////////
78  //! A ClassEntry so we can store Classes inside of Objects
79  struct ClassEntry
80  {
81    /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */
82    inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {}
83    NewObjectListBase*                _objectList;  //!< A ObjectList this Object is part of
84    NewObjectListBase::IteratorBase*  _iterator;    //!< An iterator pointing to the position of the Object inside of the List.
85  };
86  typedef std::list<ClassEntry>        ClassList;   //!< Type definition for the List.
87
88  std::string                         className;    //!< the name of the class
89  ClassList                           _classes;     //!< All Classes this object is part of.
90  const NewClassID*                       _leafClassID;  //!< Topmost ClassID.
91};
92
93
94/**
95 * @brief Registeres an Object of Type T to objectList
96 * @param object The Object to append to the objectList.
97 * @param objectList The ObjectList to append the Object to.
98 *
99 * This function is essential to integrate objects into their designated ObjectList.
100 * Remember if you do not want objects to be stored in Lists (less overhead),
101 * do not attempt to call this function.
102 */
103template<class T>
104inline void BaseObject::registerObject(T* object, NewObjectList<T>& objectList)
105{
106  this->_leafClassID = &objectList.identity();
107  this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object)));
108}
109
110#endif /* __BASE_OBJECT_H_ */
Note: See TracBrowser for help on using the repository browser.