21 template<
typename TYPE,
typename DELETER>
38 template<
typename TYPE,
typename DERIVED,
typename DELETER>
40 public comparable<autoPtr<TYPE, DERIVED, DELETER>>,
41 public hashable<autoPtr<TYPE, DERIVED, DELETER>> {
132 explicit operator
bool() const;
153 virtual const TYPE& operator*() const;
160 virtual const TYPE* operator->() const;
176 virtual TYPE& operator*();
183 virtual TYPE* operator->();
226 bool equals(const
autoPtr& other) const noexcept override;
233 template<typename T, typename DER, typename DEL>
234 friend
bool operator==(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
236 template<typename T, typename DER, typename DEL>
237 friend
bool operator!=(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
239 template<typename T, typename DER, typename DEL>
240 friend
bool operator==(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
242 template<typename T, typename DER, typename DEL>
243 friend
bool operator!=(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
256 template<typename T, typename DER, typename DEL>
257 bool operator==(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
269 template<typename T, typename DER, typename DEL>
270 bool operator!=(const
autoPtr<T, DER, DEL>& ptr, const std::nullptr_t& null);
282 template<typename T, typename DER, typename DEL>
283 bool operator==(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
295 template<typename T, typename DER, typename DEL>
296 bool operator!=(const std::nullptr_t& null, const
autoPtr<T, DER, DEL>& ptr);
308 template<typename TYPE, typename DELETER>
310 template <
typename,
typename,
typename>
322 explicit refCount(TYPE* p =
nullptr);
327 void destroyPtr()
noexcept;
336template<
typename TYPE,
typename DERIVED,
typename DELETER>
338 : ref_count(newRefCount(p)) {}
341template<
typename TYPE,
typename DERIVED,
typename DELETER>
346 this->ref_count->ptr = p;
349template<
typename TYPE,
typename DERIVED,
typename DELETER>
351 this->ref_count->strong_refs += 1;
354template<
typename TYPE,
typename DERIVED,
typename DELETER>
356 this->ref_count->weak_refs += 1;
359template<
typename TYPE,
typename DERIVED,
typename DELETER>
361 this->ref_count->strong_refs -= 1;
364template<
typename TYPE,
typename DERIVED,
typename DELETER>
366 this->ref_count->weak_refs -= 1;
369template<
typename TYPE,
typename DERIVED,
typename DELETER>
371 delete this->ref_count;
372 this->ref_count =
nullptr;
375template<
typename TYPE,
typename DERIVED,
typename DELETER>
378 this->destroyRefCnt();
380 if (this->expired()){
381 this->ref_count->destroyPtr();
385template <
typename TYPE,
typename DERIVED,
typename DELETER>
391template<
typename TYPE,
typename DERIVED,
typename DELETER>
393 return this->ref_count->strong_refs;
396template<
typename TYPE,
typename DERIVED,
typename DELETER>
398 return this->ref_count->weak_refs;
401template<
typename TYPE,
typename DERIVED,
typename DELETER>
403 return this->ref_count && (this->strongRefs() > 0 || this->weakRefs() > 0);
406template<
typename TYPE,
typename DERIVED,
typename DELETER>
408 return this->ref_count && this->strongRefs() == 0;
411template<
typename TYPE,
typename DERIVED,
typename DELETER>
413 return this->exist() && this->get();
416template<
typename TYPE,
typename DERIVED,
typename DELETER>
421 return this->ref_count->ptr;
424template<
typename TYPE,
typename DERIVED,
typename DELETER>
429 return this->ref_count->ptr;
432template<
typename TYPE,
typename DERIVED,
typename DELETER>
434 const auto ptr = this->get();
440template<
typename TYPE,
typename DERIVED,
typename DELETER>
443 const auto ptr = this->get();
449template<
typename TYPE,
typename DERIVED,
typename DELETER>
451 const auto ptr = this->get();
457template<
typename TYPE,
typename DERIVED,
typename DELETER>
459 auto ptr = this->get();
465template<
typename TYPE,
typename DERIVED,
typename DELETER>
468 auto ptr = this->get();
474template<
typename TYPE,
typename DERIVED,
typename DELETER>
476 auto ptr = this->get();
482template<
typename TYPE,
typename DERIVED,
typename DELETER>
484 auto other_ref_count = other.ref_count;
485 other.ref_count = this->ref_count;
486 this->ref_count = other_ref_count;
489template<
typename TYPE,
typename DERIVED,
typename DELETER>
491 return this->ref_count - other.
ref_count;
494template<
typename TYPE,
typename DERIVED,
typename DELETER>
499template<
typename TYPE,
typename DERIVED,
typename DELETER>
501 std::stringstream ss;
502 ss << this->className() <<
"(";
503 ss << formatString(this->get());
510template<
typename TYPE,
typename DERIVED,
typename DELETER>
515template<
typename TYPE,
typename DERIVED,
typename DELETER>
517 return *
this == other;
520template<
typename TYPE,
typename DERIVED,
typename DELETER>
525template<
typename T,
typename DER,
typename DEL>
527 return !ptr.operator bool();
530template<
typename T,
typename DER,
typename DEL>
532 return ptr.operator bool();
535template<
typename T,
typename DER,
typename DEL>
537 return !ptr.operator bool();
540template<
typename T,
typename DER,
typename DEL>
542 return ptr.operator bool();
545template<
typename TYPE,
typename DELETER>
547 : ptr(p), strong_refs(0), weak_refs(0) {}
549template<
typename TYPE,
typename DELETER>
551 TYPE* tmp = this->ptr;
556template<
typename TYPE,
typename DELETER>
Base smart pointer with reference counting.
Definition autoPtr.h:41
static refCount< TYPE, DELETER > * newRefCount(TYPE *p=nullptr)
Create new reference counter.
Definition autoPtr.h:386
integer compareTo(const autoPtr &other) const override
Compare reference counters.
Definition autoPtr.h:490
void destroyRefCnt() noexcept
Destroy reference counter.
Definition autoPtr.h:370
void removeStrongRef()
Decrement strong reference count.
Definition autoPtr.h:360
virtual const TYPE & operator[](u_integer index) const
Const array access operator.
Definition autoPtr.h:450
u_integer strongRefs() const
Get strong reference count.
Definition autoPtr.h:392
~autoPtr() override
Destructor triggers reference cleanup.
Definition autoPtr.h:521
void addStrongRef()
Increment strong reference count.
Definition autoPtr.h:350
bool exist() const
Check active ownership.
Definition autoPtr.h:402
void setPtr(TYPE *p)
Replace managed pointer.
Definition autoPtr.h:342
void removeWeakRef()
Decrement weak reference count.
Definition autoPtr.h:365
void addWeakRef()
Increment weak reference count.
Definition autoPtr.h:355
std::string className() const override
Get class name string.
Definition autoPtr.h:495
void swap(autoPtr &other) noexcept
Swaps the reference counters between two autoPtr instances.
Definition autoPtr.h:483
u_integer toHash() const noexcept override
Computes the hash of the object.
Definition autoPtr.h:511
bool expired() const
Check resource validity.
Definition autoPtr.h:407
void clean() noexcept
Cleanup resources when expired.
Definition autoPtr.h:376
u_integer weakRefs() const
Get weak reference count.
Definition autoPtr.h:397
autoPtr(TYPE *p)
Construct from raw pointer.
Definition autoPtr.h:337
refCount< TYPE, DELETER > * ref_count
Reference counter object.
Definition autoPtr.h:43
virtual const TYPE & operator*() const
Const dereference operator.
Definition autoPtr.h:433
std::string toString(bool enter) const override
String representation formatter.
Definition autoPtr.h:500
const TYPE * get() const
Get managed pointer const version.
Definition autoPtr.h:417
virtual const TYPE * operator->() const
Const member access operator.
Definition autoPtr.h:442
Base class for comparable objects.
Definition comparable.h:31
Default deletion policy for single objects.
Definition deleter.h:79
static u_integer hashFunc(const T &t) noexcept
Default hash function fallback.
Forward declaration of hashable interface template.
Definition hash.h:216
Exception for null pointer dereference attempts.
Definition error.h:110
Base class providing polymorphic string conversion capabilities.
Definition printable.h:29
Reference counting metadata container.
Definition autoPtr.h:309
Interface for objects that can be compared.
Platform-independent integer and floating-point type definitions.
Custom exception classes and callback validation utilities.
Provides a generic hashing utility and a base interface for hashable types.
Main namespace for the project Original.
Definition algorithms.h:21
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:43
bool operator!=(const autoPtr< T, DER, DEL > &ptr, const std::nullptr_t &null)
Inequality comparison with nullptr.
Definition autoPtr.h:531
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:35
bool operator==(const autoPtr< T, DER, DEL > &ptr, const std::nullptr_t &null)
Equality comparison with nullptr.
Definition autoPtr.h:526
Interface for polymorphic string formatting and output.