1 // Copyright 2010 Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /// \file utils/auto_array.hpp
30 /// Provides the utils::auto_array class.
32 /// The class is provided as a separate module on its own to minimize
33 /// header-inclusion side-effects.
35 #if !defined(UTILS_AUTO_ARRAY_HPP)
36 #define UTILS_AUTO_ARRAY_HPP
43 template< class > class auto_array
;
49 /// Wrapper class to provide reference semantics for utils::auto_array.
51 /// This class is internally used, for example, to allow returning a
52 /// utils::auto_array from a function.
54 class auto_array_ref
{
55 /// Internal pointer to the dynamically-allocated array.
58 template< class > friend class utils::auto_array
;
61 explicit auto_array_ref(T
*);
68 /// A simple smart pointer for arrays providing strict ownership semantics.
70 /// This class is the counterpart of std::auto_ptr for arrays. The semantics of
71 /// the API of this class are the same as those of std::auto_ptr.
73 /// The wrapped pointer must be NULL or must have been allocated using operator
77 /// Internal pointer to the dynamically-allocated array.
81 auto_array(T
* = NULL
) throw();
82 auto_array(auto_array
< T
>&) throw();
83 auto_array(detail::auto_array_ref
< T
>) throw();
84 ~auto_array(void) throw();
87 const T
* get(void) const throw();
89 T
* release(void) throw();
90 void reset(T
* = NULL
) throw();
92 auto_array
< T
>& operator=(auto_array
< T
>&) throw();
93 auto_array
< T
>& operator=(detail::auto_array_ref
< T
>) throw();
94 T
& operator[](int) throw();
95 const T
& operator[](int) const throw();
96 operator detail::auto_array_ref
< T
>(void) throw();
103 #endif // !defined(UTILS_AUTO_ARRAY_HPP)