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

GXPrimitiveLL.h

Go to the documentation of this file.
00001 #ifndef __GXPRIMITIVELL
00002 #define __GXPRIMITIVELL
00003 
00004 #include "GXStandardDefines.h"
00005 
00006 template<typename type>
00007 class CGXPrimitiveLLNode
00008 {
00009 public:
00010         CGXPrimitiveLLNode()
00011         {
00012                 m_pHead=NULL;
00013         }
00014 
00015         ~CGXPrimitiveLLNode()
00016         {
00017                 SAFE_DELETE(m_pHead);
00018         }
00019 
00020 
00021         type                                    m_Data;
00022         CGXPrimitiveLLNode<type>* m_pHead;
00023 };
00024 
00025 
00026 
00027 //type must support bool .Assign(type&)
00028 template<typename type>
00029 class CGXPrimitiveLL
00030 {       
00031 public:
00032         CGXPrimitiveLL()
00033         {
00034                 m_pHead=NULL;
00035                 m_pIteratorCurrent=m_pHead;
00036         }
00037 
00038         ~CGXPrimitiveLL()
00039         {
00040                 SAFE_DELETE(m_pHead);
00041         }
00042 
00043         void IteratorFirst()
00044         {
00045                 m_pIteratorCurrent=m_pHead;
00046         }
00047 
00048         bool IteratorHasMore()
00049         {
00050                 return (m_pIteratorCurrent!=NULL);
00051         }
00052 
00053         bool IteratorNext(type* pOut)
00054         {
00055                 assert(pOut!=NULL);
00056                 if(!IteratorHasMore())
00057                 {
00058                         return false;
00059                 }
00060 
00061                 if(!pOut->Assign(m_pIteratorCurrent->m_Data))
00062                 {
00063                         return false;
00064                 }
00065 
00066                 m_pIteratorCurrent=m_pIteratorCurrent->m_pHead;
00067 
00068                 return true;
00069         }
00070 
00071         //todo auto array here
00072         bool AddElement(type* pIn)
00073         {
00074                 assert(pIn!=NULL);
00075                 
00076                 CGXPrimitiveLLNode<type>* pNew=new CGXPrimitiveLLNode<type>;
00077                 if(!pNew)
00078                 {
00079                         return false;
00080                 }
00081 
00082                 if(!pNew->m_Data.Assign(*pIn))
00083                 {
00084                         delete pNew;
00085                         return false;
00086                 }
00087 
00088 
00089                 pNew->m_pHead=m_pHead;
00090                 IteratorFirst();
00091                 return true;
00092         }
00093         
00094 
00095 protected:
00096         CGXPrimitiveLLNode<type>* m_pHead;
00097         CGXPrimitiveLLNode<type>* m_pIteratorCurrent;
00098 };
00099 
00100 #endif

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