Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

list.cpp

Go to the documentation of this file.
00001 // 00002 // CDPA - Shell like DPA stuff 00003 // 00004 // FelixA 00005 // 00006 00007 #include "pch.h" 00008 #include "list.h" 00009 00011 // 00012 // 00013 CDPA::CDPA() 00014 : m_iAllocated(0), 00015 m_iCurrentTop(0), 00016 m_pData(NULL), 00017 m_Heap(NULL) //Allocate from global heap. 00018 { 00019 } 00020 00021 CDPA::~CDPA() 00022 { 00023 LPVOID lpV; 00024 int i=0; 00025 while( lpV=GetPointer(i++) ) 00026 delete lpV; 00027 00028 // 00029 // BugBug - you must delete all the data that we allocated in the list 00030 // 00031 if(GetData()) 00032 HeapFree(GetHeap(), 0, GetData()); 00033 } 00034 00036 // 00037 // Inserts at the end - no mechanism for inserting in the middle. 00038 // Grows the Heap if you add more items than currently have spave for 00039 // 00040 BOOL CDPA::Append(LPVOID lpData) 00041 { 00042 if(GetNextFree()==GetAllocated()) 00043 { 00044 int iNewSize = GetAllocated()+32; // Grow in 32 allocations; 00045 void FAR * FAR * ppNew; 00046 00047 if(GetData()) 00048 ppNew = (void FAR * FAR *)HeapReAlloc(GetHeap(), HEAP_ZERO_MEMORY, GetData(), iNewSize * sizeof(LPVOID)); 00049 else 00050 { 00051 if(!GetHeap()) 00052 SetHeap(HeapCreate(0,0x4000,0)); 00053 ppNew = (void FAR * FAR *)HeapAlloc(GetHeap(), HEAP_ZERO_MEMORY, iNewSize * sizeof(LPVOID)); 00054 } 00055 00056 SetData(ppNew); 00057 if(ppNew) 00058 { 00059 SetAllocated(iNewSize); 00060 } 00061 else 00062 return FALSE; 00063 } 00064 00065 *(GetData()+GetNextFree())=lpData; 00066 SetNextFree(GetNextFree()+1); 00067 return TRUE; 00068 } 00069 00071 // 00072 // Given the index into the list, returns its value. 00073 // 00074 LPVOID CDPA::GetPointer(int iItem) const 00075 { 00076 if(GetData()) 00077 if(iItem<GetAllocated()) // mCurrentTop is not active. 00078 return *(GetData()+iItem); 00079 return NULL; 00080 } 00081 00082 int CDPA::GetCount() 00083 { 00084 return GetNextFree(); 00085 } 00086 00087 void CDPA::Remove(int iItem) 00088 { 00089 if(GetData()) 00090 if(iItem<GetAllocated()) // mCurrentTop is not active. 00091 *(GetData()+iItem)=NULL; 00092 }

Generated on Sat May 15 19:40:38 2004 for test by doxygen 1.3.7