Face Engine SDK  5.8.0
A face detection, recognition and tracking engine.
RefBase.h
1 #pragma once
2 
3 #include <cstddef>
4 
5 namespace fsdk
6 {
16  template<typename T>
17  struct RefBase {
18 
21  RefBase() noexcept = default;
22 
26  explicit RefBase(T* ptr) noexcept : m_ptr(ptr) {}
27 
32  operator T* () const noexcept {
33  return get();
34  }
35 
39  T& operator * () const noexcept {
40  assert(!isNull());
41  return *get();
42  }
43 
47  operator bool () const noexcept {
48  return !isNull();
49  }
50 
55  bool operator == (const RefBase& other) const noexcept {
56  return get() == other.get();
57  }
58 
63  bool operator != (const RefBase& other) const noexcept {
64  return !(*this == other);
65  }
66 
70  bool isNull() const noexcept {
71  return get() == nullptr;
72  }
73 
77  bool isExpired() const noexcept {
78  assert(!isNull());
79  return get()->getRefCount() == 0;
80  }
81 
85  bool isUnique() const noexcept {
86  assert(!isNull());
87  return get()->getRefCount() == 1;
88  }
89 
93  T* get() const noexcept {
94  return m_ptr;
95  }
96 
101  void set(T* ptr) noexcept {
102  m_ptr = ptr;
103  }
104 
105  protected:
106  T* m_ptr {nullptr};
107  };
108 }
fsdk::RefBase::operator*
T & operator*() const noexcept
Dereference operator.
Definition: RefBase.h:39
fsdk::RefBase::set
void set(T *ptr) noexcept
Replace object pointer without any checks or reference management.
Definition: RefBase.h:101
fsdk::RefBase::operator==
bool operator==(const RefBase &other) const noexcept
Check if two refs are the same.
Definition: RefBase.h:55
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::RefBase::operator!=
bool operator!=(const RefBase &other) const noexcept
Check if two refs are not the same.
Definition: RefBase.h:63
fsdk::RefBase::isUnique
bool isUnique() const noexcept
Check if object has only one strong reference.
Definition: RefBase.h:85
fsdk::RefBase::isNull
bool isNull() const noexcept
Check for nullptr.
Definition: RefBase.h:70
fsdk::RefBase::RefBase
RefBase() noexcept=default
Initializes object pointer to nullptr.
fsdk::RefBase
Generic base class of a pointer for reference counted objects.
Definition: RefBase.h:17
fsdk::RefBase::m_ptr
T * m_ptr
Raw pointer.
Definition: RefBase.h:106
fsdk::RefBase::isExpired
bool isExpired() const noexcept
Check is object is dead.
Definition: RefBase.h:77
fsdk::RefBase::get
T * get() const noexcept
Get current raw object pointer.
Definition: RefBase.h:93