mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-19 14:52:10 +01:00
[util] Add some functionality to smart pointer
Basically lets us deal with objects that manage their own destruction, which ideally shold be all of them at some point. Also adds some missing comparison operators.
This commit is contained in:
parent
06baa48c2b
commit
888906a6da
@ -18,7 +18,7 @@ namespace dxvk {
|
||||
friend class Rc;
|
||||
public:
|
||||
|
||||
Rc() { }
|
||||
Rc() = default;
|
||||
Rc(std::nullptr_t) { }
|
||||
|
||||
Rc(T* object)
|
||||
@ -93,12 +93,19 @@ namespace dxvk {
|
||||
T* operator -> () const { return m_object; }
|
||||
T* ptr() const { return m_object; }
|
||||
|
||||
bool operator == (const Rc& other) const { return m_object == other.m_object; }
|
||||
bool operator != (const Rc& other) const { return m_object != other.m_object; }
|
||||
template<typename Tx> bool operator == (const Rc<Tx>& other) const { return m_object == other.m_object; }
|
||||
template<typename Tx> bool operator != (const Rc<Tx>& other) const { return m_object != other.m_object; }
|
||||
|
||||
template<typename Tx> bool operator == (Tx* other) const { return m_object == other; }
|
||||
template<typename Tx> bool operator != (Tx* other) const { return m_object != other; }
|
||||
|
||||
bool operator == (std::nullptr_t) const { return m_object == nullptr; }
|
||||
bool operator != (std::nullptr_t) const { return m_object != nullptr; }
|
||||
|
||||
explicit operator bool () const {
|
||||
return m_object != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
T* m_object = nullptr;
|
||||
@ -110,13 +117,24 @@ namespace dxvk {
|
||||
|
||||
force_inline void decRef() const {
|
||||
if (m_object != nullptr) {
|
||||
if (m_object->decRef() == 0)
|
||||
delete m_object;
|
||||
if constexpr (std::is_void_v<decltype(m_object->decRef())>) {
|
||||
m_object->decRef();
|
||||
} else {
|
||||
// Deprecated, objects should manage themselves now.
|
||||
if (!m_object->decRef())
|
||||
delete m_object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename Tx, typename Ty>
|
||||
bool operator == (Tx* a, const Rc<Ty>& b) { return b == a; }
|
||||
|
||||
template<typename Tx, typename Ty>
|
||||
bool operator != (Tx* a, const Rc<Ty>& b) { return b != a; }
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
Loading…
x
Reference in New Issue
Block a user