MeixnerGC  1.0
gc_ptr.h File Reference
#include <mutex>
#include <vector>
#include <cstddef>
#include <atomic>
Include dependency graph for gc_ptr.h:

Go to the source code of this file.

Classes

class  gc_object
 
class  gc_base_ptr
 
class  gc_ptr< T >
 
class  make_gc< T >
 
class  make_gc< T[]>
 

Functions

void gc_collect ()
 
template<class T , class U >
bool operator== (const gc_ptr< T > &lhs, const gc_ptr< U > &rhs) noexcept
 
template<class T >
bool operator== (const gc_ptr< T > &lhs, nullptr_t n) noexcept
 
template<class T >
bool operator== (nullptr_t n, const gc_ptr< T > &rhs) noexcept
 
template<class T , class U >
bool operator!= (const gc_ptr< T > &lhs, const gc_ptr< U > &rhs) noexcept
 
template<class T >
bool operator!= (const gc_ptr< T > &lhs, nullptr_t n) noexcept
 
template<class T >
bool operator!= (nullptr_t n, const gc_ptr< T > &rhs) noexcept
 
template<class T , class U >
bool operator< (const gc_ptr< T > &lhs, const gc_ptr< U > &rhs) noexcept
 
template<class T >
bool operator< (const gc_ptr< T > &lhs, nullptr_t n) noexcept
 
template<class T >
bool operator< (nullptr_t n, const gc_ptr< T > &rhs) noexcept
 
template<class T >
bool operator<= (const gc_ptr< T > &lhs, const gc_ptr< T > &rhs) noexcept
 
template<class T >
bool operator<= (const gc_ptr< T > &lhs, nullptr_t n) noexcept
 
template<class T >
bool operator<= (nullptr_t n, const gc_ptr< T > &rhs) noexcept
 
template<class T >
bool operator> (const gc_ptr< T > &lhs, const gc_ptr< T > &rhs) noexcept
 
template<class T >
bool operator> (const gc_ptr< T > &lhs, nullptr_t n) noexcept
 
template<class T >
bool operator> (nullptr_t n, const gc_ptr< T > &rhs) noexcept
 
template<class T >
bool operator>= (const gc_ptr< T > &lhs, const gc_ptr< T > &rhs) noexcept
 
template<class T >
bool operator>= (const gc_ptr< T > &lhs, nullptr_t n) noexcept
 
template<class T >
bool operator>= (nullptr_t n, const gc_ptr< T > &rhs) noexcept
 
template<class T , class U >
gc_ptr< T > operator+ (const gc_ptr< T > &a, const U &b) noexcept
 
template<class T , class U >
gc_ptr< T > operator+ (const U &a, const gc_ptr< T > &b) noexcept
 
template<class T , class U >
gc_ptr< T > operator- (const gc_ptr< T > &a, const U &b) noexcept
 
template<class T >
auto operator- (const gc_ptr< T > &a, const gc_ptr< T > &b) noexcept-> decltype(a.get()-b.get())
 
template<class T , class U >
gc_ptr< T > static_pointer_cast (const gc_ptr< U > &p) noexcept
 
template<class T , class U >
gc_ptr< T > dynamic_pointer_cast (const gc_ptr< U > &p) noexcept
 
template<class T , class U >
gc_ptr< T > const_pointer_cast (const gc_ptr< U > &p) noexcept
 
template<class T , class U >
gc_ptr< T > reinterpret_pointer_cast (const gc_ptr< U > &p) noexcept
 
template<class T , class U >
gc_ptr< T > pointer_cast (const gc_ptr< U > &p) noexcept
 

Variables

std::mutex gc_mutex
 
thread_local gc_objectcurrent
 
std::vector< gc_object * > all_objects
 
long gc_counter
 

Function Documentation

template<class T , class U >
gc_ptr<T> const_pointer_cast ( const gc_ptr< U > &  p)
noexcept

gc_ptr version of const_cast<>()

Returns
gc_ptr as result of static_cast()
template<class T , class U >
gc_ptr<T> dynamic_pointer_cast ( const gc_ptr< U > &  p)
noexcept

gc_ptr version of dynamic_cast<>()

Returns
gc_ptr as result of static_cast()
void gc_collect ( )

manually trigger garbage collection. Normally this is not required as the collection starts automatically. It may be useful in low-memory situations to force a garbage collection.

template<class T , class U >
bool operator!= ( const gc_ptr< T > &  lhs,
const gc_ptr< U > &  rhs 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]rhssecond pointer
Returns
true lhs.get()!=rhs.get()
template<class T >
bool operator!= ( const gc_ptr< T > &  lhs,
nullptr_t  n 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]nnullptr
Returns
true lhs.get()!=0
template<class T >
bool operator!= ( nullptr_t  n,
const gc_ptr< T > &  rhs 
)
noexcept

compare pointers

Parameters
[in]nnullptr
[in]rhssecond pointer
Returns
true 0!=rhs.get()
template<class T , class U >
gc_ptr<T> operator+ ( const gc_ptr< T > &  a,
const U &  b 
)
noexcept

pointer arithmetic

Parameters
[in]apointer
[in]binteger type
Returns
resulting pointer a+u
template<class T , class U >
gc_ptr<T> operator+ ( const U &  a,
const gc_ptr< T > &  b 
)
noexcept

pointer arithmetic

Parameters
[in]ainteger type
[in]bpointer
Returns
resulting pointer a+u
template<class T , class U >
gc_ptr<T> operator- ( const gc_ptr< T > &  a,
const U &  b 
)
noexcept

pointer arithmetic

Parameters
[in]apointer
[in]binteger type
Returns
resulting pointer a-u
template<class T >
auto operator- ( const gc_ptr< T > &  a,
const gc_ptr< T > &  b 
) -> decltype(a.get()-b.get())
noexcept

pointer arithmetic

Parameters
[in]apointer
[in]bpointer
Returns
resulting integer value a-b
template<class T , class U >
bool operator< ( const gc_ptr< T > &  lhs,
const gc_ptr< U > &  rhs 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]rhssecond pointer
Returns
true lhs.get()<rhs.get()
template<class T >
bool operator< ( const gc_ptr< T > &  lhs,
nullptr_t  n 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]nnullptr
Returns
true lhs.get()<0
template<class T >
bool operator< ( nullptr_t  n,
const gc_ptr< T > &  rhs 
)
noexcept

compare pointers

Parameters
[in]nnullptr
[in]rhssecond pointer
Returns
true 0<rhs.get()
template<class T >
bool operator<= ( const gc_ptr< T > &  lhs,
const gc_ptr< T > &  rhs 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]rhssecond pointer
Returns
true lhs.get()<=rhs.get()
template<class T >
bool operator<= ( const gc_ptr< T > &  lhs,
nullptr_t  n 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]nnullptr
Returns
true lhs.get()<=0
template<class T >
bool operator<= ( nullptr_t  n,
const gc_ptr< T > &  rhs 
)
noexcept

compare pointers

Parameters
[in]nnullptr
[in]rhssecond pointer
Returns
true 0<=rhs.get()
template<class T , class U >
bool operator== ( const gc_ptr< T > &  lhs,
const gc_ptr< U > &  rhs 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]rhssecond pointer
Returns
true lhs.get()==rhs.get()
template<class T >
bool operator== ( const gc_ptr< T > &  lhs,
nullptr_t  n 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]nnullptr
Returns
true lhs.get()==0
template<class T >
bool operator== ( nullptr_t  n,
const gc_ptr< T > &  rhs 
)
noexcept

compare pointers

Parameters
[in]nnullptr
[in]rhssecond pointer
Returns
true 0==rhs.get()
template<class T >
bool operator> ( const gc_ptr< T > &  lhs,
const gc_ptr< T > &  rhs 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]rhssecond pointer
Returns
true lhs.get()>rhs.get()
template<class T >
bool operator> ( const gc_ptr< T > &  lhs,
nullptr_t  n 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]nnullptr
Returns
true lhs.get()>0
template<class T >
bool operator> ( nullptr_t  n,
const gc_ptr< T > &  rhs 
)
noexcept

compare pointers

Parameters
[in]nnullptr
[in]rhssecond pointer
Returns
true 0>rhs.get()
template<class T >
bool operator>= ( const gc_ptr< T > &  lhs,
const gc_ptr< T > &  rhs 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]rhssecond pointer
Returns
true lhs.get()>=rhs.get()
template<class T >
bool operator>= ( const gc_ptr< T > &  lhs,
nullptr_t  n 
)
noexcept

compare pointers

Parameters
[in]lhsfirst pointer
[in]nnullptr
Returns
true lhs.get()>=0
template<class T >
bool operator>= ( nullptr_t  n,
const gc_ptr< T > &  rhs 
)
noexcept

compare pointers

Parameters
[in]nnullptr
[in]rhssecond pointer
Returns
true 0>=rhs.get()
template<class T , class U >
gc_ptr<T> pointer_cast ( const gc_ptr< U > &  p)
noexcept

gc_ptr version of C-like cast

Returns
gc_ptr as result of C-like cast
template<class T , class U >
gc_ptr<T> reinterpret_pointer_cast ( const gc_ptr< U > &  p)
noexcept

gc_ptr version of reinterpret_cast<>()

Returns
gc_ptr as result of static_cast()
template<class T , class U >
gc_ptr<T> static_pointer_cast ( const gc_ptr< U > &  p)
noexcept

gc_ptr version of static_cast<>()

Returns
gc_ptr as result of static_cast()

Variable Documentation

std::vector<gc_object *> all_objects

array containing all allocated objects

thread_local gc_object* current

pointer to current object under construction in current thread

long gc_counter

when this counter reaches 0, the garbage collection is triggered

std::mutex gc_mutex

global mutex