|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
A nullable smart wrapper around a raw pointer. More...
#include <wrapper.hpp>
Public Member Functions | |
| Wrapper () | |
| Default constructor — initialises to nullopt (no value). | |
| Wrapper (const T &t) | |
| Construct from a raw pointer. | |
| Wrapper (std::nullopt_t n) | |
| Construct in the empty (nullopt) state. | |
| Wrapper (const Wrapper< T > &w) | |
| Copy constructor. | |
| Wrapper (Wrapper< T > &&w) | |
| Move constructor. | |
| ~Wrapper ()=default | |
| Wrapper< T > & | operator= (const T &t) |
| Assign from a raw pointer. | |
| Wrapper< T > & | operator= (std::nullopt_t n) |
| Reset to the empty (nullopt) state. | |
| Wrapper< T > & | operator= (const Wrapper< T > &w) |
| Copy-assign from another Wrapper. | |
| Wrapper< T > & | operator= (Wrapper< T > &&w) |
| Move-assign from another Wrapper. | |
| bool | has_value () const |
| Check whether a non-null value is held. | |
| T | value () |
| Access the stored pointer without null checking. | |
| T | expect (const std::string &msg) |
| Unwrap with a custom panic message on null. | |
| T | unwrap () |
| Unwrap the stored pointer, panicking on null. | |
| T | unwrap_or (T value) |
| Return the stored pointer or a fallback if null. | |
Private Attributes | |
| std::optional< T > | type |
| Internal optional storage. | |
A nullable smart wrapper around a raw pointer.
Stores an optional pointer. Accessors throw mx::Exception if the pointer is null (unwrap, expect) or return a fallback (unwrap_or).
| T | A raw pointer type (must satisfy WrapType concept). |
Definition at line 36 of file wrapper.hpp.
|
inline |
Default constructor — initialises to nullopt (no value).
Definition at line 39 of file wrapper.hpp.
References type.
Referenced by operator=(), operator=(), operator=(), operator=(), Wrapper(), and Wrapper().
|
inline |
Construct from a raw pointer.
| t | Pointer to wrap. |
Definition at line 45 of file wrapper.hpp.
References type.
|
inline |
Construct in the empty (nullopt) state.
| n | std::nullopt. |
Definition at line 51 of file wrapper.hpp.
References type.
|
inline |
|
inline |
|
default |
|
inline |
Unwrap with a custom panic message on null.
| msg | Message to include in the thrown mx::Exception. |
| mx::Exception | if the value is null or absent. |
Definition at line 118 of file wrapper.hpp.
References type.
|
inline |
Check whether a non-null value is held.
true if a non-null pointer is stored. Definition at line 97 of file wrapper.hpp.
References type.
|
inline |
Assign from a raw pointer.
| t | Pointer to store. |
Definition at line 66 of file wrapper.hpp.
|
inline |
Copy-assign from another Wrapper.
Definition at line 82 of file wrapper.hpp.
|
inline |
Reset to the empty (nullopt) state.
| n | std::nullopt. |
Definition at line 76 of file wrapper.hpp.
|
inline |
Move-assign from another Wrapper.
Definition at line 88 of file wrapper.hpp.
|
inline |
Unwrap the stored pointer, panicking on null.
| mx::Exception | if the value is null or absent. |
Definition at line 132 of file wrapper.hpp.
References type.
|
inline |
Return the stored pointer or a fallback if null.
| value | Fallback pointer returned when no value is held. |
value if null/absent. Definition at line 147 of file wrapper.hpp.
|
inline |
Access the stored pointer without null checking.
Definition at line 108 of file wrapper.hpp.
References type.
Referenced by unwrap_or().
|
private |
Internal optional storage.
Definition at line 154 of file wrapper.hpp.
Referenced by expect(), has_value(), operator=(), operator=(), operator=(), operator=(), unwrap(), unwrap_or(), value(), Wrapper(), Wrapper(), Wrapper(), Wrapper(), and Wrapper().