Main Page | Modules | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Namespace Members | Data Fields | Globals

OrderedVector.h

Go to the documentation of this file.
00001 /********************************************************************
00002 
00003 Copyright 2006, ACCESS Systems Americas, Inc. All rights reserved.
00004 
00005 The contents of this file are subject to the Mozilla Public License Version
00006 1.1 (the "License"); you may not use this file except in compliance with
00007 the License. You may obtain a copy of the License at
00008 http://www.mozilla.org/MPL/
00009 
00010 Software distributed under the License is distributed on an "AS IS" basis,
00011 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012 for the specific language governing rights and limitations under the
00013 License.
00014 
00015 The Original Code is the entire contents of this file.
00016 
00017 The Initial Developer of the Original Code is ACCESS Systems Americas, Inc.
00018 
00019 Portions created by ACCESS Systems Americas, Inc. are Copyright © 2006. All
00020 Rights Reserved.
00021 
00022 Contributor(s): none.
00023 
00024 ********************************************************************/
00025 /***************************************************************************
00026 //
00027 //      File:                   support/OrderedVector.h
00028 //
00029 //      Description:    A Vector whose types have an intrinsic ordering.
00030 //
00031 //      Copyright 2001, Be Incorporated, All Rights Reserved.
00032 //
00033 ***************************************************************************/
00034 
00035 #ifndef _SUPPORT_ORDEREDVECTOR_H
00036 #define _SUPPORT_ORDEREDVECTOR_H
00037 
00038 #include <hiker/prv/support/TypeFuncs.h>
00039 #include <hiker/prv/support/Vector.h>
00040 
00041 namespace alp {
00042 
00043 /*--------------------------------------------------------*/
00044 /*----- AbstractOrderedVector abstract base class -------*/
00045 
00046 class AbstractOrderedVector : public AbstractVector
00047 {
00048 public:
00049                                                         AbstractOrderedVector(size_t element_size);
00050                                                         AbstractOrderedVector(const AbstractVector& o);
00051                                                         // WARNING: Your subclass must call MakeEmpty()
00052                                                         // in its own destructor!
00053         virtual                                 ~AbstractOrderedVector();
00054 
00055                         AbstractOrderedVector& operator=(const AbstractOrderedVector& o);
00056 
00057                         // Note that we inherit the assignment operator, so you can
00058                         // assign a plain AbstractVector to an instance of this class.
00059 
00060                         ssize_t                 AddOrdered(const void* newElement, bool* added = NULL);
00061 
00062                         ssize_t                 OrderOf(const void* element) const;
00063                         bool                    GetOrderOf(const void* element, size_t* index) const;
00064 
00065                         ssize_t                 RemoveOrdered(const void* element);
00066 
00067                         void                    Swap(AbstractOrderedVector& o);
00068 
00069 protected:
00070         virtual int32_t                 PerformCompare(const void* d1, const void* d2) const = 0;
00071         virtual bool                    PerformLessThan(const void* d1, const void* d2) const = 0;
00072 
00073 private:
00074         virtual alp_status_t    _ReservedUntypedOrderedVector1();
00075         virtual alp_status_t    _ReservedUntypedOrderedVector2();
00076         virtual alp_status_t    _ReservedUntypedOrderedVector3();
00077         virtual alp_status_t    _ReservedUntypedOrderedVector4();
00078         virtual alp_status_t    _ReservedUntypedOrderedVector5();
00079         virtual alp_status_t    _ReservedUntypedOrderedVector6();
00080 
00081                         int32_t                 _reserved[2];
00082 };
00083 
00084 // Type optimizations.
00085 void MoveBefore(AbstractOrderedVector* to, AbstractOrderedVector* from, size_t count = 1);
00086 void MoveAfter(AbstractOrderedVector* to, AbstractOrderedVector* from, size_t count = 1);
00087 void Swap(AbstractOrderedVector& v1, AbstractOrderedVector& v2);
00088 
00089 /*--------------------------------------------------------*/
00090 /*----- OrderedVector concrete class --------------------*/
00091 
00092 template<class TYPE>
00093 class OrderedVector : private AbstractOrderedVector
00094 {
00095 public:
00096                                                         OrderedVector();
00097                                                         OrderedVector(const OrderedVector<TYPE>& o);
00098         virtual                                 ~OrderedVector();
00099 
00100                         OrderedVector<TYPE>&    operator=(const OrderedVector<TYPE>& o);
00101 
00102         /* Size stats */
00103 
00104                         void                    SetCapacity(size_t total_space);
00105                         void                    SetExtraCapacity(size_t extra_space);
00106                         size_t                  Capacity() const;
00107 
00108                         size_t                  CountItems() const;
00109 
00110         /* Data access */
00111 
00112                         const TYPE&             operator[](size_t i) const;
00113                         const TYPE&             ItemAt(size_t i) const;
00114 
00115                         ssize_t                 IndexOf(const TYPE& item) const;
00116                         bool                    GetIndexOf(const TYPE& item, size_t* index) const;
00117 
00118         /* Array modification */
00119 
00120                         ssize_t                 AddItem(const TYPE& item, bool* added = NULL);
00121 
00122                         void                    MakeEmpty();
00123                         void                    RemoveItemsAt(size_t index, size_t count = 1);
00124 
00125                         ssize_t                 RemoveItemFor(const TYPE& item);
00126 
00127                         void                    Swap(OrderedVector<TYPE>& o);
00128 
00129 protected:
00130         virtual void                    PerformConstruct(void* base, size_t count) const;
00131         virtual void                    PerformCopy(void* to, const void* from, size_t count) const;
00132         virtual void                    PerformDestroy(void* base, size_t count) const;
00133 
00134         virtual void                    PerformMoveBefore(void* to, void* from, size_t count) const;
00135         virtual void                    PerformMoveAfter(void* to, void* from, size_t count) const;
00136 
00137         virtual void                    PerformAssign(void* to, const void* from, size_t count) const;
00138 
00139         virtual int32_t                 PerformCompare(const void* d1, const void* d2) const;
00140         virtual bool                    PerformLessThan(const void* d1, const void* d2) const;
00141 };
00142 
00143 // Type optimizations.
00144 template<class TYPE>
00145 void MoveBefore(OrderedVector<TYPE>* to, OrderedVector<TYPE>* from, size_t count = 1);
00146 template<class TYPE>
00147 void MoveAfter(OrderedVector<TYPE>* to, OrderedVector<TYPE>* from, size_t count = 1);
00148 template<class TYPE>
00149 void Swap(OrderedVector<TYPE>& v1, OrderedVector<TYPE>& v2);
00150 
00151 /*-------------------------------------------------------------*/
00152 /*---- No user serviceable parts after this -------------------*/
00153 
00154 inline void Swap(AbstractOrderedVector& v1, AbstractOrderedVector& v2)
00155 {
00156         v1.Swap(v2);
00157 }
00158 
00159 /*-------------------------------------------------------------*/
00160 
00161 template<class TYPE> inline
00162 OrderedVector<TYPE>::OrderedVector()
00163         :       AbstractOrderedVector(sizeof(TYPE[2])/2)
00164 {
00165 }
00166 
00167 template<class TYPE> inline
00168 OrderedVector<TYPE>::OrderedVector(const OrderedVector<TYPE>& o)
00169         :       AbstractOrderedVector(o)
00170 {
00171 }
00172 
00173 template<class TYPE> inline
00174 OrderedVector<TYPE>::~OrderedVector()
00175 {
00176         MakeEmpty();
00177 }
00178 
00179 template<class TYPE> inline
00180 OrderedVector<TYPE>& OrderedVector<TYPE>::operator=(const OrderedVector<TYPE>& o)
00181 {
00182         AbstractOrderedVector::operator=(o);
00183         return *this;
00184 }
00185 
00186 template<class TYPE> inline
00187 void OrderedVector<TYPE>::SetCapacity(size_t total_space)
00188 {
00189         AbstractVector::SetCapacity(total_space);
00190 }
00191 
00192 template<class TYPE> inline
00193 void OrderedVector<TYPE>::SetExtraCapacity(size_t extra_space)
00194 {
00195         AbstractVector::SetExtraCapacity(extra_space);
00196 }
00197 
00198 template<class TYPE> inline
00199 size_t OrderedVector<TYPE>::Capacity() const
00200 {
00201         return AbstractVector::Capacity();
00202 }
00203 
00204 template<class TYPE> inline
00205 size_t OrderedVector<TYPE>::CountItems() const
00206 {
00207         return AbstractVector::CountItems();
00208 }
00209 
00210 template<class TYPE> inline
00211 const TYPE& OrderedVector<TYPE>::operator[](size_t i) const
00212 {
00213         return *static_cast<const TYPE*>(At(i));
00214 }
00215 
00216 template<class TYPE> inline
00217 const TYPE& OrderedVector<TYPE>::ItemAt(size_t i) const
00218 {
00219         return *static_cast<const TYPE*>(At(i));
00220 }
00221 
00222 template<class TYPE> inline
00223 ssize_t OrderedVector<TYPE>::AddItem(const TYPE& item, bool* added)
00224 {
00225         return AddOrdered(&item, added);
00226 }
00227 
00228 template<class TYPE> inline
00229 ssize_t OrderedVector<TYPE>::IndexOf(const TYPE& item) const
00230 {
00231         return OrderOf(&item);
00232 }
00233 
00234 template<class TYPE> inline
00235 bool OrderedVector<TYPE>::GetIndexOf(const TYPE& item, size_t* index) const
00236 {
00237         return GetOrderOf(&item, index);
00238 }
00239 
00240 template<class TYPE> inline
00241 void OrderedVector<TYPE>::MakeEmpty()
00242 {
00243         AbstractOrderedVector::MakeEmpty();
00244 }
00245 
00246 template<class TYPE> inline
00247 void OrderedVector<TYPE>::RemoveItemsAt(size_t index, size_t count)
00248 {
00249         AbstractOrderedVector::RemoveItemsAt(index, count);
00250 }
00251 
00252 template<class TYPE> inline
00253 ssize_t OrderedVector<TYPE>::RemoveItemFor(const TYPE& item)
00254 {
00255         return RemoveOrdered(&item);
00256 }
00257 
00258 template<class TYPE> inline
00259 void OrderedVector<TYPE>::Swap(OrderedVector<TYPE>& o)
00260 {
00261         AbstractOrderedVector::Swap(o);
00262 }
00263 
00264 template<class TYPE>
00265 void OrderedVector<TYPE>::PerformConstruct(void* base, size_t count) const
00266 {
00267         Construct(static_cast<TYPE*>(base), count);
00268 }
00269 
00270 template<class TYPE>
00271 void OrderedVector<TYPE>::PerformCopy(void* to, const void* from, size_t count) const
00272 {
00273         Copy(static_cast<TYPE*>(to), static_cast<const TYPE*>(from), count);
00274 }
00275 
00276 template<class TYPE>
00277 void OrderedVector<TYPE>::PerformDestroy(void* base, size_t count) const
00278 {
00279         Destroy(static_cast<TYPE*>(base), count);
00280 }
00281 
00282 template<class TYPE>
00283 void OrderedVector<TYPE>::PerformMoveBefore(void* to, void* from, size_t count) const
00284 {
00285         MoveBefore(static_cast<TYPE*>(to), static_cast<TYPE*>(from), count);
00286 }
00287 
00288 template<class TYPE>
00289 void OrderedVector<TYPE>::PerformMoveAfter(void* to, void* from, size_t count) const
00290 {
00291         MoveAfter(static_cast<TYPE*>(to), static_cast<TYPE*>(from), count);
00292 }
00293 
00294 template<class TYPE>
00295 void OrderedVector<TYPE>::PerformAssign(void* to, const void* from, size_t count) const
00296 {
00297         Assign(static_cast<TYPE*>(to), static_cast<const TYPE*>(from), count);
00298 }
00299 
00300 template<class TYPE>
00301 int32_t OrderedVector<TYPE>::PerformCompare(const void* d1, const void* d2) const
00302 {
00303         return Compare(*static_cast<const TYPE*>(d1), *static_cast<const TYPE*>(d2));
00304 }
00305 
00306 template<class TYPE>
00307 bool OrderedVector<TYPE>::PerformLessThan(const void* d1, const void* d2) const
00308 {
00309         return LessThan(*static_cast<const TYPE*>(d1), *static_cast<const TYPE*>(d2));
00310 }
00311 
00312 /*-------------------------------------------------------------*/
00313 
00314 template<class TYPE> inline
00315 void MoveBefore(OrderedVector<TYPE>* to, OrderedVector<TYPE>* from, size_t count)
00316 {
00317         MoveBefore(static_cast<AbstractOrderedVector*>(to), static_cast<AbstractOrderedVector*>(from), count);
00318 }
00319 
00320 template<class TYPE> inline
00321 void MoveAfter(OrderedVector<TYPE>* to, OrderedVector<TYPE>* from, size_t count)
00322 {
00323         MoveAfter(static_cast<AbstractOrderedVector*>(to), static_cast<AbstractOrderedVector*>(from), count);
00324 }
00325 
00326 template<class TYPE> inline
00327 void Swap(OrderedVector<TYPE>& v1, OrderedVector<TYPE>& v2)
00328 {
00329         v1.Swap(v2);
00330 }
00331 
00332 }       // namespace alp
00333 
00334 #endif

Generated on Sat Dec 16 20:29:47 2006 for hiker-0.9 by  doxygen 1.4.4