PixelLightAPI  .
List.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: List.h                                         *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_CONTAINER_LIST_H__
00024 #define __PLCORE_CONTAINER_LIST_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/Container/Container.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Forward declarations                                  ]
00042 //[-------------------------------------------------------]
00043 template <class ValueType> class ListIterator;
00044 
00045 
00046 //[-------------------------------------------------------]
00047 //[ Classes                                               ]
00048 //[-------------------------------------------------------]
00049 /**
00050 *  @brief
00051 *    Linked list class
00052 *
00053 *  @remarks
00054 *    Within the double linked list each node knows it's previous and next element. If you
00055 *    want to receive element x, internally the process begins with the first element and
00056 *    goes to the next until element x was found. As you see the following example isn't
00057 *    that performant:\n
00058 *  @verbatim
00059 *    for (uint32 i=0; i<lstList.GetNumOfElements(); i++) {
00060 *      ListElement &cElement = lstList[i];
00061 *    }
00062 *  @endverbatim
00063 *    Instead use the provided iterator whenever possible:\
00064 *  @verbatim
00065 *    Iterator<ListElement*> cIterator = m_lstList.GetIterator();
00066 *    while (cIterator.HasNext()) {
00067 *        ListElement *pElement = cIterator.Next();
00068 *    }
00069 *  @endverbatim
00070 */
00071 template <class ValueType>
00072 class List : public Container<ValueType> {
00073 
00074 
00075     //[-------------------------------------------------------]
00076     //[ Friends                                               ]
00077     //[-------------------------------------------------------]
00078     friend class ListIterator<ValueType>;
00079 
00080 
00081     //[-------------------------------------------------------]
00082     //[ Public functions                                      ]
00083     //[-------------------------------------------------------]
00084     public:
00085         /**
00086         *  @brief
00087         *    Constructor
00088         */
00089         List();
00090 
00091         /**
00092         *  @brief
00093         *    Copy constructor
00094         *
00095         *  @param[in] lstSource
00096         *    List to copy from
00097         *  @param[in] nStart
00098         *    Index the copy operation should start
00099         *  @param[in] nCount
00100         *    Number of elements to copy, if 0 copy all elements of lstSource behind nStart
00101         */
00102         List(const List<ValueType> &lstSource, uint32 nStart = 0, uint32 nCount = 0);
00103 
00104         /**
00105         *  @brief
00106         *    Copy constructor
00107         *
00108         *  @param[in] lstSource
00109         *    Container to copy from
00110         *  @param[in] nStart
00111         *    Index the copy operation should start
00112         *  @param[in] nCount
00113         *    Number of elements to copy, if 0 copy all elements of lstSource behind nStart
00114         */
00115         List(const Container<ValueType> &lstSource, uint32 nStart = 0, uint32 nCount = 0);
00116 
00117         /**
00118         *  @brief
00119         *    Destructor
00120         */
00121         virtual ~List();
00122 
00123         /**
00124         *  @brief
00125         *    Copy operator
00126         *
00127         *  @param[in] lstSource
00128         *    List to copy from
00129         *
00130         *  @return
00131         *    Reference to this instance
00132         */
00133         Container<ValueType> &operator =(const List<ValueType> &lstSource);
00134 
00135 
00136     //[-------------------------------------------------------]
00137     //[ Private structures                                    ]
00138     //[-------------------------------------------------------]
00139     private:
00140         /**
00141         *  @brief
00142         *    Internal linked list element
00143         */
00144         struct ListElement {
00145             ListElement *pNextElement;      /**< Pointer to the next element in the list, can be a null pointer */
00146             ListElement *pPreviousElement;  /**< Pointer to the previous element in the list, can be a null pointer */
00147             ValueType    Data;              /**< The stored data */
00148         };
00149 
00150 
00151     //[-------------------------------------------------------]
00152     //[ Private data                                          ]
00153     //[-------------------------------------------------------]
00154     private:
00155         uint32       m_nNumOfElements;  /**< Current number of elements */
00156         ListElement *m_pFirstElement;   /**< Pointer to first list element, can be a null pointer */
00157         ListElement *m_pLastElement;    /**< Pointer to last list element, can be a null pointer */
00158 
00159 
00160     //[-------------------------------------------------------]
00161     //[ Public virtual Iterable functions                     ]
00162     //[-------------------------------------------------------]
00163     public:
00164         virtual Iterator<ValueType> GetIterator(uint32 nIndex = 0) const override;
00165         virtual ConstIterator<ValueType> GetConstIterator(uint32 nIndex = 0) const override;
00166         virtual Iterator<ValueType> GetEndIterator() const override;
00167         virtual ConstIterator<ValueType> GetConstEndIterator() const override;
00168 
00169 
00170     //[-------------------------------------------------------]
00171     //[ Public virtual Container functions                    ]
00172     //[-------------------------------------------------------]
00173     public:
00174         virtual bool IsEmpty() const override;
00175         virtual uint32 GetNumOfElements() const override;
00176         virtual uint32 GetElementSize() const override;
00177         virtual uint32 GetSize() const override;
00178         virtual void Clear() override;
00179         virtual bool IsElement(const ValueType &Element) const override;
00180         virtual int GetIndex(const ValueType &Element) const override;
00181         virtual ValueType &Get(uint32 nIndex) const override;
00182         virtual ValueType &operator [](uint32 nIndex) const override;
00183         virtual bool Replace(const ValueType &Element1, const ValueType &Element2) override;
00184         virtual bool ReplaceAtIndex(uint32 nIndex, const ValueType &Element) override;
00185         virtual ValueType &Add() override;
00186         virtual ValueType &Add(const ValueType &Element) override;
00187         virtual uint32 Add(const ValueType *pElements, uint32 nCount) override;
00188         virtual Container<ValueType> &operator +=(const ValueType &Element) override;
00189         virtual bool Add(const Container<ValueType> &lstContainer, uint32 nStart = 0, uint32 nCount = 0) override;
00190         virtual Container<ValueType> &operator +=(const Container<ValueType> &lstContainer) override;
00191         virtual ValueType &AddAtIndex(int nIndex) override;
00192         virtual ValueType &AddAtIndex(const ValueType &Element, int nIndex) override;
00193         virtual bool Remove(const ValueType &Element) override;
00194         virtual bool RemoveAtIndex(uint32 nElement) override;
00195         virtual Container<ValueType> &operator -=(const ValueType &Element) override;
00196         virtual bool Remove(const Container<ValueType> &lstContainer, uint32 nStart = 0, uint32 nCount = 0) override;
00197         virtual Container<ValueType> &operator -=(const Container<ValueType> &lstContainer) override;
00198         virtual bool Copy(const Container<ValueType> &lstContainer, uint32 nStart = 0, uint32 nCount = 0) override;
00199         virtual Container<ValueType> &operator =(const Container<ValueType> &lstContainer) override;
00200         virtual bool Compare(const Container<ValueType> &lstContainer, uint32 nStart = 0, uint32 nCount = 0) const override;
00201         virtual bool operator ==(const Container<ValueType> &lstContainer) const override;
00202         virtual bool operator !=(const Container<ValueType> &lstContainer) const override;
00203 
00204 
00205 };
00206 
00207 
00208 //[-------------------------------------------------------]
00209 //[ Namespace                                             ]
00210 //[-------------------------------------------------------]
00211 } // PLCore
00212 
00213 
00214 //[-------------------------------------------------------]
00215 //[ Implementation                                        ]
00216 //[-------------------------------------------------------]
00217 #include "PLCore/Container/List.inl"
00218 
00219 
00220 #endif // __PLCORE_CONTAINER_LIST_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:56
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported