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 
62  inline T* get() const
63  { return m_ptr; }
64 
69  {
70  T* pTmp = b.m_ptr;
71  b.m_ptr = m_ptr;
72  m_ptr = pTmp;
73  }
74 
82  T* release()
83  {
84  T* pTmp = m_ptr;
85  m_ptr = NULL;
86  return pTmp;
87  }
88 
95  void reset(T *p=0)
96  {
97  if(m_ptr != p) {
98  delete [] m_ptr;
99  m_ptr = p;
100  }
101  }
102 
103  private:
104  T *m_ptr;
105 
106  private:
107  p6ScopedArray(p6ScopedArray const &);
108  p6ScopedArray & operator=(p6ScopedArray const &);
109  void operator==(p6ScopedArray const&) const;
110  void operator!=(p6ScopedArray const&) const;
111  };
112 } // namespace
113 
114 #endif
115 
T * release()
Return the wrapped raw pointer and give up ownership.
Definition: p6scopedarray.h:82
Threading interfaces and definitions.
Standard error codes.
P6VOID swap(p6ScopedArray &b)
Exchange ownership with another p6ScopedArray.
Definition: p6scopedarray.h:68
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...
Definition: p6scopedarray.h:95
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.
p6ScopedArray(T *ptr=0)
Definition: p6scopedarray.h:38
void P6VOID
Definition: p6types.h:75