| Face Engine SDK 5.33.0 A face detection, recognition and tracking engine.

Loading...
Searching...
No Matches
RefBase.h
1#pragma once
2
3#include <cstddef>
4
5 namespace fsdk {
15 template <typename T>
16 struct RefBase {
17
20 RefBase() noexcept = default;
21
25 explicit RefBase(T* ptr) noexcept
26 : m_ptr(ptr) {
27 }
28
33 operator T*() const noexcept {
34 return get();
35 }
36
40 T& operator*() const noexcept {
41 assert(!isNull());
42 return *get();
43 }
44
48 operator bool() const noexcept {
49 return !isNull();
50 }
51
56 bool operator==(const RefBase& other) const noexcept {
57 return get() == other.get();
58 }
59
64 bool operator!=(const RefBase& other) const noexcept {
65 return !(*this == other);
66 }
67
71 bool isNull() const noexcept {
72 return get() == nullptr;
73 }
74
78 bool isExpired() const noexcept {
79 assert(!isNull());
80 return get()->getRefCount() == 0;
81 }
82
86 bool isUnique() const noexcept {
87 assert(!isNull());
88 return get()->getRefCount() == 1;
89 }
90
94 T* get() const noexcept {
95 return m_ptr;
96 }
97
102 void set(T* ptr) noexcept {
103 m_ptr = ptr;
104 }
105
106 protected:
107 T* m_ptr{nullptr};
108 };
109} // namespace fsdk
fsdk
SDK namespace.
Definition IAGSEstimator.h:8
fsdk::RefBase
Generic base class of a pointer for reference counted objects.
Definition RefBase.h:16
fsdk::RefBase::operator*
T & operator*() const noexcept
Dereference operator.
Definition RefBase.h:40
fsdk::RefBase::isUnique
bool isUnique() const noexcept
Check if object has only one strong reference.
Definition RefBase.h:86
fsdk::RefBase::RefBase
RefBase() noexcept=default
Initializes object pointer to nullptr.
fsdk::RefBase::operator!=
bool operator!=(const RefBase &other) const noexcept
Check if two refs are not the same.
Definition RefBase.h:64
fsdk::RefBase::isNull
bool isNull() const noexcept
Check for nullptr.
Definition RefBase.h:71
fsdk::RefBase::isExpired
bool isExpired() const noexcept
Check is object is dead.
Definition RefBase.h:78
fsdk::RefBase::operator==
bool operator==(const RefBase &other) const noexcept
Check if two refs are the same.
Definition RefBase.h:56
fsdk::RefBase::set
void set(T *ptr) noexcept
Replace object pointer without any checks or reference management.
Definition RefBase.h:102
fsdk::RefBase::m_ptr
T * m_ptr
Raw pointer.
Definition RefBase.h:107
fsdk::RefBase::get
T * get() const noexcept
Get current raw object pointer.
Definition RefBase.h:94