31#define FASTLED_SMART_PTR(type) \
33 using type##Ptr = fl::Ptr<type>;
35#define FASTLED_SMART_PTR_STRUCT(type) \
37 using type##Ptr = fl::Ptr<type>;
39#define FASTLED_SMART_PTR_NO_FWD(type) using type##Ptr = fl::Ptr<type>;
43#define FASTLED_SMART_PTR_CONSTRUCTOR(type, constructor) \
44 template <> class PtrTraits<type> { \
46 template <typename... Args> static Ptr<type> New(Args... args) { \
47 fl::Ptr<type> ptr = constructor(args...); \
56template <
typename T>
class Ptr;
57template <
typename T>
class WeakPtr;
59template <
typename T,
typename... Args> Ptr<T>
NewPtr(Args...
args);
69 T *ptr =
new T(
args...);
137 template <
typename U,
typename = fl::is_derived<T, U>>
148 Ptr(T *referent) =
delete;
158 other.referent_ =
nullptr;
168 if (
this != &other) {
200 if (
this != &other) {
205 other.referent_ =
nullptr;
216 explicit operator bool() const noexcept {
return referent_ !=
nullptr; }
247 other.referent_ = temp;
299 ptr->setWeakPtr(weakRefNoCreate);
300 weakRefNoCreate->setReferent(ptr.
get());
312 ptr->setWeakPtr(weakRefNoCreate);
313 weakRefNoCreate->setReferent(ptr.
get());
321 template <
typename U>
347 return other ==
nullptr;
349 return mWeakPtr->getReferent() == other;
360 bool equal = *
this == other;
373 T *out =
static_cast<T *
>(
mWeakPtr->getReferent());
374 if (out->ref_count() == 0) {
415 virtual void ref()
const;
416 virtual void unref()
const;
421 template <
typename T>
friend class Ptr;
439 T *referent =
static_cast<T *
>(tmp->
getReferent());
bool operator<(const Ptr &other) const
void reset(Ptr< T > &refptr)
static Ptr TakeOwnership(T *ptr)
void swap(Ptr &other) noexcept
Ptr(T *referent, bool from_heap)
Ptr & operator=(Ptr &&other) noexcept
static Ptr< T > New(Args... args)
Ptr(Ptr &&other) noexcept
WeakPtr< T > weakRefNoCreate() const
Ptr(const Ptr< U > &refptr)
bool operator==(const Ptr &other) const
static Ptr NoTracking(T &referent)
bool operator!=(const Ptr &other) const
Ptr & operator=(T *referent)=delete
Ptr & operator=(const Ptr &other)
WeakPtr< T > weakPtr() const
bool operator==(const T *other) const
bool operator!=(const T *other) const
static Ptr< T > New(Args... args)
virtual int ref_count() const
Referent & operator=(const Referent &)
Ptr< WeakReferent > mWeakPtr
Referent & operator=(Referent &&)
void setWeakPtr(Ptr< WeakReferent > weakRefNoCreate)
Referent(const Referent &)
virtual void destroy() const
virtual void unref() const
friend class WeakReferent
WeakPtr & operator=(const WeakPtr &other)
bool operator==(const T *other) const
bool operator==(const Ptr< T > &other) const
bool operator==(T *other) const
bool operator==(const WeakPtr &other) const
WeakPtr(const Ptr< U > &ptr)
WeakPtr(const WeakPtr< U > &other)
bool operator!=(const WeakPtr &other) const
bool operator!=(const T *other) const
WeakPtr(const WeakPtr &other)
WeakPtr(const Ptr< T > &ptr)
WeakPtr(WeakPtr &&other) noexcept
Ptr< WeakReferent > mWeakPtr
WeakReferent & operator=(WeakReferent &&)=default
void setReferent(Referent *referent)
WeakReferent(const WeakReferent &)=default
WeakReferent & operator=(const WeakReferent &)=default
Referent * getReferent() const
WeakReferent(WeakReferent &&)=default
Implements the FastLED namespace macros.
Ptr< T > NewPtr(Args... args)
Ptr< T > NewPtrNoTracking(Args... args)
Implements a simple red square effect for 2D LED grids.