ReactOS  0.4.15-dev-985-gd905dd5
auto_array_ptr.h
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Automatic Testing Utility
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Template similar to std::auto_ptr for arrays
5  * COPYRIGHT: Copyright 2009 Colin Finck (colin@reactos.org)
6  */
7 
8 template<typename Type>
10 {
11 private:
13 
14 public:
15  typedef Type element_type;
16 
17  /* Construct an auto_array_ptr from a pointer */
18  explicit auto_array_ptr(Type* Ptr = 0) throw()
19  : m_Ptr(Ptr)
20  {
21  }
22 
23  /* Construct an auto_array_ptr from an existing auto_array_ptr */
25  : m_Ptr(Right.release())
26  {
27  }
28 
29  /* Destruct the auto_array_ptr and remove the corresponding array from memory */
30  ~auto_array_ptr() throw()
31  {
32  delete[] m_Ptr;
33  }
34 
35  /* Get the pointer address */
36  Type* get() const throw()
37  {
38  return m_Ptr;
39  }
40 
41  /* Release the pointer */
42  Type* release() throw()
43  {
44  Type* Tmp = m_Ptr;
45  m_Ptr = 0;
46 
47  return Tmp;
48  }
49 
50  /* Reset to a new pointer */
51  void reset(Type* Ptr = 0) throw()
52  {
53  if(Ptr != m_Ptr)
54  delete[] m_Ptr;
55 
56  m_Ptr = Ptr;
57  }
58 
59  /* Simulate all the functionality of real arrays by casting the auto_array_ptr to Type* on demand */
60  operator Type*() const throw()
61  {
62  return m_Ptr;
63  }
64 };
auto_array_ptr(Type *Ptr=0)
Type
Definition: Type.h:6
Type * get() const
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
Type * release()
void reset(Type *Ptr=0)
auto_array_ptr(auto_array_ptr< Type > &Right)