PixelLightAPI  .
SimpleMap.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SimpleMap.h                                    *
00003  *
00004  *  Copyright (C) 2002-2011 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_SIMPLEMAP_H__
00024 #define __PLCORE_CONTAINER_SIMPLEMAP_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/Container/Map.h"
00032 #include "PLCore/Container/FastPool.h"
00033 #include "PLCore/Container/Functions.h"
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLCore {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Forward declarations                                  ]
00044 //[-------------------------------------------------------]
00045 template <class KeyType, class ValueType, class Comparer> class SimpleMapIterator;
00046 template <class KeyType, class ValueType, class Comparer> class SimpleMapKeyIterator;
00047 
00048 
00049 //[-------------------------------------------------------]
00050 //[ Classes                                               ]
00051 //[-------------------------------------------------------]
00052 /**
00053 *  @brief
00054 *    Simple map template
00055 *
00056 *  @remarks
00057 *    This map implementation is quite simple, but not that performant. It's not recommended
00058 *    to use this implementation if you have a lot of elements within the map.
00059 */
00060 template <class KeyType, class ValueType, class Comparer = CompareFunction>
00061 class SimpleMap : public Map<KeyType, ValueType> {
00062 
00063 
00064     //[-------------------------------------------------------]
00065     //[ Friends                                               ]
00066     //[-------------------------------------------------------]
00067     friend class SimpleMapIterator<KeyType, ValueType, Comparer>;
00068     friend class SimpleMapKeyIterator<KeyType, ValueType, Comparer>;
00069 
00070 
00071     //[-------------------------------------------------------]
00072     //[ Public functions                                      ]
00073     //[-------------------------------------------------------]
00074     public:
00075         /**
00076         *  @brief
00077         *    Constructor
00078         */
00079         SimpleMap();
00080 
00081         /**
00082         *  @brief
00083         *    Destructor
00084         */
00085         virtual ~SimpleMap();
00086 
00087         /**
00088         *  @brief
00089         *    Copy operator
00090         *
00091         *  @param[in] cSource
00092         *    'SimpleMap' to copy from
00093         *
00094         *  @return
00095         *    Reference to this instance
00096         */
00097         Map<KeyType, ValueType> &operator =(const SimpleMap<KeyType, ValueType, Comparer> &cSource);
00098 
00099 
00100     //[-------------------------------------------------------]
00101     //[ Private structures                                    ]
00102     //[-------------------------------------------------------]
00103     private:
00104         /**
00105         *  @brief
00106         *    Internal fast pool element
00107         */
00108         class Element : public FastPoolElement<Element> {
00109             public:
00110                 KeyType   Key;      /**< The key*/
00111                 ValueType Value;    /**< The value */
00112                 bool operator ==(const Element &cOther) const
00113                 {
00114                     return false;
00115                 }
00116         };
00117 
00118 
00119     //[-------------------------------------------------------]
00120     //[ Private data                                          ]
00121     //[-------------------------------------------------------]
00122     private:
00123         FastPool<Element> m_lstElements;    /**< List of elements */
00124 
00125 
00126     //[-------------------------------------------------------]
00127     //[ Public virtual Iterable functions                     ]
00128     //[-------------------------------------------------------]
00129     public:
00130         virtual Iterator<ValueType> GetIterator(uint32 nIndex = 0) const override;
00131         virtual ConstIterator<ValueType> GetConstIterator(uint32 nIndex = 0) const override;
00132         virtual Iterator<ValueType> GetEndIterator() const override;
00133         virtual ConstIterator<ValueType> GetConstEndIterator() const override;
00134 
00135 
00136     //[-------------------------------------------------------]
00137     //[ Public virtual Map functions                          ]
00138     //[-------------------------------------------------------]
00139     public:
00140         virtual void Clear() override;
00141         virtual bool IsEmpty() const override;
00142         virtual uint32 GetNumOfElements() const override;
00143         virtual bool Add(const KeyType &Key, const ValueType &Value) override;
00144         virtual bool Replace(const KeyType &Key, const ValueType &NewValue) override;
00145         virtual bool Set(const KeyType &Key, const ValueType &Value) override;
00146         virtual bool Remove(const KeyType &Key) override;
00147         virtual uint32 RemoveValue(const ValueType &Value) override;
00148         virtual const ValueType &Get(const KeyType &Key) const override;
00149         virtual ValueType &Get(const KeyType &Key) override;
00150         virtual Iterator<KeyType> GetKeyIterator(uint32 nIndex = 0) const override;
00151         virtual ConstIterator<KeyType> GetConstKeyIterator(uint32 nIndex = 0) const override;
00152         virtual Iterator<KeyType> GetEndKeyIterator() const override;
00153         virtual ConstIterator<KeyType> GetConstEndKeyIterator() const override;
00154 
00155 
00156     //[-------------------------------------------------------]
00157     //[ Private virtual Map functions                         ]
00158     //[-------------------------------------------------------]
00159     private:
00160         virtual Map<KeyType, ValueType> &operator =(const Map<KeyType, ValueType> &cMap) override;
00161 
00162 
00163 };
00164 
00165 
00166 //[-------------------------------------------------------]
00167 //[ Namespace                                             ]
00168 //[-------------------------------------------------------]
00169 } // PLCore
00170 
00171 
00172 //[-------------------------------------------------------]
00173 //[ Implementation                                        ]
00174 //[-------------------------------------------------------]
00175 #include "PLCore/Container/SimpleMap.inl"
00176 
00177 
00178 #endif // __PLCORE_CONTAINER_SIMPLEMAP_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:01
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported