Clone
ixen <ixen@copyhandler.com>
committed
on 17 Nov 16
Updated Turkish translation file with the new version from Onur (CH-294).
ParallelizeReaderWriter + 3 more
src/ch/TAutoHandles.h (deleted)
1   // ============================================================================
2   //  Copyright (C) 2001-2010 by Jozef Starosczyk
3   //  ixen@copyhandler.com
4   //
5   //  This program is free software; you can redistribute it and/or modify
6   //  it under the terms of the GNU Library General Public License
7   //  (version 2) as published by the Free Software Foundation;
8   //
9   //  This program is distributed in the hope that it will be useful,
10   //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11   //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   //  GNU General Public License for more details.
13   //
14   //  You should have received a copy of the GNU Library General Public
15   //  License along with this program; if not, write to the
16   //  Free Software Foundation, Inc.,
17   //  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   // ============================================================================
19   /// @file  TAutoHandles.h
20   /// @date  2010/09/18
21   /// @brief Contains implementation of auto-close handles.
22   // ============================================================================
23   #ifndef __TAUTOHANDLES_H__
24   #define __TAUTOHANDLES_H__
25  
26   /// class encapsulates windows HANDLE, allowing automatic closing it in destructor.
27   class TAutoFileHandle
28   {
29   public:
30           // ============================================================================
31           /// TAutoFileHandle::TAutoFileHandle
32           /// @date 2010/08/26
33           ///
34           /// @brief     Constructs the TAutoFileHandle object.
35           // ============================================================================
36           TAutoFileHandle() :
37                   m_hHandle(INVALID_HANDLE_VALUE)
38           {
39           }
40  
41           // ============================================================================
42           /// TAutoFileHandle::TAutoFileHandle
43           /// @date 2010/08/26
44           ///
45           /// @brief     Constructs the TAutoFileHandle object with specified handle.
46           /// @param[in] hHandle - System handle to be managed by this class.
47           // ============================================================================
48           TAutoFileHandle(HANDLE hHandle) :
49                   m_hHandle(hHandle)
50           {
51           }
52  
53           // ============================================================================
54           /// TAutoFileHandle::~TAutoFileHandle
55           /// @date 2010/08/26
56           ///
57           /// @brief     Destructs the TAutoFileHandle object and closes handle if not closed already.
58           // ============================================================================
59           ~TAutoFileHandle()
60           {
61                   VERIFY(Close());
62           }
63  
64           // ============================================================================
65           /// TAutoFileHandle::operator=
66           /// @date 2010/08/26
67           ///
68           /// @brief     Assignment operator.
69           /// @param[in] hHandle - Handle to be assigned.
70           /// @return    Reference to this object,
71           // ============================================================================
72           TAutoFileHandle& operator=(HANDLE hHandle)
73           {
74                   if(m_hHandle != hHandle)
75                   {
76                           VERIFY(Close());
77                           m_hHandle = hHandle;
78                   }
79                   return *this;
80           }
81  
82           // ============================================================================
83           /// TAutoFileHandle::operator HANDLE
84           /// @date 2010/08/26
85           ///
86           /// @brief     Retrieves the system handle.
87           /// @return    HANDLE value.
88           // ============================================================================
89           operator HANDLE()
90           {
91                   return m_hHandle;
92           }
93  
94           // ============================================================================
95           /// TAutoFileHandle::Close
96           /// @date 2010/08/26
97           ///
98           /// @brief     Closes the internal handle if needed.
99           /// @return    Result of the CloseHandle() function.
100           // ============================================================================
101           BOOL Close()
102           {
103                   BOOL bResult = TRUE;
104                   if(m_hHandle != INVALID_HANDLE_VALUE)
105                   {
106                           bResult = CloseHandle(m_hHandle);
107                           m_hHandle = INVALID_HANDLE_VALUE;
108                   }
109  
110                   return bResult;
111           }
112  
113           // ============================================================================
114           /// TAutoFileHandle::Detach
115           /// @date 2010/09/12
116           ///
117           /// @brief     Detaches the handle, so it won't be closed in destructor.
118           /// @return        Returns current handle.
119           // ============================================================================
120           HANDLE Detach()
121           {
122                   HANDLE hHandle = m_hHandle;
123                   m_hHandle = INVALID_HANDLE_VALUE;
124                   return hHandle;
125           }
126  
127   private:
128           HANDLE m_hHandle;               ///< System handle
129   };
130  
131   #endif