Hauptseite   Klassenhierarchie   Übersicht   Auflistung der Dateien   Datenstruktur-Elemente   Datei-Elemente  

data_holder.h

gehe zur Dokumentation dieser Datei
00001 
00014 #ifndef __DATA_HOLDER_H__
00015 #define __DATA_HOLDER_H__
00016 
00017 #include <exception.h>
00018 
00019 #include <assert.h>
00020 #include <stdlib.h>
00021 
00027 template <class ItemType> class DataHolder {
00028  public:
00033   DataHolder(unsigned long size) throw (NotEnoughMemoryException) 
00034       : last(0), size(size) {
00035     pool= (ItemType *)malloc(size * sizeof(ItemType));
00036     
00037     if (pool == NULL) {
00038       throw new NotEnoughMemoryException();
00039     }
00040   }
00041 
00045   virtual ~DataHolder() {
00046     free(pool);
00047   }
00048 
00054   virtual ItemType get()= 0;
00055 
00060   virtual bool isEmpty()= 0;
00061 
00067   virtual bool isFull()= 0;
00068 
00074   inline void put(ItemType item) {
00075     assert (!isFull());
00076     
00077     pool[last]= item;
00078     last= (last + 1) % getSize();
00079   }
00080 
00081  protected:  
00086   inline unsigned long getSize() {
00087     return size;
00088   }
00089   
00093   unsigned long last;
00094  
00098   ItemType* pool;
00099 
00100  private: 
00104   unsigned long size;
00105 
00106 };
00107 
00108 #endif // ! __DATA_HOLDER_H__

Erzeugt am Fri Mar 14 19:44:50 2003 für cad2octree von doxygen1.2.16