1 #ifndef MMANAGER_H_INCLUDED
\r
2 #define MMANAGER_H_INCLUDED
\r
9 static IMMObject * liveObjects;
\r
10 static IMMObject * deadObjects;
\r
11 IMMObject *nextObject;
\r
12 IMMObject *prevObject;
\r
14 bool bIsStackAllocated;
\r
15 static std::list<IMMObject*> heapObjects;
\r
18 virtual ~IMMObject();
\r
22 static void CollectGarbage();
\r
23 static void CollectRemainingObjects(bool bEmitWarnings=false);
\r
24 virtual unsigned long size()=0;
\r
25 void *operator new(size_t size);
\r
26 void operator delete(void* obj);
\r
29 #define AUTO_SIZE unsigned long size(){return sizeof(*this);}
\r
37 CMMPointer(){obj=0;}
\r
38 CMMPointer(T *o){obj=0; *this=o;}
\r
39 CMMPointer(const CMMPointer<T> &p){obj=0; *this=p;}
\r
41 ~CMMPointer(){if(obj)obj->Release();}
\r
43 inline void operator =(const CMMPointer<T> &p)
\r
45 if(obj)obj->Release();
\r
47 if(obj)obj->AddRef();
\r
49 inline void operator =(T* o)
\r
51 if(obj)obj->Release();
\r
53 if(obj)obj->AddRef();
\r
56 inline T& operator *() const
\r
58 assert(obj!=0 && "Tried to * a NULL smart pointer");
\r
62 inline T* operator ->() const
\r
64 assert(obj!=0 && "Tried to -> on a NULL smart pointer");
\r
68 inline operator T*() const
\r
73 inline bool operator !(){return !(obj);}
\r
75 inline bool isValid() const
\r
78 inline bool operator ==(const CMMPointer<T> &p) const
\r
80 return (obj==p.obj);
\r
82 inline bool operator ==(const T* o) const
\r
88 template<class T, int i>
\r
89 class CMMBlob : public IMMObject
\r
94 inline T& operator [](int index){assert(index<i); return buffer[index];}
\r
95 inline operator T*(){return buffer;}
\r
100 class CMMDynamicBlob : public IMMObject
\r
103 unsigned long dataSize;
\r
106 inline T& operator [](int index){assert(index<dataSize); return buffer[index];}
\r
107 inline operator T*(){return buffer;}
\r
108 CMMDynamicBlob(unsigned long size){dataSize=size; buffer=new T[size]; }
\r
109 ~CMMDynamicBlob(){if(buffer)delete[] buffer;}
\r
110 unsigned long size(){return dataSize*sizeof(T) + sizeof(this); }
\r
111 unsigned long blobsize(){return dataSize;}
\r