Merge pull request #4676 from jmarshallnz/dont_set_scraper_on_tvshow_on_nfo
[vuplus_xbmc] / xbmc / utils / AutoPtrHandle.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
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.
9  *
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.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "AutoPtrHandle.h"
22
23 using namespace AUTOPTR;
24
25 CAutoPtrHandle::CAutoPtrHandle(HANDLE hHandle)
26     : m_hHandle(hHandle)
27 {}
28
29 CAutoPtrHandle::~CAutoPtrHandle(void)
30 {
31   Cleanup();
32 }
33
34 CAutoPtrHandle::operator HANDLE()
35 {
36   return m_hHandle;
37 }
38
39 void CAutoPtrHandle::attach(HANDLE hHandle)
40 {
41   Cleanup();
42   m_hHandle = hHandle;
43 }
44
45 HANDLE CAutoPtrHandle::release()
46 {
47   HANDLE hTmp = m_hHandle;
48   m_hHandle = INVALID_HANDLE_VALUE;
49   return hTmp;
50 }
51
52 void CAutoPtrHandle::Cleanup()
53 {
54   if ( isValid() )
55   {
56     CloseHandle(m_hHandle);
57     m_hHandle = INVALID_HANDLE_VALUE;
58   }
59 }
60
61 bool CAutoPtrHandle::isValid() const
62 {
63   if ( INVALID_HANDLE_VALUE != m_hHandle)
64     return true;
65   return false;
66 }
67 void CAutoPtrHandle::reset()
68 {
69   Cleanup();
70 }
71
72 //-------------------------------------------------------------------------------
73 CAutoPtrFind ::CAutoPtrFind(HANDLE hHandle)
74     : CAutoPtrHandle(hHandle)
75 {}
76 CAutoPtrFind::~CAutoPtrFind(void)
77 {
78   Cleanup();
79 }
80
81 void CAutoPtrFind::Cleanup()
82 {
83   if ( isValid() )
84   {
85     FindClose(m_hHandle);
86     m_hHandle = INVALID_HANDLE_VALUE;
87   }
88 }
89
90 //-------------------------------------------------------------------------------
91 CAutoPtrSocket::CAutoPtrSocket(SOCKET hSocket)
92     : m_hSocket(hSocket)
93 {}
94
95 CAutoPtrSocket::~CAutoPtrSocket(void)
96 {
97   Cleanup();
98 }
99
100 CAutoPtrSocket::operator SOCKET()
101 {
102   return m_hSocket;
103 }
104
105 void CAutoPtrSocket::attach(SOCKET hSocket)
106 {
107   Cleanup();
108   m_hSocket = hSocket;
109 }
110
111 SOCKET CAutoPtrSocket::release()
112 {
113   SOCKET hTmp = m_hSocket;
114   m_hSocket = INVALID_SOCKET;
115   return hTmp;
116 }
117
118 void CAutoPtrSocket::Cleanup()
119 {
120   if ( isValid() )
121   {
122     closesocket(m_hSocket);
123     m_hSocket = INVALID_SOCKET;
124   }
125 }
126
127 bool CAutoPtrSocket::isValid() const
128 {
129   if ( INVALID_SOCKET != m_hSocket)
130     return true;
131   return false;
132 }
133 void CAutoPtrSocket::reset()
134 {
135   Cleanup();
136 }