00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _ADAPT_H_
00029 #define _ADAPT_H_
00030
00037 namespace HL {
00038
00039 template <class Dictionary, class SuperHeap>
00040 class AdaptHeap : public SuperHeap {
00041 public:
00042
00044 inline void * malloc (const size_t) {
00045 void * ptr = (Entry *) dict.get();
00046 return ptr;
00047 }
00048
00050 inline void free (void * ptr) {
00051 Entry * entry = (Entry *) ptr;
00052 dict.insert (entry);
00053 }
00054
00056 inline int remove (void * ptr) {
00057 dict.remove ((Entry *) ptr);
00058 return 1;
00059 }
00060
00062 inline void clear (void) {
00063 Entry * ptr;
00064 while ((ptr = (Entry *) dict.get()) != NULL) {
00065 SuperHeap::free (ptr);
00066 }
00067 dict.clear();
00068 SuperHeap::clear();
00069 }
00070
00071
00072 private:
00073
00075 Dictionary dict;
00076
00077 class Entry : public Dictionary::Entry {};
00078 };
00079
00080 }
00081
00082 #endif // _ADAPT_H_