//------------------------------------------------------------------------------------- // scoped.h // // Utility header with helper classes for exception-safe handling of resources // // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. // // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------------- #if defined(_MSC_VER) && (_MSC_VER > 1000) #pragma once #endif #include #include #include //--------------------------------------------------------------------------------- struct aligned_deleter { void operator()(void* p) { _aligned_free(p); } }; typedef std::unique_ptr ScopedAlignedArrayFloat; typedef std::unique_ptr ScopedAlignedArrayXMVECTOR; //--------------------------------------------------------------------------------- struct handle_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VALUE); if (h) CloseHandle(h); } }; typedef public std::unique_ptr ScopedHandle; inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; } //--------------------------------------------------------------------------------- #include template class ScopedObject : public Microsoft::WRL::ComPtr { public: ScopedObject() : Microsoft::WRL::ComPtr() {} ScopedObject( T *p ) : Microsoft::WRL::ComPtr(p) {} ScopedObject( const ScopedObject& other ) : Microsoft::WRL::ComPtr( other ) {} };