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 #ifdef __cplusplus
22 namespace P6R {
23 
34  template<typename T> class p6ScopedArray
35  {
36  public:
37  typedef T element_type;
38 
39  explicit p6ScopedArray(T *ptr=0) : m_ptr(ptr)
40  {}
41 
43  {
52  typedef char ensure_type_is_complete[sizeof(T)];
53  delete [] m_ptr;
54  }
55 
56  operator T*() {
57  return static_cast<T*>(m_ptr);
58  }
59 
63  inline T* get() const
64  { return m_ptr; }
65 
70  {
71  T* pTmp = b.m_ptr;
72  b.m_ptr = m_ptr;
73  m_ptr = pTmp;
74  }
75 
83  T* release()
84  {
85  T* pTmp = m_ptr;
86  m_ptr = NULL;
87  return pTmp;
88  }
89 
96  void reset(T *p=0)
97  {
98  if(m_ptr != p) {
99  delete [] m_ptr;
100  m_ptr = p;
101  }
102  }
103 
104  private:
105  T *m_ptr;
106 
107  private:
108  p6ScopedArray(p6ScopedArray const &);
109  p6ScopedArray & operator=(p6ScopedArray const &);
110  void operator==(p6ScopedArray const&) const;
111  void operator!=(p6ScopedArray const&) const;
112  };
113 } // namespace
114 #endif // __cplusplus
115 #endif
116 
T * release()
Return the wrapped raw pointer and give up ownership.
Definition: p6scopedarray.h:83
Threading interfaces and definitions.
Standard error codes.
P6VOID swap(p6ScopedArray &b)
Exchange ownership with another p6ScopedArray.
Definition: p6scopedarray.h:69
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:96
A simple smart pointer that stores a pointer to an dynamically allocated array (allocated via new) an...
Definition: p6scopedarray.h:34
P6COM runtime interfaces definitions.
p6ScopedArray(T *ptr=0)
Definition: p6scopedarray.h:39
void P6VOID
Definition: p6types.h:109