1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * A simplified analog to std::auto_ptr<> that encapsulates
23 * an array allocated dynamically via new[].
25 * Use this where you could not use a std::auto_ptr<> (works
26 * for single elements only) nor a std::vector<> (no guarantees
27 * w.r.t. to internal organization, i.e. no access to mem buffer).
37 /// no copy nor assignment
39 auto_buffer(const auto_buffer
&);
40 auto_buffer
& operator=(const auto_buffer
&);
44 explicit auto_buffer (size_t size
= 0) throw()
45 : buffer (size
== 0 ? NULL
: new T
[size
]())
54 operator T
*() const throw()
59 operator void*() const throw()
64 operator bool() const throw()
66 return buffer
!= NULL
;
69 T
* operator->() const throw()
74 T
*get() const throw()
86 void reset (size_t newSize
= 0)
89 buffer
= (newSize
== 0 ? NULL
: new T
[newSize
]);