41#ifndef __BASE_REFCNT_HH__
42#define __BASE_REFCNT_HH__
134 static constexpr auto TisConst = std::is_const_v<T>;
210 template <
bool B = TisConst>
229 template <
bool B = TisConst>
262 operator bool()
const {
return data != 0; }
270 return l.get() ==
r.get();
296 return l.get() !=
r.get();
Derive from RefCounted if you want to enable reference counting of this class.
RefCounted(const RefCounted &)
virtual ~RefCounted()
We make the destructor virtual because we're likely to have virtual functions on reference counted ob...
RefCounted()
We initialize the reference count to zero and the first object to take ownership of it must increment...
void decref() const
Decrement the reference count and destroy the object if all references are gone.
RefCounted & operator=(const RefCounted &)
void incref() const
Increment the reference count.
If you want a reference counting pointer to a mutable object, create it like this:
RefCountingPtr()
Create an empty reference counting pointer.
T * data
The stored pointer.
T & operator*() const
Dereference the pointer.
const RefCountingPtr & operator=(RefCountingPtr &&r)
Move-assign the pointer from another RefCountingPtr.
typename std::conditional_t< TisConst, RefCountingPtr< T >, RefCountingPtr< typename std::add_const< T >::type > > ConstT
bool operator!() const
Check if the pointer is empty.
const RefCountingPtr & operator=(T *p)
Assign a new value to the pointer.
void set(T *d)
Drop the old reference and change it to something new.
void del()
Delete the reference to any existing object if it is non NULL.
static constexpr auto TisConst
Convenience aliases for const/non-const versions of T w/ friendship.
~RefCountingPtr()
Destroy the pointer and any reference it may hold.
RefCountingPtr(T *data)
Create a new reference counting pointer to some object (probably something newly created).
RefCountingPtr(const RefCountingPtr &r)
Create a new reference counting pointer by copying another one.
RefCountingPtr(const NonConstT &r)
void copy(T *d)
Copy a new pointer value and increment the reference count if it is a valid pointer.
T * operator->() const
Access a member variable.
const RefCountingPtr & operator=(const RefCountingPtr &r)
Copy the pointer from another RefCountingPtr.
RefCountingPtr(RefCountingPtr &&r)
Move-constructor.
typename std::conditional_t< TisConst, RefCountingPtr< typename std::remove_const< T >::type >, RefCountingPtr< T > > NonConstT
T * get() const
Directly access the pointer itself without taking a reference.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
static bool operator==(const PCStateBase &a, const PCStateBase &b)
static bool operator!=(const PCStateBase &a, const PCStateBase &b)