vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / media / plugins / ape_reader / MAClib / SmartPtr.h
blobebf3a443491a2a88ab7f486cd3aa70129772ac4a
1 #ifndef APE_SMARTPTR_H
2 #define APE_SMARTPTR_H
4 // disable the operator -> on UDT warning
5 #ifdef _MSC_VER
6 #pragma warning(push)
7 #pragma warning(disable : 4284)
8 #endif
10 #include "NoWindows.h"
12 /*************************************************************************************************
13 CSmartPtr - a simple smart pointer class that can automatically initialize and free memory
14 note: (doesn't do garbage collection / reference counting because of the many pitfalls)
15 *************************************************************************************************/
16 template <class TYPE> class CSmartPtr
18 public:
19 TYPE * m_pObject;
20 BOOL m_bArray;
21 BOOL m_bDelete;
23 CSmartPtr()
25 m_bDelete = TRUE;
26 m_pObject = NULL;
28 CSmartPtr(TYPE * a_pObject, BOOL a_bArray = FALSE, BOOL a_bDelete = TRUE)
30 m_bDelete = TRUE;
31 m_pObject = NULL;
32 Assign(a_pObject, a_bArray, a_bDelete);
35 ~CSmartPtr()
37 Delete();
40 void Assign(TYPE * a_pObject, BOOL a_bArray = FALSE, BOOL a_bDelete = TRUE)
42 Delete();
44 m_bDelete = a_bDelete;
45 m_bArray = a_bArray;
46 m_pObject = a_pObject;
49 void Delete()
51 if (m_bDelete && m_pObject)
53 if (m_bArray)
54 delete [] m_pObject;
55 else
56 delete m_pObject;
58 m_pObject = NULL;
62 void SetDelete(const BOOL a_bDelete)
64 m_bDelete = a_bDelete;
67 __inline TYPE * GetPtr() const
69 return m_pObject;
72 __inline operator TYPE * () const
74 return m_pObject;
77 __inline TYPE * operator ->() const
79 return m_pObject;
82 // declare assignment, but don't implement (compiler error if we try to use)
83 // that way we can't carelessly mix smart pointers and regular pointers
84 __inline void * operator =(void *) const;
87 #ifdef _MSC_VER
88 #pragma warning(pop)
89 #endif // _MSC_VER
91 #endif // #ifndef APE_SMARTPTR_H