Skip to content

Commit

Permalink
Refactor: details namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
matt77hias committed May 31, 2018
1 parent 8ece84a commit fba8570
Showing 1 changed file with 41 additions and 35 deletions.
76 changes: 41 additions & 35 deletions MAGE/Utilities/src/memory/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,39 +233,42 @@ namespace mage {
//-------------------------------------------------------------------------
#pragma region

/**
Destructs the given handle.
@param[in] handle
The handle to destruct.
*/
inline void DestructHandle(HANDLE handle) noexcept {
if (handle) {
CloseHandle(handle);
}
}

/**
A struct of handle destructors (i.e. for closing handles).
*/
struct HandleCloser final {
namespace details {

/**
Destructs the given handle.
@param[in] handle
The handle to destruct.
*/
void operator()(HANDLE handle) const noexcept {
DestructHandle(handle);
inline void DestructHandle(HANDLE handle) noexcept {
if (handle) {
CloseHandle(handle);
}
}
};

/**
A struct of handle destructors (i.e. for closing handles).
*/
struct HandleCloser final {

/**
Destructs the given handle.
@param[in] handle
The handle to destruct.
*/
void operator()(HANDLE handle) const noexcept {
DestructHandle(handle);
}
};
}

/**
A class of smart pointers for managing exclusive-ownership handle
resources.
*/
using UniqueHandle = UniquePtr< void, HandleCloser >;
using UniqueHandle = UniquePtr< void, details::HandleCloser >;

/**
A class of smart pointers for managing shared-ownership handle resources.
Expand Down Expand Up @@ -306,7 +309,7 @@ namespace mage {
@return A shared handle for the given handle @a handle.
*/
inline SharedHandle CreateSharedHandle(HANDLE handle) {
return SharedHandle(SafeHandle(handle), DestructHandle);
return SharedHandle(SafeHandle(handle), details::DestructHandle);
}

#pragma endregion
Expand All @@ -316,28 +319,31 @@ namespace mage {
//-------------------------------------------------------------------------
#pragma region

/**
A struct of file stream destructors (i.e. for closing file streams).
*/
struct FileStreamCloser final {
namespace details {

/**
Destructs the file stream.
@param[in] stream
A pointer to a file stream to destruct.
A struct of file stream destructors (i.e. for closing file streams).
*/
void operator()(FILE* stream) const noexcept {
if (stream) {
fclose(stream);
struct FileStreamCloser final {

/**
Destructs the file stream.
@param[in] stream
A pointer to a file stream to destruct.
*/
void operator()(FILE* stream) const noexcept {
if (stream) {
fclose(stream);
}
}
}
};
};
}

/**
A class of smart pointers for managing exclusive-ownership file streams.
*/
using UniqueFileStream = UniquePtr< FILE, FileStreamCloser >;
using UniqueFileStream = UniquePtr< FILE, details::FileStreamCloser >;

#pragma endregion

Expand Down

0 comments on commit fba8570

Please sign in to comment.