DQCsim
|
Base class for wrapping any handle. More...
Public Member Functions | |
Handle () noexcept | |
Constructs an empty wrapper. More... | |
Handle (HandleIndex handle) noexcept | |
Wraps the given raw handle. More... | |
virtual | ~Handle () noexcept |
Delete the handle and its wrapper. | |
void | free () |
Explicitly delete the handle, allowing errors to be caught. More... | |
bool | is_valid () const noexcept |
Returns whether this wrapper (still) contains a valid handle. More... | |
HandleIndex | get_handle () const noexcept |
Returns the raw handle without relinquishing ownership. More... | |
HandleIndex | take_handle () noexcept |
Returns the raw handle and relinquishes ownership. More... | |
Handle (const Handle &)=delete | |
void | operator= (const Handle &)=delete |
Handle (Handle &&src) | |
Move constructor; simply moves ownership of the handle from the source object to the constructed object. More... | |
Handle & | operator= (Handle &&src) |
Move constructor; simply moves ownership of the handle from the source object to the assignment target. More... | |
std::string | dump () const |
Returns a string containing a debug dump of the handle. More... | |
HandleType | type () const |
Returns the type of this handle. More... | |
Protected Attributes | |
HandleIndex | handle |
The wrapped handle. | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const Handle &handle) |
Write the debug dump string of the handle to the given output stream. More... | |
Base class for wrapping any handle.
This class ensures that the wrapped handle is freed when it is destroyed, preventing memory leaks. You can also free the handle before destruction, which allows any errors reported by DQCsim to be caught. You can take back ownership of the handle using take_handle
, preventing it from being freed at destruction.
Only one Handle
should wrap a single handle at a time. Since handles cannot typically be cloned, this class is not copy constructible or assignable. If you need it to be, consider wrapping the Handle
in a std::shared_ptr
.
Handle
objects can not and should never be passed between threads. The wrapped C API handles are thread local can cannot be moved between threads, therefore this wrapper can't either. Trying to do so anyway is undefined behavior and will absolutely not work! If you need to move data between threads, copy the data represented by the handle into C++ variables, pass those over, and reconstruct the handle from them in the destination thread.
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Move constructor; simply moves ownership of the handle from the source object to the constructed object.
is_valid
will return false
and all other methods will likely fail. Note that using an object after moving it is explicitly undefined behavior in the C++ specification, so you shouldn't be using it anymore anyway.src | The handle wrapper to move from. |
|
inline |
Explicitly delete the handle, allowing errors to be caught.
is_valid
will return false
and all other methods will likely fail.std::runtime_error | When deletion of the handle fails for some reason. |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Move constructor; simply moves ownership of the handle from the source object to the assignment target.
is_valid
will return false
and all other methods will likely fail. Note that using an object after moving it is explicitly undefined behavior in the C++ specification, so you shouldn't be using it anymore anyway.src | The handle wrapper to move from. |
std::runtime_error | When the destination already wrapped a handle, and freeing that handle failed. |
|
inline |
Returns a string containing a debug dump of the handle.
The string uses newlines and indentation to improve readability. It does not end in a newline.
std::runtime_error | When the currently wrapped handle is invalid. |
|
inline |
|
friend |
Write the debug dump string of the handle to the given output stream.
Newlines and indentation are used to improve readability. However, there is implicit trailing std::endl
.
out | The output stream to write to. |
handle | The handle to dump. |
std::runtime_error | When the given handle is invalid. |