Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

GXVectorArray.h

Go to the documentation of this file.
00001 #ifndef __GXVECTORARRAY
00002 #define __GXVECTORARRAY
00003 
00004 
00005 #include "GXSizeableArray.h"
00006 
00007 inline void GXBoolZeroer(bool* pBool)
00008 {
00009         assert(pBool);
00010         *pBool=false;
00011 }
00012 
00013 
00014 //todo, refactor using this baby
00015 template <typename type>
00016 class CGXVectorArray
00017 {
00018 public:
00019         CGXVectorArray()
00020         {
00021                 m_BitArray.SetInitCallback(GXBoolZeroer);
00022         }
00023 
00024         ~CGXVectorArray()
00025         {
00026                 Cleanup();
00027         }
00028         
00029         //optional, does not need to be called
00030         void Cleanup()
00031         {
00032                 m_ElementArray.Cleanup();
00033                 m_BitArray.Cleanup();
00034         }
00035 
00036         inline UINT GetElementCount()
00037         {
00038                 return m_ElementArray.GetElementCount();
00039         }
00040 
00041 
00042         inline void SetInitCallback(void (*pCallback)(type*))
00043         {
00044                 m_ElementArray.SetInitCallback(pCallback);
00045         }
00046 
00047         inline bool GetElementAt(UINT uIndex, type* pOut)
00048         {
00049                 bool bBit=m_BitArray.GetElementAt(uIndex);
00050                 if(!bBit)
00051                 {
00052                         return false;
00053                 }
00054 
00055                 *pOut=m_ElementArray.GetElementAt(uIndex);
00056                 return true;
00057         }
00058 
00059         //-1 on error, else the index
00060         int InsertElement(type& NewElement)
00061         {
00062                 UINT uCtr;
00063 
00064                 for(uCtr=0;uCtr<m_BitArray.GetElementCount();uCtr++)
00065                 {
00066                         bool bCurrentVal=m_BitArray.GetElementAt(uCtr);
00067                         if(!bCurrentVal)
00068                         {
00069                                 if(!m_ElementArray.SetElementAt(&NewElement, uCtr))
00070                                 {
00071                                         return -1;
00072                                 }
00073 
00074                                 bCurrentVal=true;
00075                                 if(!m_BitArray.SetElementAt(&bCurrentVal, uCtr))
00076                                 {
00077                                         return -1;
00078                                 }
00079                                 return (int)uCtr;       
00080                         }
00081                 }
00082 
00083                 if(!m_ElementArray.InsertElement(uCtr, NewElement))
00084                 {
00085                         return -1;
00086                 }
00087 
00088                 bool bNewVal=true;
00089                 if(!m_BitArray.InsertElement(uCtr, bNewVal))
00090                 {
00091                         return -1;
00092                 }
00093 
00094                 return (int) uCtr;
00095         }
00096 
00097 
00098         bool DeleteElement(UINT uIndex)
00099         {
00100                 if(uIndex>=m_ElementArray.GetElementCount())
00101                 {
00102                         return false;
00103                 }
00104 
00105                 bool bCurrent=m_BitArray.GetElementAt(uIndex);
00106 
00107                 if(!bCurrent)
00108                 {
00109                         return false;
00110                 }
00111 
00112                 bCurrent=false;
00113 
00114                 if(!m_BitArray.SetElementAt(&bCurrent, uIndex))
00115                 {
00116                         return false;
00117                 }
00118 
00119 
00120                 return true;
00121         }
00122 
00123 
00124         bool ChangeElement(UINT uIndex, type* pIn)
00125         {
00126                 bool bBit=m_BitArray.GetElementAt(uIndex);
00127 
00128                 if(!bBit)
00129                 {
00130                         return false;
00131                 }
00132 
00133                 return m_ElementArray.SetElementAt(pIn, uIndex);
00134         }
00135                         
00136 
00137 
00138 
00139 private:
00140         CGXSizeableArray<type>  m_ElementArray;
00141         CGXSizeableArray<bool>  m_BitArray;
00142 
00143 };
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 #endif

Generated on Thu May 23 17:51:00 2002 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001