Last active
August 29, 2015 13:57
-
-
Save somma/6d1527dd2068f518db57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
* RAII (Resource Acquisition Is Initialization ) | |
******************************************************************************/ | |
/* ex) | |
raii_handle map_handle( | |
CreateFileMapping(file_handle, NULL, PAGE_READONLY, 0, 1, NULL), | |
raii_CloseHandle | |
); | |
if (NULL == map_handle.get()) | |
{ | |
err... | |
} | |
//> U don't need call CloseHandle() manually. | |
//> When 'file_handle' enter out of this scope, raii_CloseHandle() function called automatically :-) | |
*/ | |
typedef boost::shared_ptr< boost::remove_pointer<HANDLE>::type > raii_handle; | |
void raii_CloseHandle(_In_ HANDLE handle); | |
/* | |
raii_void_ptr ods_buf( malloc(ods_size), raii_free ); | |
if (NULL == ods_buf.get()) | |
{ | |
err... | |
} | |
... | |
ods_buf.get(); | |
... | |
raii_void_ptr map_ptr( | |
MapViewOfFile(map_handle.get(), FILE_MAP_READ, 0, 0, 1), | |
raii_UnmapViewOfFile | |
); | |
if (NULL == map_ptr.get()) | |
{ | |
err... | |
} | |
*/ | |
typedef boost::shared_ptr< boost::remove_pointer<wchar_t*>::type > raii_wchar_ptr; | |
typedef boost::shared_ptr< boost::remove_pointer<char*>::type > raii_char_ptr; | |
typedef boost::shared_ptr< boost::remove_pointer<void*>::type > raii_void_ptr; | |
void raii_free(_In_ void* void_ptr); | |
void raii_UnmapViewOfFile(_In_ void* void_ptr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment