103 template <
typename... Args>
static Ref<T> New(Args... args) {
108 static Ref TakeOwnership(T *ptr) {
return Ref(ptr,
true); }
113 static Ref NoTracking(T &referent) {
return Ref(&referent,
false); }
117 template <
typename U,
typename = fl::is_derived<T, U>>
118 Ref(
const Ref<U>& refptr) : referent_(refptr.get()) {
119 if (referent_ && isOwned()) {
126 Ref() : referent_(
nullptr) {}
130 Ref(T *referent) =
delete;
131 Ref &operator=(T *referent) =
delete;
133 Ref(
const Ref &other) : referent_(other.referent_) {
134 if (referent_ && isOwned()) {
139 Ref(
Ref &&other) noexcept : referent_(other.referent_) {
140 other.referent_ =
nullptr;
144 if (referent_ && isOwned()) {
149 Ref &operator=(
const Ref &other) {
150 if (
this != &other) {
151 if (referent_ && isOwned()) {
154 referent_ = other.referent_;
155 if (referent_ && isOwned()) {
166 bool operator==(
const T *other)
const {
return referent_ == other; }
168 bool operator!=(
const T *other)
const {
return referent_ != other; }
171 return referent_ == other.referent_;
174 return referent_ != other.referent_;
178 return referent_ < other.referent_;
181 Ref &operator=(
Ref &&other)
noexcept {
182 if (
this != &other) {
183 if (referent_ && isOwned()) {
186 referent_ = other.referent_;
187 other.referent_ =
nullptr;
192 T *get()
const {
return referent_; }
194 T *operator->()
const {
return referent_; }
196 T &
operator*()
const {
return *referent_; }
198 explicit operator bool()
const noexcept {
return referent_ !=
nullptr; }
201 if (referent_ && isOwned()) {
207 void reset(
Ref<T> &refptr) {
208 if (refptr.referent_ != referent_) {
209 if (refptr.referent_ && refptr.isOwned()) {
210 refptr.referent_->ref();
212 if (referent_ && isOwned()) {
215 referent_ = refptr.referent_;
226 void swap(
Ref &other)
noexcept {
228 referent_ = other.referent_;
229 other.referent_ = temp;
232 bool isOwned()
const {
return referent_ && referent_->ref_count() > 0; }
235 Ref(T *referent,
bool from_heap) : referent_(referent) {
236 if (referent_ && from_heap) {
277 WeakRef weakRefNoCreate = ptr.weakRefNoCreate();
278 bool expired = weakRefNoCreate.expired();
281 ptr->setWeakRef(weakRefNoCreate);
282 weakRefNoCreate->setReferent(ptr.get());
284 mWeakRef = ptr->mWeakRef;
288 template <
typename U>
WeakRef(
const Ref<U> &ptr) : mWeakRef(ptr->mWeakRef) {
290 WeakRef weakRefNoCreate = ptr.weakRefNoCreate();
291 bool expired = weakRefNoCreate.expired();
294 ptr->setWeakRef(weakRefNoCreate);
295 weakRefNoCreate->setReferent(ptr.get());
297 mWeakRef = ptr->mWeakRef;
303 template <
typename U>
310 operator bool()
const {
return mWeakRef && mWeakRef->getReferent(); }
312 bool operator!()
const {
317 bool operator==(
const WeakRef &other)
const {
318 return mWeakRef == other.mWeakRef;
321 bool operator!=(
const WeakRef &other)
const {
322 return !(mWeakRef != other.mWeakRef);
325 bool operator==(
const T *other)
const {
return lock().get() == other; }
327 bool operator==(T *other)
const {
329 return other ==
nullptr;
331 return mWeakRef->getReferent() == other;
334 bool operator==(
const Ref<T> &other)
const {
338 return mWeakRef->getReferent() == other.get();
341 bool operator!=(
const T *other)
const {
342 bool equal = *
this == other;
347 this->mWeakRef = other.mWeakRef;
355 T* out =
static_cast<T*
>(mWeakRef->getReferent());
356 if (out->ref_count() == 0) {
364 bool expired()
const {
368 if (!mWeakRef->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.