|
| UniqueHandle (const UniqueHandle &v)=delete |
|
UniqueHandle & | operator= (const UniqueHandle &other)=delete |
|
| UniqueHandle (UniqueHandle &&v) |
|
| UniqueHandle (const Handle &externalHandle) |
|
CloseReturnType | assign (UniqueHandle &&other) |
| Move assigns another UniqueHandle to this object, eventually closing existing handle.
|
|
CloseReturnType | assign (const Handle &externalHandle) |
| Copy assigns another UniqueHandle to this object, eventually closing existing handle.
|
|
UniqueHandle & | operator= (UniqueHandle &&other) |
|
bool | isValid () const |
| Check if current handle is valid.
|
|
void | detach () |
| Detaches (sets to invalid) current handle, without closing it.
|
|
CloseReturnType | get (Handle &outHandle, CloseReturnType invalidReturnType) const |
| Extracts the native operating system handle out.
|
|
CloseReturnType | close () |
| Closes the handle by calling its OS specific close function.
|
|
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;
};
Result PosixFileDescriptorDefinition::releaseHandle(Handle& handle)
{
{
}
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
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:12
static constexpr Result Error(const char(&msg)[numChars])
Constructs an Error from a pointer to an ASCII string literal.
Definition Result.h:24
Move only handle that has a special tag value flagging its invalid state.
Definition UniqueHandle.h:67
CloseReturnType close()
Closes the handle by calling its OS specific close function.
Definition UniqueHandle.h:140