35 template<
typename TYPE,
typename DELETER>
54 template<
typename TYPE,
typename DERIVED,
typename DELETER>
56 public comparable<autoPtr<TYPE, DERIVED, DELETER>>,
57 public hashable<autoPtr<TYPE, DERIVED, DELETER>> {
58 template<
typename,
typename,
typename>
friend class autoPtr;
151 explicit operator
bool() const;
157 bool operator!() const;
178 virtual const TYPE& operator*() const;
185 virtual const TYPE* operator->() const;
201 virtual TYPE& operator*();
208 virtual TYPE* operator->();
269 template<typename T, typename DER, typename DEL>
270 friend
bool operator==(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
272 template<typename T, typename DER, typename DEL>
273 friend
bool operator!=(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
275 template<typename T, typename DER, typename DEL>
276 friend
bool operator==(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
278 template<typename T, typename DER, typename DEL>
279 friend
bool operator!=(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
292 template<typename T, typename DER, typename DEL>
293 bool operator==(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
305 template<typename T, typename DER, typename DEL>
306 bool operator!=(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
318 template<typename T, typename DER, typename DEL>
319 bool operator==(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
331 template<typename T, typename DER, typename DEL>
332 bool operator!=(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
340 template <
typename,
typename,
typename>
356 virtual const void*
getPtr() const noexcept = 0;
362 virtual
void* getPtr() noexcept = 0;
374 virtual
void destroyPtr() noexcept = 0;
389 template<typename TYPE, typename DELETER>
391 template <
typename,
typename,
typename>
401 explicit refCount(TYPE* p =
nullptr);
403 const void* getPtr()
const noexcept override;
405 void* getPtr()
noexcept override;
412 void destroyPtr()
noexcept override;
421template<
typename TYPE,
typename DERIVED,
typename DELETER>
425template<
typename TYPE,
typename DERIVED,
typename DELETER>
429 current->strong_refs += 1;
433template<
typename TYPE,
typename DERIVED,
typename DELETER>
437 current->weak_refs += 1;
441template<
typename TYPE,
typename DERIVED,
typename DELETER>
445 current->strong_refs -= 1;
449template<
typename TYPE,
typename DERIVED,
typename DELETER>
453 current->weak_refs -= 1;
457template <
typename TYPE,
typename DERIVED,
typename DELETER>
461 if (!current)
return nullptr;
462 return static_cast<TYPE*
>(current->
releasePtr());
465template<
typename TYPE,
typename DERIVED,
typename DELETER>
468 if (!current)
return;
469 this->ref_count =
nullptr;
473template<
typename TYPE,
typename DERIVED,
typename DELETER>
483 if (strong_refs == 0) {
487 if (strong_refs == 0 && weak_refs == 0) {
488 this->ref_count =
nullptr;
493template <
typename TYPE,
typename DERIVED,
typename DELETER>
499template<
typename TYPE,
typename DERIVED,
typename DELETER>
502 if (!current)
return 0;
506template<
typename TYPE,
typename DERIVED,
typename DELETER>
509 if (!current)
return 0;
513template<
typename TYPE,
typename DERIVED,
typename DELETER>
516 if (!current)
return false;
520template<
typename TYPE,
typename DERIVED,
typename DELETER>
523 if (!current)
return true;
527template<
typename TYPE,
typename DERIVED,
typename DELETER>
530 if (!current)
return false;
532 const void* p = current->
getPtr();
533 return p !=
nullptr || this->alias_ptr !=
nullptr;
536template <
typename TYPE,
typename DERIVED,
typename DELETER>
538 return !this->
operator bool();
541template<
typename TYPE,
typename DERIVED,
typename DELETER>
546 if (this->alias_ptr) {
547 return this->alias_ptr;
550 return static_cast<TYPE*
>(current->
getPtr());
553template<
typename TYPE,
typename DERIVED,
typename DELETER>
558 if (this->alias_ptr) {
559 return this->alias_ptr;
562 return static_cast<TYPE*
>(current->
getPtr());
565template<
typename TYPE,
typename DERIVED,
typename DELETER>
567 const auto ptr = this->get();
573template<
typename TYPE,
typename DERIVED,
typename DELETER>
576 const auto ptr = this->get();
582template<
typename TYPE,
typename DERIVED,
typename DELETER>
584 const auto ptr = this->get();
590template<
typename TYPE,
typename DERIVED,
typename DELETER>
592 auto ptr = this->get();
598template<
typename TYPE,
typename DERIVED,
typename DELETER>
601 auto ptr = this->get();
607template<
typename TYPE,
typename DERIVED,
typename DELETER>
609 auto ptr = this->get();
615template<
typename TYPE,
typename DERIVED,
typename DELETER>
617 std::swap(this->alias_ptr, other.alias_ptr);
624template<
typename TYPE,
typename DERIVED,
typename DELETER>
626 return this->get() - other.
get();
629template<
typename TYPE,
typename DERIVED,
typename DELETER>
634template<
typename TYPE,
typename DERIVED,
typename DELETER>
636 std::stringstream ss;
637 ss << this->className() <<
"(";
638 ss << formatString(this->get());
645template<
typename TYPE,
typename DERIVED,
typename DELETER>
650template<
typename TYPE,
typename DERIVED,
typename DELETER>
652 return *
this == other;
655template<
typename TYPE,
typename DERIVED,
typename DELETER>
660template<
typename T,
typename DER,
typename DEL>
662 return !ptr.operator bool();
665template<
typename T,
typename DER,
typename DEL>
667 return ptr.operator bool();
670template<
typename T,
typename DER,
typename DEL>
672 return !ptr.operator bool();
675template<
typename T,
typename DER,
typename DEL>
677 return ptr.operator bool();
682template<
typename TYPE,
typename DELETER>
686template <
typename TYPE,
typename DELETER>
692template <
typename TYPE,
typename DELETER>
695 if constexpr (std::is_const_v<TYPE>) {
696 return const_cast<std::remove_const_t<TYPE>*
>(this->ptr);
702template <
typename TYPE,
typename DELETER>
705 if constexpr (std::is_const_v<TYPE>) {
706 auto p =
const_cast<std::remove_const_t<TYPE>*
>(this->ptr);
716template<
typename TYPE,
typename DELETER>
718 TYPE* tmp = this->ptr;
723template<
typename TYPE,
typename DELETER>
Base smart pointer with reference counting.
Definition autoPtr.h:57
void addWeakRef() const
Increment weak reference count.
Definition autoPtr.h:434
static refCount< TYPE, DELETER > * newRefCount(TYPE *p=nullptr)
Create new reference counter.
Definition autoPtr.h:494
integer compareTo(const autoPtr &other) const override
Compare reference counters.
Definition autoPtr.h:625
void destroyRefCnt() noexcept
Destroy reference counter.
Definition autoPtr.h:466
virtual const TYPE & operator[](u_integer index) const
Const array access operator.
Definition autoPtr.h:583
u_integer strongRefs() const
Get strong reference count.
Definition autoPtr.h:500
~autoPtr() override
Destructor triggers reference cleanup.
Definition autoPtr.h:656
bool exist() const
Check active ownership.
Definition autoPtr.h:514
void removeWeakRef() const
Decrement weak reference count.
Definition autoPtr.h:450
void addStrongRef() const
Increment strong reference count.
Definition autoPtr.h:426
TYPE * alias_ptr
Aliased pointer for type casting scenarios.
Definition autoPtr.h:61
bool equals(const autoPtr &other) const noexcept override
Equality comparison.
Definition autoPtr.h:651
TYPE * releasePtr() noexcept
Release ownership of the managed pointer.
Definition autoPtr.h:458
bool operator!() const
Logical NOT operator.
Definition autoPtr.h:537
std::string className() const override
Get class name string.
Definition autoPtr.h:630
atomic< refCountBase * > ref_count
Reference counter object.
Definition autoPtr.h:60
void removeStrongRef() const
Decrement strong reference count.
Definition autoPtr.h:442
void swap(autoPtr &other) noexcept
Swaps the reference counters between two autoPtr instances.
Definition autoPtr.h:616
u_integer toHash() const noexcept override
Compute hash value for the pointer.
Definition autoPtr.h:646
bool expired() const
Check resource validity.
Definition autoPtr.h:521
void clean() noexcept
Cleanup resources when expired.
Definition autoPtr.h:474
u_integer weakRefs() const
Get weak reference count.
Definition autoPtr.h:507
autoPtr(TYPE *p)
Construct from raw pointer.
Definition autoPtr.h:422
virtual const TYPE & operator*() const
Const dereference operator.
Definition autoPtr.h:566
std::string toString(bool enter) const override
String representation formatter.
Definition autoPtr.h:635
const TYPE * get() const
Get managed pointer const version.
Definition autoPtr.h:542
virtual const TYPE * operator->() const
Const member access operator.
Definition autoPtr.h:575
Base class for comparable objects.
Definition comparable.h:32
Default deletion policy for single objects.
Definition deleter.h:109
static u_integer hashFunc(const T &t) noexcept
Default hash function fallback.
Forward declaration of hashable interface template.
Definition hash.h:206
Exception for null pointer dereference attempts.
Definition error.h:171
Base class providing polymorphic string conversion capabilities.
Definition printable.h:39
Base class for reference counting metadata.
Definition autoPtr.h:339
atomic< u_integer > strong_refs
Strong reference counter.
Definition autoPtr.h:344
virtual const void * getPtr() const noexcept=0
Get managed pointer (const version)
refCountBase()
Construct refCountBase object.
Definition autoPtr.h:680
atomic< u_integer > weak_refs
Weak reference counter.
Definition autoPtr.h:345
virtual void destroyPtr() noexcept=0
Destroy managed pointer using deleter.
virtual void * releasePtr() noexcept=0
Release ownership of the managed pointer.
Reference counting metadata container.
Definition autoPtr.h:390
Interface for objects that can be compared.
Platform-independent type definitions and compiler/platform detection.
Custom exception classes and callback validation utilities.
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:263
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:254
Provides a generic hashing utility and interface for hashable types.
Main namespace for the project Original.
Definition algorithms.h:21
bool operator!=(const autoPtr< T, DER, DEL > &ptr, const std::nullptr_t &null)
Inequality comparison with nullptr.
Definition autoPtr.h:666
bool operator==(const autoPtr< T, DER, DEL > &ptr, const std::nullptr_t &null)
Equality comparison with nullptr.
Definition autoPtr.h:661
Interface for polymorphic string formatting and output.