106 template <
typename... Args>
static Ptr<T> New(Args... args) {
111 static Ptr TakeOwnership(T *ptr) {
return Ptr(ptr,
true); }
116 static Ptr NoTracking(T &referent) {
return Ptr(&referent,
false); }
120 template <
typename U,
typename = fl::is_derived<T, U>>
121 Ptr(
const Ptr<U>& refptr) : referent_(refptr.get()) {
122 if (referent_ && isOwned()) {
129 Ptr() : referent_(
nullptr) {}
133 Ptr(T *referent) =
delete;
134 Ptr &operator=(T *referent) =
delete;
136 Ptr(
const Ptr &other) : referent_(other.referent_) {
137 if (referent_ && isOwned()) {
142 Ptr(
Ptr &&other) noexcept : referent_(other.referent_) {
143 other.referent_ =
nullptr;
147 if (referent_ && isOwned()) {
152 Ptr &operator=(
const Ptr &other) {
153 if (
this != &other) {
154 if (referent_ && isOwned()) {
157 referent_ = other.referent_;
158 if (referent_ && isOwned()) {
169 bool operator==(
const T *other)
const {
return referent_ == other; }
171 bool operator!=(
const T *other)
const {
return referent_ != other; }
174 return referent_ == other.referent_;
177 return referent_ != other.referent_;
181 return referent_ < other.referent_;
184 Ptr &operator=(
Ptr &&other)
noexcept {
185 if (
this != &other) {
186 if (referent_ && isOwned()) {
189 referent_ = other.referent_;
190 other.referent_ =
nullptr;
195 T *get()
const {
return referent_; }
197 T *operator->()
const {
return referent_; }
199 T &
operator*()
const {
return *referent_; }
201 explicit operator bool()
const noexcept {
return referent_ !=
nullptr; }
204 if (referent_ && isOwned()) {
210 void reset(
Ptr<T> &refptr) {
211 if (refptr.referent_ != referent_) {
212 if (refptr.referent_ && refptr.isOwned()) {
213 refptr.referent_->ref();
215 if (referent_ && isOwned()) {
218 referent_ = refptr.referent_;
229 void swap(
Ptr &other)
noexcept {
231 referent_ = other.referent_;
232 other.referent_ = temp;
235 bool isOwned()
const {
return referent_ && referent_->ref_count() > 0; }
238 Ptr(T *referent,
bool from_heap) : referent_(referent) {
239 if (referent_ && from_heap) {
280 WeakPtr weakRefNoCreate = ptr.weakRefNoCreate();
281 bool expired = weakRefNoCreate.expired();
284 ptr->setWeakPtr(weakRefNoCreate);
285 weakRefNoCreate->setReferent(ptr.get());
287 mWeakPtr = ptr->mWeakPtr;
291 template <
typename U>
WeakPtr(
const Ptr<U> &ptr) : mWeakPtr(ptr->mWeakPtr) {
293 WeakPtr weakRefNoCreate = ptr.weakRefNoCreate();
294 bool expired = weakRefNoCreate.expired();
297 ptr->setWeakPtr(weakRefNoCreate);
298 weakRefNoCreate->setReferent(ptr.get());
300 mWeakPtr = ptr->mWeakPtr;
306 template <
typename U>
313 operator bool()
const {
return mWeakPtr && mWeakPtr->getReferent(); }
315 bool operator!()
const {
320 bool operator==(
const WeakPtr &other)
const {
321 return mWeakPtr == other.mWeakPtr;
324 bool operator!=(
const WeakPtr &other)
const {
325 return !(mWeakPtr != other.mWeakPtr);
328 bool operator==(
const T *other)
const {
return lock().get() == other; }
330 bool operator==(T *other)
const {
332 return other ==
nullptr;
334 return mWeakPtr->getReferent() == other;
337 bool operator==(
const Ptr<T> &other)
const {
341 return mWeakPtr->getReferent() == other.get();
344 bool operator!=(
const T *other)
const {
345 bool equal = *
this == other;
350 this->mWeakPtr = other.mWeakPtr;
358 T* out =
static_cast<T*
>(mWeakPtr->getReferent());
359 if (out->ref_count() == 0) {
367 bool expired()
const {
371 if (!mWeakPtr->getReferent()) {
FASTLED_FORCE_INLINE bool operator<(const CRGB &lhs, const CRGB &rhs)
Check if the sum of the color channels in one CRGB object is less than another.
FASTLED_FORCE_INLINE CRGB operator*(const CRGB &p1, uint8_t d)
Multiply each of the channels by a constant, saturating each channel at 0xFF.