Big testing system commit
[reactos.git] / rostests / rosautotest / auto_array_ptr.h
1 /*
2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
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>
9 class auto_array_ptr
10 {
11 private:
12 Type* m_Ptr;
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 */
24 auto_array_ptr(auto_array_ptr<Type>& Right) throw()
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 };