template<typename Definition>
struct SC::UniqueHandle< Definition >
Move only handle that has a special tag value flagging its invalid state.
Typically used to wrap Operating System specific handles.
- Template Parameters
-
Definition | A struct declaring handle type, release function and invalid handle value. |
Example:
struct PosixFileDescriptorDefinition
{
using Handle = int;
static Result releaseHandle(Handle& handle);
static constexpr Handle Invalid = -1;
};
using PosixFileDescriptor = UniqueHandle<PosixFileDescriptorDefinition>;
Result PosixFileDescriptorDefinition::releaseHandle(Handle& handle)
{
if (::
close(handle) != 0)
{
}
return Result(true);
}
PosixFileDescriptor myDescriptor;
const int nativeFd = ::open(filePath.getNullTerminatedNative(), flags, access);
myDescriptor.assign(nativeFd);
PosixFileDescriptor otherDescriptor =
move(myDescriptor);
otherDescriptor.close()
otherDescriptor.detach()
if(otherDescriptor.isValid())
{
}
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition: Compiler.h:269
static constexpr Result Error(const char(&msg)[numChars])
Constructs an Error from a pointer to an ASCII string literal.
Definition: Result.h:23
CloseReturnType close()
Closes the handle by calling its OS specific close function.
Definition: UniqueHandle.h:140