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 124 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 163 of file rc.hpp.

163 {
164 ensure(rc, "Rc is invalid");
165 if (!rc->acquireWeak()) {
167 }
168 return *this;
169 }
#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:124
impl::ThreadLocalRefCount< T > * rc
Definition rc.hpp:125
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 139 of file rc.hpp.

139 {
140 if (!rc) {
141 return;
142 }
143
144 ensure(rc, "Rc is invalid");
145 if (rc->releaseWeak()) {
146 alloc.destroy(rc);
147 }
148 }
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 310 of file rc.hpp.

310 {
311 ensure(rc, "arc is invalid");
312 if (!rc->acquireStrong()) {
314 }
315 return Rc<T>{rc};
316 }
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 158 of file rc.hpp.

158{ return valid(); }
bool valid() const
Checks if weak reference is valid.
Definition rc.hpp:153
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 153 of file rc.hpp.

153{ 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 125 of file rc.hpp.


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