4#include "../Foundation/Result.h"
25template <
typename Definition>
28 using Handle =
typename Definition::Handle;
30 static constexpr Handle Invalid = Definition::Invalid;
36 UniqueHandle(
const Handle& externalHandle) : handle(externalHandle) {}
44 if (other.handle == handle)
48 handle = other.handle;
60 if (handle == externalHandle)
64 handle = externalHandle;
78 [[nodiscard]]
bool isValid()
const {
return handle != Invalid; }
94 return invalidReturnType;
103 Handle handleCopy = handle;
105 return Definition::releaseHandle(handleCopy);
111 Handle handle = Invalid;
constexpr T && forward(typename TypeTraits::RemoveReference< T >::type &value)
Forwards an lvalue or an rvalue as an rvalue reference.
Definition Compiler.h:260
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:12
Move only handle that has a special tag value flagging its invalid state.
Definition UniqueHandle.h:27
Result assign(const Handle &externalHandle)
Copy assigns another UniqueHandle to this object, eventually closing existing handle.
Definition UniqueHandle.h:58
void detach()
Detaches (sets to invalid) current handle, without closing it.
Definition UniqueHandle.h:81
Result get(Handle &outHandle, Result invalidReturnType) const
Extracts the native operating system handle out.
Definition UniqueHandle.h:87
bool isValid() const
Check if current handle is valid.
Definition UniqueHandle.h:78
Result close()
Closes the handle by calling its OS specific close function.
Definition UniqueHandle.h:99
Result assign(UniqueHandle &&other)
Move assigns another UniqueHandle to this object, eventually closing existing handle.
Definition UniqueHandle.h:42