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

Non-owning reference to shared resource. More...

#include <refCntPtr.h>

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

Public Member Functions

 weakPtr ()
 Initialize empty weak reference.
 
 weakPtr (const strongPtr< TYPE, DELETER > &other)
 Construct from strongPtr observer.
 
weakPtroperator= (const strongPtr< TYPE, DELETER > &other)
 Assign observation from strongPtr.
 
 weakPtr (const weakPtr &other)
 Copy constructor duplicates observation.
 
weakPtroperator= (const weakPtr &other)
 Copy assignment duplicates observation.
 
 weakPtr (weakPtr &&other) noexcept
 Move constructor transfers observation.
 
weakPtroperator= (weakPtr &&other) noexcept
 Move assignment transfers observation.
 
template<typename U , typename DEL = DELETER::template rebound_deleter<U>>
weakPtr< U, DELstaticCastTo ()
 Static cast to different pointer type.
 
template<typename U , typename DEL = DELETER::template rebound_deleter<const U>>
weakPtr< const U, DELstaticCastTo () const
 Static cast to const pointer type.
 
template<typename U , typename DEL = DELETER::template rebound_deleter<U>>
weakPtr< U, DELdynamicCastTo ()
 Dynamic cast to different pointer type.
 
template<typename U , typename DEL = DELETER::template rebound_deleter<const U>>
weakPtr< const U, DELdynamicCastTo () const
 Dynamic cast to const pointer type.
 
template<typename U , typename DEL = DELETER::template rebound_deleter<U>>
weakPtr< U, DELconstCastTo () const
 Const cast to remove/add const qualifier.
 
strongPtr< TYPE, DELETERlock () const
 Attempt to acquire ownership.
 
const TYPEoperator* () const override
 Const dereference via temporary strong reference.
 
const TYPEoperator-> () const override
 Const member access via temporary strong reference.
 
const TYPEoperator[] (u_integer index) const override
 Const array element access via temporary strong reference.
 
TYPEoperator* () override
 Mutable dereference via temporary strong reference.
 
TYPEoperator-> () override
 Mutable member access via temporary strong reference.
 
TYPEoperator[] (u_integer index) override
 Mutable array element access via temporary strong reference.
 
std::string className () const override
 Get class type identifier.
 
 ~weakPtr () override
 Destructor releases weak reference.
 
- Public Member Functions inherited from original::refCntPtr< TYPE, weakPtr< TYPE, DELETER >, DELETER >
bool operator== (const refCntPtr< TYPE, O_DERIVED, DELETER > &other) const
 Equality comparison operator.
 
bool operator!= (const refCntPtr< TYPE, O_DERIVED, DELETER > &other) const
 Inequality comparison operator.
 
std::string toString (bool enter) const override
 Formatted string with reference info.
 
 ~refCntPtr () override=default
 Default destructor of refCntPtr.
 
- Public Member Functions inherited from original::autoPtr< TYPE, DERIVED, DELETER >
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.
 
void swap (autoPtr &other) noexcept
 Swaps the reference counters between two autoPtr instances.
 
integer compareTo (const autoPtr &other) const override
 Compare reference counters.
 
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.
 

Friends

template<typename , typename >
class strongPtr
 

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
 
- Protected Member Functions inherited from original::refCntPtr< TYPE, weakPtr< TYPE, DELETER >, DELETER >
 refCntPtr (TYPE *p=std::nullptr_t{})
 Construct from raw pointer.
 
- Protected Member Functions inherited from original::autoPtr< TYPE, DERIVED, DELETER >
 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 inherited from original::autoPtr< TYPE, DERIVED, DELETER >
static refCount< TYPE, DELETER > * newRefCount (TYPE *p=nullptr)
 Create new reference counter.
 
- Protected Attributes inherited from original::autoPtr< TYPE, DERIVED, DELETER >
atomic< refCountBase * > ref_count
 Reference counter object.
 
TYPEalias_ptr
 Aliased pointer for type casting scenarios.
 

Detailed Description

template<typename TYPE, typename DELETER>
class original::weakPtr< TYPE, DELETER >

Non-owning reference to shared resource.

Template Parameters
TYPEManaged object type
DELETERDeletion policy type (default: deleter<TYPE>)

Provides safe access to resources managed by strongPtr:

Constructor & Destructor Documentation

◆ weakPtr() [1/3]

template<typename TYPE , typename DELETER >
original::weakPtr< TYPE, DELETER >::weakPtr ( const strongPtr< TYPE, DELETER > &  other)
explicit

Construct from strongPtr observer.

Parameters
otherSource strongPtr to observe

Creates weak reference to same resource:

  • Shares reference counter with strongPtr
  • Increments weak reference count
  • Does NOT affect strong reference count

◆ weakPtr() [2/3]

template<typename TYPE , typename DELETER >
original::weakPtr< TYPE, DELETER >::weakPtr ( const weakPtr< TYPE, DELETER > &  other)

Copy constructor duplicates observation.

Parameters
otherSource weakPtr to copy

Shares the same observation target:

  • Increments weak reference count
  • No change to strong reference count

◆ weakPtr() [3/3]

template<typename TYPE , typename DELETER >
original::weakPtr< TYPE, DELETER >::weakPtr ( weakPtr< TYPE, DELETER > &&  other)
noexcept

Move constructor transfers observation.

Parameters
otherSource weakPtr to move from
Postcondition
other becomes empty observer

◆ ~weakPtr()

Destructor releases weak reference.

Decrements weak reference count:

  • Does NOT trigger object destruction
  • Final weak reference cleans up counter

Member Function Documentation

◆ className()

template<typename TYPE , typename DELETER >
std::string original::weakPtr< TYPE, DELETER >::className ( ) const
overridevirtual

Get class type identifier.

Returns
std::string "weakPtr"

Reimplemented from original::refCntPtr< TYPE, weakPtr< TYPE, DELETER >, DELETER >.

◆ constCastTo()

template<typename TYPE , typename DELETER >
template<typename U , typename DEL >
weakPtr< U, DEL > original::weakPtr< TYPE, DELETER >::constCastTo ( ) const

Const cast to remove/add const qualifier.

Template Parameters
UTarget type for const cast
DELRebound deleter type for target type
Returns
weakPtr<U, DEL> with const removed
Note
Uses const_cast for type conversion

◆ dynamicCastTo() [1/2]

template<typename TYPE , typename DELETER >
template<typename U , typename DEL >
weakPtr< U, DEL > original::weakPtr< TYPE, DELETER >::dynamicCastTo ( )

Dynamic cast to different pointer type.

Template Parameters
UTarget type for dynamic cast
DELRebound deleter type for target type
Returns
weakPtr<U, DEL> if cast succeeds, empty weakPtr otherwise
Note
Uses dynamic_cast for type conversion

◆ dynamicCastTo() [2/2]

template<typename TYPE , typename DELETER >
template<typename U , typename DEL >
weakPtr< const U, DEL > original::weakPtr< TYPE, DELETER >::dynamicCastTo ( ) const

Dynamic cast to const pointer type.

Template Parameters
UTarget type for dynamic cast
DELRebound deleter type for target type
Returns
weakPtr<const U, DEL> if cast succeeds, empty weakPtr otherwise
Note
Uses dynamic_cast for type conversion

◆ lock()

Attempt to acquire ownership.

Returns
strongPtr<TYPE, DELETER> Valid strongPtr if resource exists

Creates temporary strong reference:

  • Returns empty strongPtr if object destroyed
  • Increments strong count if successful
  • Thread-safe atomic reference check
    Exceptions
    nothing(nothrow guarantee)

◆ operator*() [1/2]

template<typename TYPE , typename DELETER >
const TYPE & original::weakPtr< TYPE, DELETER >::operator* ( ) const
overridevirtual

Const dereference via temporary strong reference.

Returns
const TYPE& Reference to observed object
Exceptions
nullPointerErrorif object has been destroyed

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

◆ operator*() [2/2]

template<typename TYPE , typename DELETER >
TYPE & original::weakPtr< TYPE, DELETER >::operator* ( )
overridevirtual

Mutable dereference via temporary strong reference.

Returns
Reference to observed object
Exceptions
nullPointerErrorif object has been destroyed

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

◆ operator->() [1/2]

template<typename TYPE , typename DELETER >
const TYPE * original::weakPtr< TYPE, DELETER >::operator-> ( ) const
overridevirtual

Const member access via temporary strong reference.

Returns
Pointer to observed object
Exceptions
nullPointerErrorif object has been destroyed

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

◆ operator->() [2/2]

template<typename TYPE , typename DELETER >
TYPE * original::weakPtr< TYPE, DELETER >::operator-> ( )
overridevirtual

Mutable member access via temporary strong reference.

Returns
Pointer to observed object
Exceptions
nullPointerErrorif object has been destroyed

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

◆ operator=() [1/3]

template<typename TYPE , typename DELETER >
weakPtr< TYPE, DELETER > & original::weakPtr< TYPE, DELETER >::operator= ( const strongPtr< TYPE, DELETER > &  other)

Assign observation from strongPtr.

Parameters
otherSource strongPtr to observe
Returns
Reference to this weakPtr

Behavior:

  1. Releases current observation (decrements weak count)
  2. Adopts new reference counter from other
  3. Increments new weak reference count
    Note
    Handles self-assignment safely

◆ operator=() [2/3]

template<typename TYPE , typename DELETER >
weakPtr< TYPE, DELETER > & original::weakPtr< TYPE, DELETER >::operator= ( const weakPtr< TYPE, DELETER > &  other)

Copy assignment duplicates observation.

Parameters
otherSource weakPtr to copy
Returns
Reference to this weakPtr

Behavior:

  1. Releases current observation
  2. Shares other's reference counter
  3. Increments new weak reference count
    Note
    Safely handles self-assignment

◆ operator=() [3/3]

template<typename TYPE , typename DELETER >
weakPtr< TYPE, DELETER > & original::weakPtr< TYPE, DELETER >::operator= ( weakPtr< TYPE, DELETER > &&  other)
noexcept

Move assignment transfers observation.

Parameters
otherSource weakPtr to move from
Returns
Reference to this weakPtr
Postcondition
other becomes empty observer

◆ operator[]() [1/2]

template<typename TYPE , typename DELETER >
const TYPE & original::weakPtr< TYPE, DELETER >::operator[] ( u_integer  index) const
overridevirtual

Const array element access via temporary strong reference.

Parameters
indexArray position
Returns
Reference to element
Exceptions
nullPointerErrorif object has been destroyed

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

◆ operator[]() [2/2]

template<typename TYPE , typename DELETER >
TYPE & original::weakPtr< TYPE, DELETER >::operator[] ( u_integer  index)
overridevirtual

Mutable array element access via temporary strong reference.

Parameters
indexArray position
Returns
Reference to element
Exceptions
nullPointerErrorif object has been destroyed

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

◆ staticCastTo() [1/2]

template<typename TYPE , typename DELETER >
template<typename U , typename DEL >
weakPtr< U, DEL > original::weakPtr< TYPE, DELETER >::staticCastTo ( )

Static cast to different pointer type.

Template Parameters
UTarget type for static cast
DELRebound deleter type for target type
Returns
weakPtr<U, DEL> with same reference counter
Note
Uses static_cast for type conversion

◆ staticCastTo() [2/2]

template<typename TYPE , typename DELETER >
template<typename U , typename DEL >
weakPtr< const U, DEL > original::weakPtr< TYPE, DELETER >::staticCastTo ( ) const

Static cast to const pointer type.

Template Parameters
UTarget type for static cast
DELRebound deleter type for target type
Returns
weakPtr<const U, DEL> with same reference counter
Note
Uses static_cast for type conversion

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