Index: src/libchcore/TAutoHandles.h =================================================================== diff -u -N -rfb4c4006dee5aaf815d08bc3e89312445b994307 -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 --- src/libchcore/TAutoHandles.h (.../TAutoHandles.h) (revision fb4c4006dee5aaf815d08bc3e89312445b994307) +++ src/libchcore/TAutoHandles.h (.../TAutoHandles.h) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) @@ -25,113 +25,112 @@ #include "libchcore.h" -BEGIN_CHCORE_NAMESPACE - -/// class encapsulates windows HANDLE, allowing automatic closing it in destructor. -class TAutoFileHandle +namespace chcore { -public: - // ============================================================================ - /// TAutoFileHandle::TAutoFileHandle - /// @date 2010/08/26 - /// - /// @brief Constructs the TAutoFileHandle object. - // ============================================================================ - TAutoFileHandle() : - m_hHandle(INVALID_HANDLE_VALUE) + /// class encapsulates windows HANDLE, allowing automatic closing it in destructor. + class TAutoFileHandle { - } + public: + // ============================================================================ + /// TAutoFileHandle::TAutoFileHandle + /// @date 2010/08/26 + /// + /// @brief Constructs the TAutoFileHandle object. + // ============================================================================ + TAutoFileHandle() : + m_hHandle(INVALID_HANDLE_VALUE) + { + } - // ============================================================================ - /// TAutoFileHandle::TAutoFileHandle - /// @date 2010/08/26 - /// - /// @brief Constructs the TAutoFileHandle object with specified handle. - /// @param[in] hHandle - System handle to be managed by this class. - // ============================================================================ - TAutoFileHandle(HANDLE hHandle) : - m_hHandle(hHandle) - { - } + // ============================================================================ + /// TAutoFileHandle::TAutoFileHandle + /// @date 2010/08/26 + /// + /// @brief Constructs the TAutoFileHandle object with specified handle. + /// @param[in] hHandle - System handle to be managed by this class. + // ============================================================================ + TAutoFileHandle(HANDLE hHandle) : + m_hHandle(hHandle) + { + } - // ============================================================================ - /// TAutoFileHandle::~TAutoFileHandle - /// @date 2010/08/26 - /// - /// @brief Destructs the TAutoFileHandle object and closes handle if not closed already. - // ============================================================================ - ~TAutoFileHandle() - { - Close(); - } - - // ============================================================================ - /// TAutoFileHandle::operator= - /// @date 2010/08/26 - /// - /// @brief Assignment operator. - /// @param[in] hHandle - Handle to be assigned. - /// @return Reference to this object, - // ============================================================================ - TAutoFileHandle& operator=(HANDLE hHandle) - { - if(m_hHandle != hHandle) + // ============================================================================ + /// TAutoFileHandle::~TAutoFileHandle + /// @date 2010/08/26 + /// + /// @brief Destructs the TAutoFileHandle object and closes handle if not closed already. + // ============================================================================ + ~TAutoFileHandle() { Close(); - m_hHandle = hHandle; } - return *this; - } - // ============================================================================ - /// TAutoFileHandle::operator HANDLE - /// @date 2010/08/26 - /// - /// @brief Retrieves the system handle. - /// @return HANDLE value. - // ============================================================================ - operator HANDLE() - { - return m_hHandle; - } + // ============================================================================ + /// TAutoFileHandle::operator= + /// @date 2010/08/26 + /// + /// @brief Assignment operator. + /// @param[in] hHandle - Handle to be assigned. + /// @return Reference to this object, + // ============================================================================ + TAutoFileHandle& operator=(HANDLE hHandle) + { + if (m_hHandle != hHandle) + { + Close(); + m_hHandle = hHandle; + } + return *this; + } - // ============================================================================ - /// TAutoFileHandle::Close - /// @date 2010/08/26 - /// - /// @brief Closes the internal handle if needed. - /// @return Result of the CloseHandle() function. - // ============================================================================ - BOOL Close() - { - BOOL bResult = TRUE; - if(m_hHandle != INVALID_HANDLE_VALUE) + // ============================================================================ + /// TAutoFileHandle::operator HANDLE + /// @date 2010/08/26 + /// + /// @brief Retrieves the system handle. + /// @return HANDLE value. + // ============================================================================ + operator HANDLE() { - bResult = CloseHandle(m_hHandle); - m_hHandle = INVALID_HANDLE_VALUE; + return m_hHandle; } - return bResult; - } + // ============================================================================ + /// TAutoFileHandle::Close + /// @date 2010/08/26 + /// + /// @brief Closes the internal handle if needed. + /// @return Result of the CloseHandle() function. + // ============================================================================ + BOOL Close() + { + BOOL bResult = TRUE; + if (m_hHandle != INVALID_HANDLE_VALUE) + { + bResult = CloseHandle(m_hHandle); + m_hHandle = INVALID_HANDLE_VALUE; + } - // ============================================================================ - /// TAutoFileHandle::Detach - /// @date 2010/09/12 - /// - /// @brief Detaches the handle, so it won't be closed in destructor. - /// @return Returns current handle. - // ============================================================================ - HANDLE Detach() - { - HANDLE hHandle = m_hHandle; - m_hHandle = INVALID_HANDLE_VALUE; - return hHandle; - } + return bResult; + } -private: - HANDLE m_hHandle; ///< System handle -}; + // ============================================================================ + /// TAutoFileHandle::Detach + /// @date 2010/09/12 + /// + /// @brief Detaches the handle, so it won't be closed in destructor. + /// @return Returns current handle. + // ============================================================================ + HANDLE Detach() + { + HANDLE hHandle = m_hHandle; + m_hHandle = INVALID_HANDLE_VALUE; + return hHandle; + } -END_CHCORE_NAMESPACE + private: + HANDLE m_hHandle; ///< System handle + }; +} #endif