Drop main() prototype. Syncs with NetBSD-8
[minix.git] / external / bsd / atf / dist / atf-c++ / detail / auto_array.hpp
blob1459284e3b6744740a0bfc8cb0d4495bda250711
1 //
2 // Automated Testing Framework (atf)
3 //
4 // Copyright (c) 2007 The NetBSD Foundation, Inc.
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #if !defined(_ATF_CXX_AUTO_ARRAY_HPP_)
31 #define _ATF_CXX_AUTO_ARRAY_HPP_
33 #include <cstddef>
35 namespace atf {
37 // ------------------------------------------------------------------------
38 // The "auto_array" class.
39 // ------------------------------------------------------------------------
41 template< class T >
42 struct auto_array_ref {
43 T* m_ptr;
45 explicit auto_array_ref(T*);
48 template< class T >
49 auto_array_ref< T >::auto_array_ref(T* ptr) :
50 m_ptr(ptr)
54 template< class T >
55 class auto_array {
56 T* m_ptr;
58 public:
59 auto_array(T* = NULL) throw();
60 auto_array(auto_array< T >&) throw();
61 auto_array(auto_array_ref< T >) throw();
62 ~auto_array(void) throw();
64 T* get(void) throw();
65 const T* get(void) const throw();
66 T* release(void) throw();
67 void reset(T* = NULL) throw();
69 auto_array< T >& operator=(auto_array< T >&) throw();
70 auto_array< T >& operator=(auto_array_ref< T >) throw();
72 T& operator[](int) throw();
73 operator auto_array_ref< T >(void) throw();
76 template< class T >
77 auto_array< T >::auto_array(T* ptr)
78 throw() :
79 m_ptr(ptr)
83 template< class T >
84 auto_array< T >::auto_array(auto_array< T >& ptr)
85 throw() :
86 m_ptr(ptr.release())
90 template< class T >
91 auto_array< T >::auto_array(auto_array_ref< T > ref)
92 throw() :
93 m_ptr(ref.m_ptr)
97 template< class T >
98 auto_array< T >::~auto_array(void)
99 throw()
101 if (m_ptr != NULL)
102 delete [] m_ptr;
105 template< class T >
107 auto_array< T >::get(void)
108 throw()
110 return m_ptr;
113 template< class T >
114 const T*
115 auto_array< T >::get(void)
116 const throw()
118 return m_ptr;
121 template< class T >
123 auto_array< T >::release(void)
124 throw()
126 T* ptr = m_ptr;
127 m_ptr = NULL;
128 return ptr;
131 template< class T >
132 void
133 auto_array< T >::reset(T* ptr)
134 throw()
136 if (m_ptr != NULL)
137 delete [] m_ptr;
138 m_ptr = ptr;
141 template< class T >
142 auto_array< T >&
143 auto_array< T >::operator=(auto_array< T >& ptr)
144 throw()
146 reset(ptr.release());
147 return *this;
150 template< class T >
151 auto_array< T >&
152 auto_array< T >::operator=(auto_array_ref< T > ref)
153 throw()
155 if (m_ptr != ref.m_ptr) {
156 delete [] m_ptr;
157 m_ptr = ref.m_ptr;
159 return *this;
162 template< class T >
164 auto_array< T >::operator[](int pos)
165 throw()
167 return m_ptr[pos];
170 template< class T >
171 auto_array< T >::operator auto_array_ref< T >(void)
172 throw()
174 return auto_array_ref< T >(release());
177 } // namespace atf
179 #endif // !defined(_ATF_CXX_AUTO_ARRAY_HPP_)