Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
p6scopedarray.h
Go to the documentation of this file.
1 
12 #ifndef P6SCOPEDARRAY_H__
13 #define P6SCOPEDARRAY_H__ 1
14 
15 #include "p6err.h"
16 #include "p6runtimeif.h"
17 #include "p6log.h"
18 #include "p6thread.h"
19 #include "p6runtimeapi.h"
21 namespace P6R {
22 
33  template<typename T> class p6ScopedArray
34  {
35  public:
36  typedef T element_type;
37 
38  explicit p6ScopedArray(T *ptr=0) : m_ptr(ptr)
39  {}
40 
42  {
51  typedef char ensure_type_is_complete[sizeof(T)];
52  delete [] m_ptr;
53  }
54 
55  operator T*() {
56  return static_cast<T*>(m_ptr);
57  }
58 
60  {
61  P6ASSERT(i >= 0);
62  P6ASSERT(NULL != m_ptr);
63  return m_ptr[i];
64  }
65 
69  inline T* get() const
70  { return m_ptr; }
71 
76  {
77  T* pTmp = b.m_ptr;
78  b.m_ptr = m_ptr;
79  m_ptr = pTmp;
80  }
81 
89  T* release()
90  {
91  T* pTmp = m_ptr;
92  m_ptr = NULL;
93  return pTmp;
94  }
95 
102  void reset(T *p=0)
103  {
104  if(m_ptr != p) {
105  delete [] m_ptr;
106  m_ptr = p;
107  }
108  }
109 
110  private:
111  T *m_ptr;
112 
113  private:
114  p6ScopedArray(p6ScopedArray const &);
115  p6ScopedArray & operator=(p6ScopedArray const &);
116  void operator==(p6ScopedArray const&) const;
117  void operator!=(p6ScopedArray const&) const;
118  };
119 } // namespace
120 
121 #endif
122 
std::ptrdiff_t P6PTRDIFF
Definition: p6types.h:64
P6R::P6ERR(* P6ASSERT)(const P6R::P6WCHAR *pszExpr, const P6R::P6CHAR *pszFile, P6R::P6UINT32 nLine)
Definition: p6dllapi.h:57
T * release()
Return the wrapped raw pointer and give up ownership.
Definition: p6scopedarray.h:89
Threading interfaces and definitions.
Standard error codes.
P6VOID swap(p6ScopedArray &b)
Exchange ownership with another p6ScopedArray.
Definition: p6scopedarray.h:75
P6COM runtime interfaces definitions.
Log producer component interfaces.
void reset(T *p=0)
Destroy any existing owned array, then take ownership of the array pointed to by p argument...
A simple smart pointer that stores a pointer to an dynamically allocated array (allocated via new) an...
Definition: p6scopedarray.h:33
P6COM runtime interfaces definitions.
T & operator[](P6PTRDIFF i)
Definition: p6scopedarray.h:59
p6ScopedArray(T *ptr=0)
Definition: p6scopedarray.h:38
void P6VOID
Definition: p6types.h:75