34 template<
typename TYPE,
typename DELETER>
53 template<
typename TYPE,
typename DERIVED,
typename DELETER>
55 public comparable<autoPtr<TYPE, DERIVED, DELETER>>,
56 public hashable<autoPtr<TYPE, DERIVED, DELETER>> {
57 template<
typename,
typename,
typename>
friend class autoPtr;
150 explicit operator
bool() const;
156 bool operator!() const;
177 virtual const TYPE& operator*() const;
184 virtual const TYPE* operator->() const;
200 virtual TYPE& operator*();
207 virtual TYPE* operator->();
268 template<typename T, typename DER, typename DEL>
269 friend
bool operator==(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
271 template<typename T, typename DER, typename DEL>
272 friend
bool operator!=(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
274 template<typename T, typename DER, typename DEL>
275 friend
bool operator==(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
277 template<typename T, typename DER, typename DEL>
278 friend
bool operator!=(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
291 template<typename T, typename DER, typename DEL>
292 bool operator==(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
304 template<typename T, typename DER, typename DEL>
305 bool operator!=(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
317 template<typename T, typename DER, typename DEL>
318 bool operator==(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
330 template<typename T, typename DER, typename DEL>
331 bool operator!=(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
339 template <
typename,
typename,
typename>
355 virtual const void*
getPtr() const noexcept = 0;
361 virtual
void* getPtr() noexcept = 0;
373 virtual
void destroyPtr() noexcept = 0;
388 template<typename TYPE, typename DELETER>
390 template <
typename,
typename,
typename>
400 explicit refCount(TYPE* p =
nullptr);
402 const void* getPtr()
const noexcept override;
404 void* getPtr()
noexcept override;
411 void destroyPtr()
noexcept override;
420template<
typename TYPE,
typename DERIVED,
typename DELETER>
424template<
typename TYPE,
typename DERIVED,
typename DELETER>
430template<
typename TYPE,
typename DERIVED,
typename DELETER>
436template<
typename TYPE,
typename DERIVED,
typename DELETER>
442template<
typename TYPE,
typename DERIVED,
typename DELETER>
448template <
typename TYPE,
typename DERIVED,
typename DELETER>
451 return static_cast<TYPE*
>(this->ref_count->
releasePtr());
454template<
typename TYPE,
typename DERIVED,
typename DELETER>
456 delete this->ref_count;
457 this->ref_count =
nullptr;
460template<
typename TYPE,
typename DERIVED,
typename DELETER>
463 this->destroyRefCnt();
465 if (this->expired()){
470template <
typename TYPE,
typename DERIVED,
typename DELETER>
476template<
typename TYPE,
typename DERIVED,
typename DELETER>
481template<
typename TYPE,
typename DERIVED,
typename DELETER>
486template<
typename TYPE,
typename DERIVED,
typename DELETER>
488 return this->ref_count && (this->strongRefs() > 0 || this->weakRefs() > 0);
491template<
typename TYPE,
typename DERIVED,
typename DELETER>
493 return this->ref_count && this->strongRefs() == 0;
496template<
typename TYPE,
typename DERIVED,
typename DELETER>
498 return this->exist() && this->get();
501template <
typename TYPE,
typename DERIVED,
typename DELETER>
503 return !this->
operator bool();
506template<
typename TYPE,
typename DERIVED,
typename DELETER>
511 if (this->alias_ptr) {
512 return this->alias_ptr;
514 return static_cast<TYPE*
>(this->ref_count->
getPtr());
517template<
typename TYPE,
typename DERIVED,
typename DELETER>
522 if (this->alias_ptr) {
523 return this->alias_ptr;
525 return static_cast<TYPE*
>(this->ref_count->
getPtr());
528template<
typename TYPE,
typename DERIVED,
typename DELETER>
530 const auto ptr = this->get();
536template<
typename TYPE,
typename DERIVED,
typename DELETER>
539 const auto ptr = this->get();
545template<
typename TYPE,
typename DERIVED,
typename DELETER>
547 const auto ptr = this->get();
553template<
typename TYPE,
typename DERIVED,
typename DELETER>
555 auto ptr = this->get();
561template<
typename TYPE,
typename DERIVED,
typename DELETER>
564 auto ptr = this->get();
570template<
typename TYPE,
typename DERIVED,
typename DELETER>
572 auto ptr = this->get();
578template<
typename TYPE,
typename DERIVED,
typename DELETER>
580 auto other_ref_count = other.ref_count;
581 other.ref_count = this->ref_count;
582 this->ref_count = other_ref_count;
585template<
typename TYPE,
typename DERIVED,
typename DELETER>
587 return this->ref_count - other.
ref_count;
590template<
typename TYPE,
typename DERIVED,
typename DELETER>
595template<
typename TYPE,
typename DERIVED,
typename DELETER>
597 std::stringstream ss;
598 ss << this->className() <<
"(";
599 ss << formatString(this->get());
606template<
typename TYPE,
typename DERIVED,
typename DELETER>
611template<
typename TYPE,
typename DERIVED,
typename DELETER>
613 return *
this == other;
616template<
typename TYPE,
typename DERIVED,
typename DELETER>
621template<
typename T,
typename DER,
typename DEL>
623 return !ptr.operator bool();
626template<
typename T,
typename DER,
typename DEL>
628 return ptr.operator bool();
631template<
typename T,
typename DER,
typename DEL>
633 return !ptr.operator bool();
636template<
typename T,
typename DER,
typename DEL>
638 return ptr.operator bool();
643template<
typename TYPE,
typename DELETER>
647template <
typename TYPE,
typename DELETER>
653template <
typename TYPE,
typename DELETER>
656 if constexpr (std::is_const_v<TYPE>) {
657 return const_cast<std::remove_const_t<TYPE>*
>(this->ptr);
663template <
typename TYPE,
typename DELETER>
666 if constexpr (std::is_const_v<TYPE>) {
667 auto p =
const_cast<std::remove_const_t<TYPE>*
>(this->ptr);
677template<
typename TYPE,
typename DELETER>
679 TYPE* tmp = this->ptr;
684template<
typename TYPE,
typename DELETER>
Base smart pointer with reference counting.
Definition autoPtr.h:56
void addWeakRef() const
Increment weak reference count.
Definition autoPtr.h:431
static refCount< TYPE, DELETER > * newRefCount(TYPE *p=nullptr)
Create new reference counter.
Definition autoPtr.h:471
integer compareTo(const autoPtr &other) const override
Compare reference counters.
Definition autoPtr.h:586
void destroyRefCnt() noexcept
Destroy reference counter.
Definition autoPtr.h:455
virtual const TYPE & operator[](u_integer index) const
Const array access operator.
Definition autoPtr.h:546
u_integer strongRefs() const
Get strong reference count.
Definition autoPtr.h:477
~autoPtr() override
Destructor triggers reference cleanup.
Definition autoPtr.h:617
bool exist() const
Check active ownership.
Definition autoPtr.h:487
void removeWeakRef() const
Decrement weak reference count.
Definition autoPtr.h:443
void addStrongRef() const
Increment strong reference count.
Definition autoPtr.h:425
TYPE * alias_ptr
Aliased pointer for type casting scenarios.
Definition autoPtr.h:60
bool equals(const autoPtr &other) const noexcept override
Equality comparison.
Definition autoPtr.h:612
TYPE * releasePtr() noexcept
Release ownership of the managed pointer.
Definition autoPtr.h:449
bool operator!() const
Logical NOT operator.
Definition autoPtr.h:502
refCountBase * ref_count
Reference counter object.
Definition autoPtr.h:59
std::string className() const override
Get class name string.
Definition autoPtr.h:591
void removeStrongRef() const
Decrement strong reference count.
Definition autoPtr.h:437
void swap(autoPtr &other) noexcept
Swaps the reference counters between two autoPtr instances.
Definition autoPtr.h:579
u_integer toHash() const noexcept override
Compute hash value for the pointer.
Definition autoPtr.h:607
bool expired() const
Check resource validity.
Definition autoPtr.h:492
void clean() noexcept
Cleanup resources when expired.
Definition autoPtr.h:461
u_integer weakRefs() const
Get weak reference count.
Definition autoPtr.h:482
autoPtr(TYPE *p)
Construct from raw pointer.
Definition autoPtr.h:421
virtual const TYPE & operator*() const
Const dereference operator.
Definition autoPtr.h:529
std::string toString(bool enter) const override
String representation formatter.
Definition autoPtr.h:596
const TYPE * get() const
Get managed pointer const version.
Definition autoPtr.h:507
virtual const TYPE * operator->() const
Const member access operator.
Definition autoPtr.h:538
Base class for comparable objects.
Definition comparable.h:31
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:240
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:338
virtual const void * getPtr() const noexcept=0
Get managed pointer (const version)
refCountBase()
Construct refCountBase object.
Definition autoPtr.h:641
u_integer weak_refs
Weak reference counter.
Definition autoPtr.h:344
u_integer strong_refs
Strong reference counter.
Definition autoPtr.h:343
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:389
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:627
bool operator==(const autoPtr< T, DER, DEL > &ptr, const std::nullptr_t &null)
Equality comparison with nullptr.
Definition autoPtr.h:622
Interface for polymorphic string formatting and output.