ORIGINAL
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
original::autoPtr< TYPE, DERIVED, DELETER > Class Template Reference

Base smart pointer with reference counting. More...

#include <autoPtr.h>

Inheritance diagram for original::autoPtr< TYPE, DERIVED, DELETER >:
Inheritance graph
Collaboration diagram for original::autoPtr< TYPE, DERIVED, DELETER >:
Collaboration graph

Public Member Functions

u_integer strongRefs () const
 Get strong reference count.
 
u_integer weakRefs () const
 Get weak reference count.
 
bool exist () const
 Check active ownership.
 
bool expired () const
 Check resource validity.
 
 operator bool () const
 Boolean conversion operator.
 
bool operator! () const
 Logical NOT operator.
 
const TYPEget () const
 Get managed pointer const version.
 
TYPEget ()
 Get managed pointer.
 
virtual const TYPEoperator* () const
 Const dereference operator.
 
virtual const TYPEoperator-> () const
 Const member access operator.
 
virtual const TYPEoperator[] (u_integer index) const
 Const array access operator.
 
virtual TYPEoperator* ()
 Mutable dereference operator.
 
virtual TYPEoperator-> ()
 Mutable member access operator.
 
virtual TYPEoperator[] (u_integer index)
 Mutable array access operator.
 
void swap (autoPtr &other) noexcept
 Swaps the reference counters between two autoPtr instances.
 
integer compareTo (const autoPtr &other) const override
 Compare reference counters.
 
std::string className () const override
 Get class name string.
 
std::string toString (bool enter) const override
 String representation formatter.
 
u_integer toHash () const noexcept override
 Compute hash value for the pointer.
 
bool equals (const autoPtr &other) const noexcept override
 Equality comparison.
 
 ~autoPtr () override
 Destructor triggers reference cleanup.
 
- Public Member Functions inherited from original::printable
 operator std::string () const
 Explicit conversion to std::string.
 
 operator const char * () const
 Explicit conversion to C-style string.
 
const chartoCString (bool enter) const
 Direct C-string access with formatting control.
 
template<typename TYPE >
auto formatString (const TYPE &t) -> std::string
 
template<typename TYPE >
auto formatCString (const TYPE &t) -> const char *
 
template<typename TYPE >
auto formatEnum (const TYPE &t) -> std::string
 
template<typename TYPE >
auto formatString (TYPE *const &ptr) -> std::string
 
- Public Member Functions inherited from original::comparable< autoPtr< TYPE, DERIVED, DELETER > >
bool operator== (const autoPtr< TYPE, DERIVED, DELETER > &other) const
 Checks if the current object is equal to another.
 
bool operator!= (const autoPtr< TYPE, DERIVED, DELETER > &other) const
 Checks if the current object is not equal to another.
 
bool operator< (const autoPtr< TYPE, DERIVED, DELETER > &other) const
 Checks if the current object is less than another.
 
bool operator> (const autoPtr< TYPE, DERIVED, DELETER > &other) const
 Checks if the current object is greater than another.
 
bool operator<= (const autoPtr< TYPE, DERIVED, DELETER > &other) const
 Checks if the current object is less than or equal to another.
 
bool operator>= (const autoPtr< TYPE, DERIVED, DELETER > &other) const
 Checks if the current object is greater than or equal to another.
 
virtual ~comparable ()=default
 Virtual destructor for proper cleanup of derived objects.
 
- Public Member Functions inherited from original::hashable< autoPtr< TYPE, DERIVED, DELETER > >
virtual bool equals (const autoPtr< TYPE, DERIVED, DELETER > &other) const noexcept
 Compares two objects for equality.
 
virtual ~hashable ()=0
 Virtual destructor.
 

Protected Member Functions

 autoPtr (TYPE *p)
 Construct from raw pointer.
 
void addStrongRef () const
 Increment strong reference count.
 
void addWeakRef () const
 Increment weak reference count.
 
void removeStrongRef () const
 Decrement strong reference count.
 
void removeWeakRef () const
 Decrement weak reference count.
 
TYPEreleasePtr () noexcept
 Release ownership of the managed pointer.
 
void destroyRefCnt () noexcept
 Destroy reference counter.
 
void clean () noexcept
 Cleanup resources when expired.
 

Static Protected Member Functions

static refCount< TYPE, DELETER > * newRefCount (TYPE *p=nullptr)
 Create new reference counter.
 

Protected Attributes

atomic< refCountBase * > ref_count
 Reference counter object.
 
TYPEalias_ptr
 Aliased pointer for type casting scenarios.
 

Friends

template<typename T , typename DER , typename DEL >
bool operator== (const autoPtr< T, DER, DEL > &ptr, const std::nullptr_t &null)
 Equality comparison with nullptr.
 
template<typename T , typename DER , typename DEL >
bool operator!= (const autoPtr< T, DER, DEL > &ptr, const std::nullptr_t &null)
 Inequality comparison with nullptr.
 
template<typename T , typename DER , typename DEL >
bool operator== (const std::nullptr_t &null, const autoPtr< T, DER, DEL > &ptr)
 Equality comparison with nullptr (reversed operands)
 
template<typename T , typename DER , typename DEL >
bool operator!= (const std::nullptr_t &null, const autoPtr< T, DER, DEL > &ptr)
 Inequality comparison with nullptr (reversed operands)
 

Additional Inherited Members

- Static Public Member Functions inherited from original::printable
template<typename TYPE >
static std::string formatString (const TYPE &t)
 Universal value-to-string conversion with type-specific formatting.
 
template<Printable TYPE>
static std::string formatString (const TYPE &t)
 Specialization for types deriving from printable.
 
template<EnumType TYPE>
static std::string formatString (const TYPE &t)
 Specialization for enum types with type-safe formatting.
 
template<typename TYPE >
static std::string formatString (TYPE *const &ptr)
 Pointer-specific formatting with null safety.
 
template<typename TYPE >
static const charformatCString (const TYPE &t)
 C-string cache for temporary usage with static storage.
 
template<typename TYPE >
static std::string formatEnum (const TYPE &t)
 Enum formatting utility with underlying value extraction.
 
template<>
auto formatString (const char &t) -> std::string
 
template<>
auto formatString (const bool &t) -> std::string
 
template<>
auto formatString (const char *const &ptr) -> std::string
 

Detailed Description

template<typename TYPE, typename DERIVED, typename DELETER>
class original::autoPtr< TYPE, DERIVED, DELETER >

Base smart pointer with reference counting.

Template Parameters
TYPEManaged object type
DERIVEDCRTP pattern parameter for inheritance
DELETERCustom deleter policy type

Provides core resource management capabilities through:

Memory Management Strategy:

Thread Safety:

Constructor & Destructor Documentation

◆ autoPtr()

original::autoPtr< TYPE, DERIVED, DELETER >::autoPtr ( TYPE p)
explicitprotected

Construct from raw pointer.

Parameters
pRaw pointer to manage
Warning
Ownership is transferred to autoPtr
Postcondition
ref_count points to new refCount object managing p

◆ ~autoPtr()

Destructor triggers reference cleanup.

Decrements reference counts and may trigger object destruction

Member Function Documentation

◆ className()

std::string original::autoPtr< TYPE, DERIVED, DELETER >::className ( ) const
overridevirtual

◆ compareTo()

original::integer original::autoPtr< TYPE, DERIVED, DELETER >::compareTo ( const autoPtr< TYPE, DERIVED, DELETER > &  other) const
overridevirtual

Compare reference counters.

Parameters
otherautoPtr to compare with
Returns
Difference between managed pointer addresses
Note
Comparison is based on pointer values, not object contents

Implements original::comparable< autoPtr< TYPE, DERIVED, DELETER > >.

◆ destroyRefCnt()

void original::autoPtr< TYPE, DERIVED, DELETER >::destroyRefCnt ( )
protectednoexcept

Destroy reference counter.

Note
Only destroys counter when both ref counts reach zero

◆ equals()

bool original::autoPtr< TYPE, DERIVED, DELETER >::equals ( const autoPtr< TYPE, DERIVED, DELETER > &  other) const
overridenoexcept

Equality comparison.

Parameters
otherautoPtr to compare with
Returns
True if both manage same pointer
Note
Compares pointer addresses, not values

◆ exist()

Check active ownership.

Returns
True if it has active references (strong or weak)
Note
Different from operator bool() which checks for valid object

◆ expired()

Check resource validity.

Returns
True if strong references == 0
Note
Indicates the managed object has been destroyed

◆ get() [1/2]

Get managed pointer.

Returns
Raw pointer to managed object
Exceptions
nullPointerErrorif no active references
Note
Returns alias_ptr if set, otherwise the actual managed pointer

◆ get() [2/2]

Get managed pointer const version.

Returns
Raw pointer to managed object
Exceptions
nullPointerErrorif no active references
Note
Returns alias_ptr if set, otherwise the actual managed pointer

◆ newRefCount()

original::refCount< TYPE, DELETER > * original::autoPtr< TYPE, DERIVED, DELETER >::newRefCount ( TYPE p = nullptr)
staticprotected

Create new reference counter.

Parameters
pPointer to manage (nullptr allowed)
Returns
Newly created counter object
Exceptions
std::bad_allocif memory allocation fails

◆ operator bool()

original::autoPtr< TYPE, DERIVED, DELETER >::operator bool ( ) const
explicit

Boolean conversion operator.

Returns
True if has strong reference and managed pointer is non-null
Note
Considers both reference count and pointer validity

◆ operator!()

Logical NOT operator.

Returns
Opposite of operator bool()

◆ operator*() [1/2]

TYPE & original::autoPtr< TYPE, DERIVED, DELETER >::operator* ( )
virtual

Mutable dereference operator.

Returns
Reference to managed object
Exceptions
nullPointerErrorif no managed object

Reimplemented in original::weakPtr< TYPE, DELETER >.

◆ operator*() [2/2]

const TYPE & original::autoPtr< TYPE, DERIVED, DELETER >::operator* ( ) const
virtual

Const dereference operator.

Returns
Reference to managed object
Exceptions
nullPointerErrorif no managed object

Reimplemented in original::weakPtr< TYPE, DELETER >.

◆ operator->() [1/2]

TYPE * original::autoPtr< TYPE, DERIVED, DELETER >::operator-> ( )
virtual

Mutable member access operator.

Returns
Pointer to managed object
Exceptions
nullPointerErrorif no managed object

Reimplemented in original::weakPtr< TYPE, DELETER >.

◆ operator->() [2/2]

const TYPE * original::autoPtr< TYPE, DERIVED, DELETER >::operator-> ( ) const
virtual

Const member access operator.

Returns
Pointer to managed object
Exceptions
nullPointerErrorif no managed object

Reimplemented in original::weakPtr< TYPE, DELETER >.

◆ operator[]() [1/2]

TYPE & original::autoPtr< TYPE, DERIVED, DELETER >::operator[] ( u_integer  index)
virtual

Mutable array access operator.

Parameters
indexArray index
Returns
Reference to element
Exceptions
nullPointerErrorif no managed array
outOfBoundErrorif index is invalid

Reimplemented in original::weakPtr< TYPE, DELETER >.

◆ operator[]() [2/2]

const TYPE & original::autoPtr< TYPE, DERIVED, DELETER >::operator[] ( u_integer  index) const
virtual

Const array access operator.

Parameters
indexArray index
Returns
Reference to element
Exceptions
nullPointerErrorif no managed array
outOfBoundErrorif index is invalid

Reimplemented in original::weakPtr< TYPE, DELETER >.

◆ releasePtr()

TYPE * original::autoPtr< TYPE, DERIVED, DELETER >::releasePtr ( )
protectednoexcept

Release ownership of the managed pointer.

Returns
Raw pointer to the managed object
Note
The caller becomes responsible for deleting the returned pointer
Postcondition
Reference counter retains weak references but no strong references
Warning
After release, the autoPtr becomes empty and should not be used

◆ strongRefs()

Get strong reference count.

Returns
Current number of strong references
Note
Returns 0 if no reference counter exists

◆ swap()

Swaps the reference counters between two autoPtr instances.

Parameters
otherAnother autoPtr instance to swap with
Postcondition
After swapping:
  • Current object acquires other's reference counter
  • Other object acquires current object's reference counter
  • Managed object ownership transfers implicitly
  • alias_ptr values are also swapped
Warning
This operation is not thread-safe. Do not call swap concurrently from multiple threads on the same autoPtr instances, as it may lead to data races and undefined behavior.
Examples
/home/runner/work/original/original/src/core/tuple.h, and /home/runner/work/original/original/src/core/vector.h.

◆ toHash()

original::u_integer original::autoPtr< TYPE, DERIVED, DELETER >::toHash ( ) const
overridevirtualnoexcept

Compute hash value for the pointer.

Returns
Hash of managed pointer address
Note
Uses hash<TYPE> specialization
Warning
Hash is based on pointer address, not object contents

Reimplemented from original::hashable< autoPtr< TYPE, DERIVED, DELETER > >.

◆ toString()

std::string original::autoPtr< TYPE, DERIVED, DELETER >::toString ( bool  enter) const
overridevirtual

◆ weakRefs()

Get weak reference count.

Returns
Current number of weak references
Note
Returns 0 if no reference counter exists

Friends And Related Symbol Documentation

◆ operator!= [1/2]

template<typename T , typename DER , typename DEL >
bool operator!= ( const autoPtr< T, DER, DEL > &  ptr,
const std::nullptr_t &  null 
)
friend

Inequality comparison with nullptr.

Template Parameters
TManaged object type
DERCRTP derived class type
DELDeleter policy type
Parameters
ptrautoPtr to compare
nullnullptr_t to compare against
Returns
true if the autoPtr is not empty (has a managed object)
Note
Equivalent to checking operator bool() of ptr

◆ operator!= [2/2]

template<typename T , typename DER , typename DEL >
bool operator!= ( const std::nullptr_t &  null,
const autoPtr< T, DER, DEL > &  ptr 
)
friend

Inequality comparison with nullptr (reversed operands)

Template Parameters
TManaged object type
DERCRTP derived class type
DELDeleter policy type
Parameters
ptrautoPtr to compare
nullnullptr_t to compare against
Returns
true if the autoPtr is not empty (has a managed object)
Note
Equivalent to checking operator bool() of ptr

◆ operator== [1/2]

template<typename T , typename DER , typename DEL >
bool operator== ( const autoPtr< T, DER, DEL > &  ptr,
const std::nullptr_t &  null 
)
friend

Equality comparison with nullptr.

Template Parameters
TManaged object type
DERCRTP derived class type
DELDeleter policy type
Parameters
ptrautoPtr to compare
nullnullptr_t to compare against
Returns
true if the autoPtr is empty (no managed object)
Note
Equivalent to checking !operator bool() of ptr

◆ operator== [2/2]

template<typename T , typename DER , typename DEL >
bool operator== ( const std::nullptr_t &  null,
const autoPtr< T, DER, DEL > &  ptr 
)
friend

Equality comparison with nullptr (reversed operands)

Template Parameters
TManaged object type
DERCRTP derived class type
DELDeleter policy type
Parameters
ptrautoPtr to compare
nullnullptr_t to compare against
Returns
true if the autoPtr is empty (no managed object)
Note
Equivalent to checking !operator bool() of ptr

The documentation for this class was generated from the following file: