Prevent the recycle bin from even getting monitored
[TortoiseGit.git] / src / Utils / auto_buffer.h
blob050b36b0fdb610c150f71f32e59768c59abe1a74
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.
19 #pragma once
21 /**
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).
30 template<class T>
31 class auto_buffer
33 private:
35 T* buffer;
37 /// no copy nor assignment
39 auto_buffer(const auto_buffer&);
40 auto_buffer& operator=(const auto_buffer&);
42 public:
44 explicit auto_buffer (size_t size = 0) throw()
45 : buffer (size == 0 ? NULL : new T[size]())
49 ~auto_buffer()
51 delete[] buffer;
54 operator T*() const throw()
56 return buffer;
59 operator void*() const throw()
61 return buffer;
64 operator bool() const throw()
66 return buffer != NULL;
69 T* operator->() const throw()
71 return buffer;
74 T *get() const throw()
76 return buffer;
79 T* release() throw()
81 T* temp = buffer;
82 buffer = NULL;
83 return temp;
86 void reset (size_t newSize = 0)
88 delete[] buffer;
89 buffer = (newSize == 0 ? NULL : new T[newSize]);