Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/lang/new_class_id.h @ 9678

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

orxonox/trunk: implemented isA leafID and listInheritance

File size: 2.1 KB
Line 
1/*!
2 * @file new_class_id.h
3 * @brief Definition of a dynamically allocating ClassID
4 *
5 */
6
7#ifndef _NEW_CLASS_ID_H
8#define _NEW_CLASS_ID_H
9
10#include "new_object_list.h"
11
12#include <string>
13#include <list>
14
15
16
17
18//! A class to dynamically allocate ClassID's and support a isA operator
19class NewClassID
20{
21public:
22  NewClassID();
23  ~NewClassID();
24
25
26  int leafClassID() const { return _classes.front()._objectList->id(); }
27
28  template<class T> void registerObject(T* object, NewObjectList<T>& list);
29  bool isA(const NewObjectListBase& objectList) const;
30  bool isA(int classID) const;
31  bool isA(const std::string& className) const;
32
33  void listInheritance() const;
34
35private:
36  //////////////////////////////
37  //// Type Definition Part ////
38  //////////////////////////////
39  //! A ClassEntry so we can store Classes inside of Objects
40  struct ClassEntry
41  {
42    /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */
43    inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {}
44    NewObjectListBase*                _objectList;  //!< A ObjectList this Object is part of
45    NewObjectListBase::IteratorBase*  _iterator;    //!< An iterator pointing to the position of the Object inside of the List.
46  };
47  typedef std::list<ClassEntry>        ClassList;   //!< Type definition for the List.
48
49  ClassList                           _classes;     //!< All Classes this object is part of.
50};
51
52
53/**
54 * @brief Registeres an Object of Type T to objectList
55 * @param object The Object to append to the objectList.
56 * @param objectList The ObjectList to append the Object to.
57 *
58 * This function is essential to integrate objects into their designated ObjectList.
59 * Remember if you do not want objects to be stored in Lists (less overhead),
60 * do not attempt to call this function.
61 */
62template<class T>
63inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList)
64{
65  this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object)));
66}
67
68#endif /* _NEW_CLASS_ID_H */
Note: See TracBrowser for help on using the repository browser.