4 * Copyright (C) 2005-2008 Team XBMC
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This Program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with XBMC; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 * http://www.gnu.org/copyleft/gpl.html
24 #include "system.h" // for HANDLE and SOCKET
31 CAutoPtrHandle(HANDLE hHandle
);
32 virtual ~CAutoPtrHandle(void);
34 void attach(HANDLE hHandle
);
39 virtual void Cleanup();
43 class CAutoPtrFind
: public CAutoPtrHandle
46 CAutoPtrFind(HANDLE hHandle
);
47 virtual ~CAutoPtrFind(void);
49 virtual void Cleanup();
56 CAutoPtrSocket(SOCKET hSocket
);
57 virtual ~CAutoPtrSocket(void);
59 void attach(SOCKET hSocket
);
64 virtual void Cleanup();
69 * This template class is very similar to the standard "auto_ptr", but it is
70 * used for *array* pointers rather than *object* pointers, i.e. the pointer
71 * passed to it must have been allocated with "new[]", and "auto_aptr" will
72 * delete it with "delete[]".
74 * Class released under GPL and was taken from:
75 * http://userpage.fu-berlin.de/~mbayer/tools/html2text.html
83 // Constructor/copy/destroy
85 explicit auto_aptr(T
*x
= 0) : p(x
) {}
86 auto_aptr(const auto_aptr
<T
> &x
) : p(x
.p
) { ((auto_aptr
<T
> *) &x
)->p
= 0; }
87 auto_aptr
<T
>& operator=(const auto_aptr
<T
> &x
)
88 { delete[] p
; p
= x
.p
; ((auto_aptr
<T
> *) &x
)->p
= 0; return *this; }
89 // Extension: "operator=(T *)" is identical to "auto_aptr::reset(T *)".
90 void operator=(T
*x
) { delete[] p
; p
= x
; }
91 ~auto_aptr() { delete[] p
; }
95 T
&operator[](size_t idx
) const { if (!p
) abort(); return p
[idx
]; }
96 T
*get() const { return (T
*) p
; }
97 T
*release() { T
*tmp
= p
; p
= 0; return tmp
; }
98 void reset(T
*x
= 0) { delete[] p
; p
= x
; }
100 // These would make a nice extension, but are not provided by many other
102 //operator const void *() const { return p; }
103 //int operator!() const { return p == 0; }