15template <
typename T,
typename Deleter>
18 PtrStore() noexcept : PtrStore(
nullptr) {}
21 ~PtrStore() { free(); }
23 PtrStore(
const PtrStore &) =
delete;
24 PtrStore &operator=(
const PtrStore &) =
delete;
27 PtrStore(PtrStore &&other) noexcept : m_ptr(other.release()) {}
31 reset(other.release());
36 bool valid()
const {
return m_ptr; }
38 operator bool()
const {
return valid(); }
46 std::string_view
str() const noexcept
47 requires std::same_as<T,
char> {
return m_ptr ? :
""; }
50 const T *
get() const noexcept {
return m_ptr; }
52 T *
get() noexcept {
return m_ptr; }
56 const T *
operator*() const noexcept {
return m_ptr; }
64 return std::exchange(m_ptr,
nullptr);
90 [[no_unique_address]] Deleter m_deleter;
93template<
typename T,
typename Deleter>
94requires std::same_as<T, char>
97 return os << err.str();
The Deleter for UniqueHolder types.
Definition Unique.h:15
A store for a pointer which is freed in the destructor using sqlite3_free().
Definition PtrStore.h:16
void reset(T *t=nullptr)
Set the pointer to t.
Definition PtrStore.h:68
PtrStore(PtrStore &&other) noexcept
Move constructor.
Definition PtrStore.h:27
bool operator!() const
! wrapper around valid()
Definition PtrStore.h:40
std::string_view str() const noexcept
Return the current pointer as string.
Definition PtrStore.h:46
T * release()
Return the pointer and stop owning it.
Definition PtrStore.h:63
T * get() noexcept
Get the stored pointer.
Definition PtrStore.h:52
const T * operator->() const noexcept
Get the stored pointer.
Definition PtrStore.h:60
bool valid() const
Does this instance hold a valid pointer?
Definition PtrStore.h:36
const T * get() const noexcept
Get the stored pointer.
Definition PtrStore.h:50
T * operator*() noexcept
Get the stored pointer.
Definition PtrStore.h:54
PtrStore & operator=(PtrStore &&other) noexcept
Move assignment.
Definition PtrStore.h:29
T * operator->() noexcept
Get the stored pointer.
Definition PtrStore.h:58
T ** ptr() noexcept
Get a pointer to the internal pointer.
Definition PtrStore.h:79
PtrStore(T *t) noexcept
Construct a new PtrStore with pointer set to t.
Definition PtrStore.h:20
const T * operator*() const noexcept
Get the stored pointer.
Definition PtrStore.h:56