17#define FASTLED_SMART_PTR(type) \
19 using type##Ptr = fl::Ptr<type>;
21#define FASTLED_SMART_PTR_NO_FWD(type) using type##Ptr = fl::Ptr<type>;
25#define FASTLED_SMART_PTR_CONSTRUCTOR(type, constructor) \
26 template <> class PtrTraits<type> { \
28 template <typename... Args> static Ptr<type> New(Args... args) { \
29 fl::Ptr<type> ptr = constructor(args...); \
40template <
typename T>
class Ptr;
41template <
typename T>
class WeakPtr;
44template <
typename T>
class Ptr;
45template <
typename T>
class WeakPtr;
52 template <
typename... Args>
static Ptr<T> New(Args... args) {
53 T *ptr =
new T(args...);
106 template <
typename... Args>
static Ptr<T> New(Args... args) {
120 template <
typename U,
typename = fl::is_derived<T, U>>
133 Ptr(T *referent) =
delete;
143 other.referent_ =
nullptr;
153 if (
this != &other) {
185 if (
this != &other) {
190 other.referent_ =
nullptr;
201 explicit operator bool() const noexcept {
return referent_ !=
nullptr; }
232 other.referent_ = temp;
284 ptr->setWeakPtr(weakRefNoCreate);
285 weakRefNoCreate->setReferent(ptr.
get());
297 ptr->setWeakPtr(weakRefNoCreate);
298 weakRefNoCreate->setReferent(ptr.
get());
306 template <
typename U>
332 return other ==
nullptr;
334 return mWeakPtr->getReferent() == other;
345 bool equal = *
this == other;
358 T* out =
static_cast<T*
>(
mWeakPtr->getReferent());
359 if (out->ref_count() == 0) {
400 virtual void unref();
405 template <
typename T>
friend class Ptr;
422 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 &)
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.
Implements a simple red square effect for 2D LED grids.