Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
scoped.h
Go to the documentation of this file.
1 //-------------------------------------------------------------------------------------
2 // scoped.h
3 //
4 // Utility header with helper classes for exception-safe handling of resources
5 //
6 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
7 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
8 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
9 // PARTICULAR PURPOSE.
10 //
11 // Copyright (c) Microsoft Corporation. All rights reserved.
12 //-------------------------------------------------------------------------------------
13 
14 #if defined(_MSC_VER) && (_MSC_VER > 1000)
15 #pragma once
16 #endif
17 
18 #include <assert.h>
19 #include <memory>
20 #include <malloc.h>
21 
22 //---------------------------------------------------------------------------------
23 struct aligned_deleter { void operator()(void* p) { _aligned_free(p); } };
24 
25 typedef std::unique_ptr<float, aligned_deleter> ScopedAlignedArrayFloat;
26 
27 typedef std::unique_ptr<DirectX::XMVECTOR, aligned_deleter> ScopedAlignedArrayXMVECTOR;
28 
29 //---------------------------------------------------------------------------------
30 struct handle_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VALUE); if (h) CloseHandle(h); } };
31 
32 typedef public std::unique_ptr<void, handle_closer> ScopedHandle;
33 
34 inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; }
std::unique_ptr< DirectX::XMVECTOR, aligned_deleter > ScopedAlignedArrayXMVECTOR
Definition: scoped.h:27
void operator()(HANDLE h)
Definition: scoped.h:30
public std::unique_ptr< void, handle_closer > ScopedHandle
Definition: scoped.h:32
size_t _In_ DXGI_FORMAT size_t _In_ TEXP_LEGACY_FORMAT _In_ DWORD flags assert(pDestination &&outSize > 0)
std::unique_ptr< float, aligned_deleter > ScopedAlignedArrayFloat
Definition: scoped.h:25
void operator()(void *p)
Definition: scoped.h:23
HANDLE safe_handle(HANDLE h)
Definition: scoped.h:34