Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 1, 2007, 4:24:56 AM (16 years ago)
Author:
landauf
Message:

added comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/core/ObjectList.h

    r258 r365  
     1/*!
     2    @file ObjectList.h
     3    @brief Definition of the ObjectList class.
     4
     5    The ObjectList is a double-linked list, used by Identifiers to store all objects of a specific class in it.
     6    Created objects are added through the RegisterObject-macro in its constructor.
     7    Use Iterator<class> to iterate through all objects of the class.
     8*/
     9
    110#ifndef _ObjectList_H__
    211#define _ObjectList_H__
     
    413namespace orxonox
    514{
    6     class OrxonoxClass;
     15    class OrxonoxClass; // Forward declaration
    716
    817    // ###############################
    918    // ###    ObjectListElement    ###
    1019    // ###############################
     20    //! The list-element of the ObjectList
    1121    template <class T>
    1222    class ObjectListElement
     
    1424        public:
    1525            ObjectListElement(T* object);
    16             ~ObjectListElement();
    17 
    18             T* object_;
    19             ObjectListElement* next_;
    20             ObjectListElement* prev_;
     26
     27            T* object_;                     //!< The object
     28            ObjectListElement* next_;       //!< The next element in the list
     29            ObjectListElement* prev_;       //!< The previous element in the list
    2130    };
    2231
     32    /**
     33        @brief Constructor: Creates the list-element with an object.
     34        @param Object The object to store
     35    */
    2336    template <class T>
    2437    ObjectListElement<T>::ObjectListElement(T* object)
     
    2942    }
    3043
    31     template <class T>
    32     ObjectListElement<T>::~ObjectListElement()
    33     {
    34     }
    35 
    3644
    3745    // ###############################
     
    3947    // ###############################
    4048    template <class T>
    41     class Iterator;
    42 
     49    class Iterator; // Forward declaration
     50
     51    //! The ObjectList contains all objects of a specific class.
     52    /**
     53        The ObjectList is used by Identifiers to store all objects of a specific class in it.
     54        Use Iterator<class> to iterate through all objects in the list.
     55    */
    4356    template <class T>
    4457    class ObjectList
     
    4861            ~ObjectList();
    4962            ObjectListElement<T>* add(T* object);
    50             void remove(OrxonoxClass* object, bool bIterateForwards = true);
    51 
     63//            void remove(OrxonoxClass* object, bool bIterateForwards = true);
     64
     65            /** @returns the first element in the list */
    5266            inline static Iterator<T> start()
    5367                { return Iterator<T>(pointer_s->first_); }
     68
     69            /** @returns the last element in the list */
    5470            inline static Iterator<T> end()
    5571                { return Iterator<T>(pointer_s->last_); }
    5672
    57             ObjectListElement<T>* first_;
    58             ObjectListElement<T>* last_;
     73            ObjectListElement<T>* first_;       //!< The first element in the list
     74            ObjectListElement<T>* last_;        //!< The last element in the list
    5975
    6076        private:
    61             static ObjectList<T>* pointer_s;
     77            static ObjectList<T>* pointer_s;    //!< A static pointer to the last created list (different for all T)
    6278    };
    6379
    6480    template <class T>
    65     ObjectList<T>* ObjectList<T>::pointer_s = 0;
    66 
     81    ObjectList<T>* ObjectList<T>::pointer_s = 0; // Set the static member variable pointer_s to zero
     82
     83    /**
     84        @brief Constructor: Sets first_ and last_ to zero and the static member variable pointer_s to _this_
     85    */
    6786    template <class T>
    6887    ObjectList<T>::ObjectList()
     
    7190        this->last_ = 0;
    7291
     92        // ObjectLists are only created by Identifiers and therefore only one ObjectList of each T will exist.
     93        // Thats why pointer_s is in fact a pointer to the only ObjectList for a type, which makes it almost a singleton.
    7394        this->pointer_s = this;
    7495    }
    7596
     97    /**
     98        @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS.
     99    */
    76100    template <class T>
    77101    ObjectList<T>::~ObjectList()
     
    86110    }
    87111
     112    /**
     113        @brief Adds a new object to the end of the list.
     114        @param object The object to add
     115        @return The pointer to the new ObjectListElement, needed by the MetaObjectList of the added object
     116    */
    88117    template <class T>
    89118    ObjectListElement<T>* ObjectList<T>::add(T* object)
     
    91120        if (!this->last_)
    92121        {
     122            // If the list is empty
    93123            this->last_ = new ObjectListElement<T>(object);
    94             this->first_ = this->last_;
     124            this->first_ = this->last_; // There's only one object in the list now
    95125        }
    96126        else
    97127        {
     128            // If the list isn't empty
    98129            ObjectListElement<T>* temp = this->last_;
    99130            this->last_ = new ObjectListElement<T>(object);
     
    105136    }
    106137
     138
     139//    /**
     140//        @brief Removes an object from the list.
     141//        @param object The object to remove
     142//        @param bIterateForwards If true: Start searching the object at the beginning of the list
     143//    */
     144    /*
    107145    template <class T>
    108146    void ObjectList<T>::remove(OrxonoxClass* object, bool bIterateForwards)
     
    111149            return;
    112150
     151        // If there's only one object in the list, we have to set first_ and last_ to zero
    113152        if (this->first_ == this->last_)
    114153        {
     
    123162        }
    124163
     164        // Now we are sure we have more than one element in the list
    125165        if (bIterateForwards)
    126166        {
     167            // Start at the beginning of the list
     168
     169            // Check if it's the first object
    127170            if (this->first_->object_ == object)
    128171            {
     
    135178            }
    136179
     180            // Iterate through the whole list
    137181            ObjectListElement<T>* temp = this->first_;
    138182            while (temp->next_)
     
    146190                        temp2->prev_ = temp;
    147191                    else
    148                         this->last_ = temp;
     192                        this->last_ = temp; // If there is no next_, we deleted the last element and have to update the last_ pointer.
    149193
    150194                    return;
     
    156200        else
    157201        {
     202            // Start at the end of the list
     203
     204            // Check if it's the last object
    158205            if (this->last_->object_ == object)
    159206            {
     
    166213            }
    167214
     215            // Iterate through the whole list
    168216            ObjectListElement<T>* temp = this->last_;
    169217            while (temp->prev_)
     
    177225                        temp2->next_ = temp;
    178226                    else
    179                         this->first_ = temp;
     227                        this->first_ = temp; // If there is no prev_, we deleted the first element and have to update the first_ pointer.
    180228
    181229                    return;
     
    186234        }
    187235    }
     236    */
    188237}
    189238
Note: See TracChangeset for help on using the changeset viewer.