Face Engine SDK  5.8.0
A face detection, recognition and tracking engine.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 }
bool operator!=(const RefBase &other) const noexcept
Check if two refs are not the same.
Definition: RefBase.h:63
RefBase() noexcept=default
Initializes object pointer to nullptr.
bool isUnique() const noexcept
Check if object has only one strong reference.
Definition: RefBase.h:85
RefBase(T *ptr) noexcept
Initializes object pointer with ptr.
Definition: RefBase.h:26
Generic base class of a pointer for reference counted objects.
Definition: RefBase.h:17
T & operator*() const noexcept
Dereference operator.
Definition: RefBase.h:39
T * m_ptr
Raw pointer.
Definition: RefBase.h:106
bool isExpired() const noexcept
Check is object is dead.
Definition: RefBase.h:77
void set(T *ptr) noexcept
Replace object pointer without any checks or reference management.
Definition: RefBase.h:101
bool isNull() const noexcept
Check for nullptr.
Definition: RefBase.h:70
bool operator==(const RefBase &other) const noexcept
Check if two refs are the same.
Definition: RefBase.h:55