MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mtcore::WeakRc< T > Struct Template Reference

Thread-local weak reference counted pointer Not thread safe, don't share Does not hold lifetime. More...

#include <rc.hpp>

Public Member Functions

Result< Rc< T >, RcErrorobtain (Allocator &alloc)
 Tries to obtain a strong reference May error if could not obtain (e.g.
 
void deinit (Allocator &alloc)
 Deinitializes a weak pointer Will decrement weak count and may clean up counter.
 
bool valid () const
 Checks if weak reference is valid.
 
 operator bool () const
 Checks if weak reference is valid.
 
Result< WeakRc, RcErrorcopy ()
 Tries to copy a weak reference.
 

Public Attributes

impl::ThreadLocalRefCount< T > * rc = nullptr
 

Detailed Description

template<typename T>
struct mtcore::WeakRc< T >

Thread-local weak reference counted pointer Not thread safe, don't share Does not hold lifetime.

May try to obtain lifetime with "obtain(alloc)"

Template Parameters
TType pointed to

Definition at line 106 of file rc.hpp.

Member Function Documentation

◆ copy()

template<typename T>
Result< WeakRc, RcError > mtcore::WeakRc< T >::copy ( )
inline

Tries to copy a weak reference.

Definition at line 145 of file rc.hpp.

145 {
146 ensure(rc, "Rc is invalid");
147 if (!rc->acquireWeak()) {
149 }
150 return *this;
151 }
#define ensure(check,...)
Ensures that a check holds true, aborts the program if not true Will print error if the condition is ...
Error< Underlying > error(Underlying err)
Creates an error.
Definition result.hpp:425
Thread-local weak reference counted pointer Not thread safe, don't share Does not hold lifetime.
Definition rc.hpp:106
impl::ThreadLocalRefCount< T > * rc
Definition rc.hpp:107
Here is the call graph for this function:

◆ deinit()

template<typename T>
void mtcore::WeakRc< T >::deinit ( Allocator & alloc)
inline

Deinitializes a weak pointer Will decrement weak count and may clean up counter.

Parameters
allocAllocator for cleanup

Definition at line 121 of file rc.hpp.

121 {
122 if (!rc) {
123 return;
124 }
125
126 ensure(rc, "Rc is invalid");
127 if (rc->releaseWeak()) {
128 alloc.destroy(rc);
129 }
130 }
Here is the call graph for this function:

◆ obtain()

template<typename T>
Result< Rc< T >, RcError > mtcore::WeakRc< T >::obtain ( Allocator & alloc)

Tries to obtain a strong reference May error if could not obtain (e.g.

already cleaned up)

Parameters
allocAllocator to use to obtain reference

Definition at line 296 of file rc.hpp.

296 {
297 ensure(rc, "arc is invalid");
298 if (!rc->acquireStrong()) {
300 }
301 return Rc<T>{rc};
302 }
Here is the call graph for this function:

◆ operator bool()

template<typename T>
mtcore::WeakRc< T >::operator bool ( ) const
inlinenodiscard

Checks if weak reference is valid.

Definition at line 140 of file rc.hpp.

140{ return valid(); }
bool valid() const
Checks if weak reference is valid.
Definition rc.hpp:135
Here is the call graph for this function:

◆ valid()

template<typename T>
bool mtcore::WeakRc< T >::valid ( ) const
inlinenodiscard

Checks if weak reference is valid.

Definition at line 135 of file rc.hpp.

135{ return rc != nullptr; }
Here is the caller graph for this function:

Member Data Documentation

◆ rc

template<typename T>
impl::ThreadLocalRefCount<T>* mtcore::WeakRc< T >::rc = nullptr

Definition at line 107 of file rc.hpp.


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