Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

IMG_MemPtr.h

00001 
00005 
00006 #ifndef _H_IMG_MemPtr
00007 #define _H_IMG_MemPtr
00008 
00009 #include <stddef.h>
00010 
00017 
00018 template <class T> class IMG_MemPtr {
00019 public:
00021         T* m_p;
00022         bool m_owned;
00023 
00028         class Size {};
00033         class Memory {};
00034 
00041         IMG_MemPtr(size_t s)
00042                 : m_p(0), m_owned(false)
00043         {
00044                 if (s > 0) {
00045                         m_p = new T[s];
00046                         if (!m_p) {
00047                                 throw Memory();
00048                         }
00049                         m_owned = true;
00050                 }
00051                 else {
00052                         throw Size();
00053                 }
00054         }
00055 
00062         IMG_MemPtr(void* p, size_t s)
00063                 : m_p(0), m_owned(false)
00064         {
00065                 if (p && (s > 0)) {
00066                         m_p = (T*)p;
00067                 }
00068                 else {
00069                         throw Size();
00070                 }
00071         }
00072 
00076         ~IMG_MemPtr() { if (m_p && m_owned) { delete [] m_p; m_p = 0; } }
00077 
00082         operator T*() { return m_p; }
00083 };
00084 
00085 #endif // _H_IMG_MemPtr

Generated at Thu May 3 17:29:38 2001 for ImgLib by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000