Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/core/MetaObjectList.h @ 365

Last change on this file since 365 was 365, checked in by landauf, 16 years ago

added comments

File size: 3.9 KB
RevLine 
[365]1/*!
2    @file MetaObjectList.h
3    @brief Definition of the MetaObjectList class.
4
5    The MetaObjectList is a single-linked list, containing all list-elements and their
6    lists wherein the object that owns the MetaObjectList is registered.
7    This allows much faster deleting of objects.
8*/
9
[246]10#ifndef _MetaObjectList_H__
11#define _MetaObjectList_H__
12
13#include "ObjectList.h"
14#include "Identifier.h"
15
16namespace orxonox
17{
[365]18    //! Base-class of MetaObjectListElement, because those is a template
[246]19    class BaseMetaObjectListElement
20    {
21        public:
[365]22            /** @brief Defaultdestructor */
[246]23            virtual ~BaseMetaObjectListElement() {};
24
[365]25            BaseMetaObjectListElement* next_;       //!< The next Element in the list
[246]26    };
27
28    // ###############################
29    // ###  MetaObjectListElement  ###
30    // ###############################
[365]31    //! The list-element of the MetaObjectList
[246]32    template <class T>
33    class MetaObjectListElement : public BaseMetaObjectListElement
34    {
35        public:
36            MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element);
37            ~MetaObjectListElement();
38
[365]39            ObjectListElement<T>* element_;         //!< The list element, containing the object
40            ObjectList<T>* list_;                   //!< The list, containing the element
[246]41    };
42
[365]43    /**
44        @brief Constructor: Creates the list-element with given list and element.
45    */
[246]46    template <class T>
47    MetaObjectListElement<T>::MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element)
48    {
49        this->element_ = element;
50        this->list_ = list;
51        this->next_ = 0;
52    }
53
[365]54    /**
55        @brief Destructor: Removes the ObjectListElement from the ObjectList by linking next_ and prev_ of the ObjectListElement.
56    */
[246]57    template <class T>
58    MetaObjectListElement<T>::~MetaObjectListElement()
59    {
60        if (this->element_->next_)
61            this->element_->next_->prev_ = this->element_->prev_;
62        else
[365]63            this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list
[246]64
65        if (this->element_->prev_)
66            this->element_->prev_->next_ = this->element_->next_;
67        else
[365]68            this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list
[246]69
70
71#if HIERARCHY_VERBOSE
72        std::cout << "*** Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n";
73#endif
74        delete this->element_;
75    }
76
77
78    // ###############################
79    // ###       ObjectList        ###
80    // ###############################
[365]81    //!  The MetaObjectList contains ObjectListElements and their ObjectLists.
82    /**
83        The MetaObjectList is a single-linked list, containing all list-elements and their
84        lists wherein the object that owns the MetaObjectList is registered.
85        This allows much faster deleting of objects.
86    */
[246]87    class MetaObjectList
88    {
89        public:
90            MetaObjectList();
91            ~MetaObjectList();
92            template <class T>
93            void add(ObjectList<T>* list, ObjectListElement<T>* element);
94
[365]95            BaseMetaObjectListElement* first_;      //!< The first element in the list
[246]96    };
97
[365]98    /**
99        @brief Adds an ObjectList and an element of that list to the MetaObjectList.
100        @param list The ObjectList wherein the element is
101        @param element The element wherein the object is
102    */
[246]103    template <class T>
104    void MetaObjectList::add(ObjectList<T>* list, ObjectListElement<T>* element)
105    {
106        BaseMetaObjectListElement* temp = this->first_;
107        this->first_ = new MetaObjectListElement<T>(list, element);
108        this->first_->next_ = temp;
109    }
110}
111
112#endif
Note: See TracBrowser for help on using the repository browser.