L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
cxx::Ref_ptr< T, CNT > Class Template Reference

A reference-counting pointer with automatic cleanup. More...

#include <ref_ptr>

+ Inheritance diagram for cxx::Ref_ptr< T, CNT >:
+ Collaboration diagram for cxx::Ref_ptr< T, CNT >:

Public Member Functions

 Ref_ptr () noexcept
 Default constructor creates a pointer with no managed object.
 
 Ref_ptr (Wp const &o) noexcept
 Create a shared pointer from a weak pointer.
 
 Ref_ptr (decltype(nullptr) n) noexcept
 allow creation from nullptr
 
template<typename X >
 Ref_ptr (X *o) noexcept
 Create a shared pointer from a raw pointer.
 
 Ref_ptr (T *o, bool d) noexcept
 Create a shared pointer from a raw pointer without creating a new reference.
 
T * get () const noexcept)
 Return a raw pointer to the object this shared pointer points to.
 
T * ptr () const noexcept)
 Return a raw pointer to the object this shared pointer points to.
 
T * release () noexcept
 Release the shared pointer without removing the reference.
 

Detailed Description

template<typename T = void, template< typename X > class CNT = Default_ref_counter>
class cxx::Ref_ptr< T, CNT >

A reference-counting pointer with automatic cleanup.

Template Parameters
TType of object the pointer points to.
CNTType of management class that manages the life time of the object.

This pointer is similar to the standard C++-11 shared_ptr but it does the reference counting directly in the object being pointed to, so that no additional management structures need to be allocated from the heap.

Classes that use this pointer type must implement two functions:

int remove_ref()

is called when a reference is removed and must return 0 when there are no further references to the object.

void add_ref()

is called when another ref_ptr to the object is created.

Ref_obj provides a simple implementation of this interface from which classes may inherit.

Examples
tmpfs/lib/src/fs.cc.

Definition at line 81 of file ref_ptr.

Constructor & Destructor Documentation

◆ Ref_ptr() [1/3]

template<typename T = void, template< typename X > class CNT = Default_ref_counter>
cxx::Ref_ptr< T, CNT >::Ref_ptr ( Wp const &  o)
inlinenoexcept

Create a shared pointer from a weak pointer.

Increases references.

Definition at line 99 of file ref_ptr.

◆ Ref_ptr() [2/3]

template<typename T = void, template< typename X > class CNT = Default_ref_counter>
template<typename X >
cxx::Ref_ptr< T, CNT >::Ref_ptr ( X *  o)
inlineexplicitnoexcept

Create a shared pointer from a raw pointer.

In contrast to C++11 shared_ptr it is safe to use this constructor multiple times and have the same reference counter.

Definition at line 112 of file ref_ptr.

◆ Ref_ptr() [3/3]

template<typename T = void, template< typename X > class CNT = Default_ref_counter>
cxx::Ref_ptr< T, CNT >::Ref_ptr ( T *  o,
bool  d 
)
inlinenoexcept

Create a shared pointer from a raw pointer without creating a new reference.

Parameters
oPointer to the object.
dDummy parameter to select this constructor at compile time. The value may be true or false.

This is the counterpart to release().

Definition at line 125 of file ref_ptr.

Member Function Documentation

◆ get()

template<typename T = void, template< typename X > class CNT = Default_ref_counter>
T * cxx::Ref_ptr< T, CNT >::get ( ) const
inlinenoexcept

Return a raw pointer to the object this shared pointer points to.

This does not release the pointer or decrease the reference count.

Definition at line 132 of file ref_ptr.

◆ ptr()

template<typename T = void, template< typename X > class CNT = Default_ref_counter>
T * cxx::Ref_ptr< T, CNT >::ptr ( ) const
inlinenoexcept

Return a raw pointer to the object this shared pointer points to.

This does not release the pointer or decrease the reference count.

Definition at line 138 of file ref_ptr.

◆ release()

template<typename T = void, template< typename X > class CNT = Default_ref_counter>
T * cxx::Ref_ptr< T, CNT >::release ( )
inlinenoexcept

Release the shared pointer without removing the reference.

Returns
A raw pointer to the managed object.

Definition at line 149 of file ref_ptr.


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