changed: update version strings for beta4
[xbmc.git] / xbmc / utils / AutoPtrHandle.cpp
blob999ba3dba868a620229e1e3c5b51805855a82fc1
1 /*
2 * Copyright (C) 2005-2008 Team XBMC
3 * http://www.xbmc.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * 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 XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #include "AutoPtrHandle.h"
24 using namespace AUTOPTR;
26 CAutoPtrHandle::CAutoPtrHandle(HANDLE hHandle)
27 : m_hHandle(hHandle)
30 CAutoPtrHandle::~CAutoPtrHandle(void)
32 Cleanup();
35 CAutoPtrHandle::operator HANDLE()
37 return m_hHandle;
40 void CAutoPtrHandle::attach(HANDLE hHandle)
42 Cleanup();
43 m_hHandle = hHandle;
46 HANDLE CAutoPtrHandle::release()
48 HANDLE hTmp = m_hHandle;
49 m_hHandle = INVALID_HANDLE_VALUE;
50 return hTmp;
53 void CAutoPtrHandle::Cleanup()
55 if ( isValid() )
57 CloseHandle(m_hHandle);
58 m_hHandle = INVALID_HANDLE_VALUE;
62 bool CAutoPtrHandle::isValid() const
64 if ( INVALID_HANDLE_VALUE != m_hHandle)
65 return true;
66 return false;
68 void CAutoPtrHandle::reset()
70 Cleanup();
73 //-------------------------------------------------------------------------------
74 CAutoPtrFind ::CAutoPtrFind(HANDLE hHandle)
75 : CAutoPtrHandle(hHandle)
77 CAutoPtrFind::~CAutoPtrFind(void)
79 Cleanup();
82 void CAutoPtrFind::Cleanup()
84 if ( isValid() )
86 FindClose(m_hHandle);
87 m_hHandle = INVALID_HANDLE_VALUE;
91 //-------------------------------------------------------------------------------
92 CAutoPtrSocket::CAutoPtrSocket(SOCKET hSocket)
93 : m_hSocket(hSocket)
96 CAutoPtrSocket::~CAutoPtrSocket(void)
98 Cleanup();
101 CAutoPtrSocket::operator SOCKET()
103 return m_hSocket;
106 void CAutoPtrSocket::attach(SOCKET hSocket)
108 Cleanup();
109 m_hSocket = hSocket;
112 SOCKET CAutoPtrSocket::release()
114 SOCKET hTmp = m_hSocket;
115 m_hSocket = INVALID_SOCKET;
116 return hTmp;
119 void CAutoPtrSocket::Cleanup()
121 if ( isValid() )
123 closesocket(m_hSocket);
124 m_hSocket = INVALID_SOCKET;
128 bool CAutoPtrSocket::isValid() const
130 if ( INVALID_SOCKET != m_hSocket)
131 return true;
132 return false;
134 void CAutoPtrSocket::reset()
136 Cleanup();