Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 7, 2008, 5:01:44 PM (17 years ago)
Author:
nicolasc
Message:

merged FICN back into trunk
awaiting release.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

    • Property svn:ignore set to
      dependencies
  • code/trunk/src/orxonox/core/ObjectList.h

    r258 r790  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software; you can redistribute it and/or
     8 *   modify it under the terms of the GNU General Public License
     9 *   as published by the Free Software Foundation; either version 2
     10 *   of the License, or (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program; if not, write to the Free Software
     19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     20 *
     21 *   Author:
     22 *      Fabian 'x3n' Landau
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28/*!
     29    @file ObjectList.h
     30    @brief Definition and implementation of the ObjectList class.
     31
     32    The ObjectList is a double-linked list, used by Identifiers to store all objects of a given class.
     33    Newly created objects are added through the RegisterObject-macro in its constructor.
     34    Use Iterator<class> to iterate through all objects of the class.
     35*/
     36
    137#ifndef _ObjectList_H__
    238#define _ObjectList_H__
    339
     40#include "CorePrereqs.h"
     41#include "Iterator.h"
     42
    443namespace orxonox
    544{
    6     class OrxonoxClass;
    7 
    845    // ###############################
    946    // ###    ObjectListElement    ###
    1047    // ###############################
     48    //! The list-element of the ObjectList
    1149    template <class T>
    1250    class ObjectListElement
     
    1452        public:
    1553            ObjectListElement(T* object);
    16             ~ObjectListElement();
    17 
    18             T* object_;
    19             ObjectListElement* next_;
    20             ObjectListElement* prev_;
     54
     55            T* object_;                     //!< The object
     56            ObjectListElement* next_;       //!< The next element in the list
     57            ObjectListElement* prev_;       //!< The previous element in the list
    2158    };
    2259
     60    /**
     61        @brief Constructor: Creates the list-element with an object.
     62        @param object The object to store
     63    */
    2364    template <class T>
    2465    ObjectListElement<T>::ObjectListElement(T* object)
     
    2970    }
    3071
    31     template <class T>
    32     ObjectListElement<T>::~ObjectListElement()
    33     {
    34     }
    35 
    3672
    3773    // ###############################
    3874    // ###       ObjectList        ###
    3975    // ###############################
    40     template <class T>
    41     class Iterator;
    42 
     76    //! The ObjectList contains all objects of a given class.
     77    /**
     78        The ObjectList is used by Identifiers to store all objects of a given class.
     79        Use Iterator<class> to iterate through all objects in the list.
     80    */
    4381    template <class T>
    4482    class ObjectList
    4583    {
    4684        public:
     85            static ObjectList<T>* getList();
     86
     87            ObjectListElement<T>* add(T* object);
     88//            void remove(OrxonoxClass* object, bool bIterateForwards = true);
     89
     90            /** @returns the first element in the list */
     91            inline static Iterator<T> start()
     92                { return Iterator<T>(getList()->first_); }
     93
     94            /** @returns the first element in the list */
     95            inline static Iterator<T> begin()
     96                { return Iterator<T>(getList()->first_); }
     97
     98            /** @returns the last element in the list */
     99            inline static Iterator<T> end()
     100                { return Iterator<T>(getList()->last_); }
     101
     102            ObjectListElement<T>* first_;       //!< The first element in the list
     103            ObjectListElement<T>* last_;        //!< The last element in the list
     104
     105        private:
    47106            ObjectList();
    48107            ~ObjectList();
    49             ObjectListElement<T>* add(T* object);
    50             void remove(OrxonoxClass* object, bool bIterateForwards = true);
    51 
    52             inline static Iterator<T> start()
    53                 { return Iterator<T>(pointer_s->first_); }
    54             inline static Iterator<T> end()
    55                 { return Iterator<T>(pointer_s->last_); }
    56 
    57             ObjectListElement<T>* first_;
    58             ObjectListElement<T>* last_;
    59 
    60         private:
    61             static ObjectList<T>* pointer_s;
    62108    };
    63109
    64     template <class T>
    65     ObjectList<T>* ObjectList<T>::pointer_s = 0;
    66 
     110    /**
     111        @brief Constructor: Sets default values.
     112    */
    67113    template <class T>
    68114    ObjectList<T>::ObjectList()
     
    70116        this->first_ = 0;
    71117        this->last_ = 0;
    72 
    73         this->pointer_s = this;
    74     }
    75 
     118    }
     119
     120    /**
     121        @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS.
     122    */
    76123    template <class T>
    77124    ObjectList<T>::~ObjectList()
     
    86133    }
    87134
     135    /**
     136        @returns a pointer to the only existing instance for the given class T.
     137    */
     138    template <class T>
     139    ObjectList<T>* ObjectList<T>::getList()
     140    {
     141        static ObjectList<T> theOnlyObjectListObjectForClassT = ObjectList<T>();
     142        return &theOnlyObjectListObjectForClassT;
     143    }
     144
     145    /**
     146        @brief Adds a new object to the end of the list.
     147        @param object The object to add
     148        @return The pointer to the new ObjectListElement, needed by the MetaObjectList of the added object
     149    */
    88150    template <class T>
    89151    ObjectListElement<T>* ObjectList<T>::add(T* object)
     
    91153        if (!this->last_)
    92154        {
     155            // If the list is empty
    93156            this->last_ = new ObjectListElement<T>(object);
    94             this->first_ = this->last_;
     157            this->first_ = this->last_; // There's only one object in the list now
    95158        }
    96159        else
    97160        {
     161            // If the list isn't empty
    98162            ObjectListElement<T>* temp = this->last_;
    99163            this->last_ = new ObjectListElement<T>(object);
     
    105169    }
    106170
     171
     172//    /**
     173//        @brief Removes an object from the list.
     174//        @param object The object to remove
     175//        @param bIterateForwards If true: Start searching the object at the beginning of the list
     176//    */
     177    /*
    107178    template <class T>
    108179    void ObjectList<T>::remove(OrxonoxClass* object, bool bIterateForwards)
     
    111182            return;
    112183
     184        // If there's only one object in the list, we have to set first_ and last_ to zero
    113185        if (this->first_ == this->last_)
    114186        {
     
    123195        }
    124196
     197        // Now we are sure we have more than one element in the list
    125198        if (bIterateForwards)
    126199        {
     200            // Start at the beginning of the list
     201
     202            // Check if it's the first object
    127203            if (this->first_->object_ == object)
    128204            {
     
    135211            }
    136212
     213            // Iterate through the whole list
    137214            ObjectListElement<T>* temp = this->first_;
    138215            while (temp->next_)
     
    146223                        temp2->prev_ = temp;
    147224                    else
    148                         this->last_ = temp;
     225                        this->last_ = temp; // If there is no next_, we deleted the last element and have to update the last_ pointer.
    149226
    150227                    return;
     
    156233        else
    157234        {
     235            // Start at the end of the list
     236
     237            // Check if it's the last object
    158238            if (this->last_->object_ == object)
    159239            {
     
    166246            }
    167247
     248            // Iterate through the whole list
    168249            ObjectListElement<T>* temp = this->last_;
    169250            while (temp->prev_)
     
    177258                        temp2->next_ = temp;
    178259                    else
    179                         this->first_ = temp;
     260                        this->first_ = temp; // If there is no prev_, we deleted the first element and have to update the first_ pointer.
    180261
    181262                    return;
     
    186267        }
    187268    }
     269    */
    188270}
    189271
    190 #endif
     272#endif /* _ObjectList_H__ */
Note: See TracChangeset for help on using the changeset viewer.