Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
privateptr.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <memory>
8#include <utility>
9
10namespace Sonde {
11
18template <typename T>
20{
21public:
23 explicit PrivatePtr(T *p = nullptr) noexcept : m_p(p) { }
25 explicit PrivatePtr(std::unique_ptr<T> p) noexcept : m_p(std::move(p)) { }
26
27 PrivatePtr(PrivatePtr &&) noexcept = default;
28 PrivatePtr &operator=(PrivatePtr &&) noexcept = default;
29 PrivatePtr(const PrivatePtr &) = delete;
30 PrivatePtr &operator=(const PrivatePtr &) = delete;
31 ~PrivatePtr() = default;
32
34 T *get() noexcept { return m_p.get(); }
36 const T *get() const noexcept { return m_p.get(); }
38 T *operator->() noexcept { return m_p.get(); }
40 const T *operator->() const noexcept { return m_p.get(); }
42 T &operator*() noexcept { return *m_p; }
44 const T &operator*() const noexcept { return *m_p; }
46 explicit operator bool() const noexcept { return m_p != nullptr; }
47
49 void reset(T *p = nullptr) noexcept { m_p.reset(p); }
50
51private:
52 std::unique_ptr<T> m_p;
53};
54
55} // namespace Sonde
T * get() noexcept
The private part.
Definition privateptr.h:34
PrivatePtr(T *p=nullptr) noexcept
Takes ownership of p.
Definition privateptr.h:23
T * operator->() noexcept
The private part.
Definition privateptr.h:38
std::unique_ptr< T > m_p
What it owns.
Definition privateptr.h:52
PrivatePtr(std::unique_ptr< T > p) noexcept
Takes ownership of what p owns.
Definition privateptr.h:25
const T * get() const noexcept
The private part, const.
Definition privateptr.h:36
T & operator*() noexcept
The private part.
Definition privateptr.h:42
const T * operator->() const noexcept
The private part, const.
Definition privateptr.h:40
PrivatePtr(PrivatePtr &&) noexcept=default
Moves ownership.
const T & operator*() const noexcept
The private part, const.
Definition privateptr.h:44
void reset(T *p=nullptr) noexcept
Destroys what it owns, and owns p instead.
Definition privateptr.h:49
Embeddable Model Context Protocol server for Qt applications.
Definition dispatch.cpp:10