CBMC
small_shared_n_way_ptrt< Ts > Class Template Referencefinal

This class is similar to small_shared_ptrt and boost's intrusive_ptr. More...

#include <small_shared_n_way_ptr.h>

+ Inheritance diagram for small_shared_n_way_ptrt< Ts >:
+ Collaboration diagram for small_shared_n_way_ptrt< Ts >:

Public Types

typedef small_shared_n_way_pointee_baset< num_types, use_counttpointee_baset
 

Public Member Functions

 small_shared_n_way_ptrt ()=default
 
 small_shared_n_way_ptrt (const small_shared_n_way_ptrt &rhs)
 
 small_shared_n_way_ptrt (small_shared_n_way_ptrt &&rhs)
 
small_shared_n_way_ptrtoperator= (const small_shared_n_way_ptrt &rhs)
 
small_shared_n_way_ptrtoperator= (small_shared_n_way_ptrt &&rhs)
 
 ~small_shared_n_way_ptrt ()
 
void reset ()
 Clears this shared pointer. More...
 
void swap (small_shared_n_way_ptrt &rhs)
 
use_countt use_count () const
 Get the use count of the pointed-to object. More...
 
template<std::size_t I>
bool is_derived () const
 Check if converting the held raw pointer to type Ts[I] is valid. More...
 
pointee_basetget () const
 Get base type pointer to the managed object. More...
 
template<std::size_t I>
get_typet< I, Ts... >::type * get_derived () const
 Get pointer to the managed object. More...
 
bool is_same_type (const small_shared_n_way_ptrt &other) const
 Checks if the raw pointers held by *this and other both can be converted to a pointer to the same type (of a type in the parameter pack Ts) More...
 
 operator bool () const
 

Static Public Member Functions

template<std::size_t I>
static small_shared_n_way_ptrt< Ts... > create_small_shared_n_way_ptr (typename get_typet< I, Ts... >::type *p)
 Static factory method to construct a small shared n-way pointer, pointing to the given object *p of type Ts[I], which must be a subclass of small_shared_n_way_pointee_baset<len(Ts), Num>. More...
 

Public Attributes

decltype(std::declval< typename get_typet< 0, Ts... >::type >() .get_use_count()) typedef use_countt
 

Static Public Attributes

static const std::size_t num_types
 

Private Member Functions

template<typename T >
 small_shared_n_way_ptrt (T *p)
 
void destruct ()
 

Private Attributes

pointee_basetp = nullptr
 

Detailed Description

template<typename... Ts>
class small_shared_n_way_ptrt< Ts >

This class is similar to small_shared_ptrt and boost's intrusive_ptr.

Like those, it stores the use count with the pointed-to object instead of in a separate control block. Additionally, it uses the MSBs of the use count to indicate the type of the managed object (which is of one of the types in the parameter pack Ts).

A possible use case is the implementation of data structures with sharing that consist of several different types of nodes (such as a tree with internal nodes and leaf nodes). Storing the type with the use count avoids having to keep a separate type member or using typeid or dynamic_cast. Moreover, since the shared pointer is aware of the concrete type of the object being stored, it can delete it without requiring a virtual destructor or custom delete function (like std::shared_ptr).

Template Parameters
Tsparameter pack of the different types the small shared n-way pointer can point to

Definition at line 90 of file small_shared_n_way_ptr.h.

Member Typedef Documentation

◆ pointee_baset

Definition at line 103 of file small_shared_n_way_ptr.h.

Constructor & Destructor Documentation

◆ small_shared_n_way_ptrt() [1/4]

template<typename... Ts>
small_shared_n_way_ptrt< Ts >::small_shared_n_way_ptrt ( )
default

◆ small_shared_n_way_ptrt() [2/4]

template<typename... Ts>
small_shared_n_way_ptrt< Ts >::small_shared_n_way_ptrt ( const small_shared_n_way_ptrt< Ts > &  rhs)
inline

Definition at line 127 of file small_shared_n_way_ptr.h.

◆ small_shared_n_way_ptrt() [3/4]

template<typename... Ts>
small_shared_n_way_ptrt< Ts >::small_shared_n_way_ptrt ( small_shared_n_way_ptrt< Ts > &&  rhs)
inline

Definition at line 137 of file small_shared_n_way_ptr.h.

◆ ~small_shared_n_way_ptrt()

template<typename... Ts>
small_shared_n_way_ptrt< Ts >::~small_shared_n_way_ptrt ( )
inline

Definition at line 161 of file small_shared_n_way_ptr.h.

◆ small_shared_n_way_ptrt() [4/4]

template<typename... Ts>
template<typename T >
small_shared_n_way_ptrt< Ts >::small_shared_n_way_ptrt ( T *  p)
inlineexplicitprivate

Definition at line 237 of file small_shared_n_way_ptr.h.

Member Function Documentation

◆ create_small_shared_n_way_ptr()

template<typename... Ts>
template<std::size_t I>
static small_shared_n_way_ptrt<Ts...> small_shared_n_way_ptrt< Ts >::create_small_shared_n_way_ptr ( typename get_typet< I, Ts... >::type *  p)
inlinestatic

Static factory method to construct a small shared n-way pointer, pointing to the given object *p of type Ts[I], which must be a subclass of small_shared_n_way_pointee_baset<len(Ts), Num>.

Template Parameters
Iindex of a type in the parameter pack Ts
Parameters
ppointer to an object of type Ts[I]
Returns
a small shared n-way pointer pointing to p

Definition at line 116 of file small_shared_n_way_ptr.h.

◆ destruct()

template<typename... Ts>
void small_shared_n_way_ptrt< Ts >::destruct ( )
inlineprivate

Definition at line 241 of file small_shared_n_way_ptr.h.

◆ get()

template<typename... Ts>
pointee_baset* small_shared_n_way_ptrt< Ts >::get ( ) const
inline

Get base type pointer to the managed object.

Returns
pointer to the managed object, as type pointer to small_shared_n_way_pointee_baset (the common base type of all types in Ts)

Definition at line 203 of file small_shared_n_way_ptr.h.

◆ get_derived()

template<typename... Ts>
template<std::size_t I>
get_typet<I, Ts...>::type* small_shared_n_way_ptrt< Ts >::get_derived ( ) const
inline

Get pointer to the managed object.

Returns
pointer to the managed object, cast to type pointer to Ts[I]

Definition at line 212 of file small_shared_n_way_ptr.h.

◆ is_derived()

template<typename... Ts>
template<std::size_t I>
bool small_shared_n_way_ptrt< Ts >::is_derived ( ) const
inline

Check if converting the held raw pointer to type Ts[I] is valid.

Template Parameters
Iindex into the parameter pack Ts

Definition at line 193 of file small_shared_n_way_ptr.h.

◆ is_same_type()

template<typename... Ts>
bool small_shared_n_way_ptrt< Ts >::is_same_type ( const small_shared_n_way_ptrt< Ts > &  other) const
inline

Checks if the raw pointers held by *this and other both can be converted to a pointer to the same type (of a type in the parameter pack Ts)

Definition at line 222 of file small_shared_n_way_ptr.h.

◆ operator bool()

template<typename... Ts>
small_shared_n_way_ptrt< Ts >::operator bool ( ) const
inlineexplicit

Definition at line 230 of file small_shared_n_way_ptr.h.

◆ operator=() [1/2]

template<typename... Ts>
small_shared_n_way_ptrt& small_shared_n_way_ptrt< Ts >::operator= ( const small_shared_n_way_ptrt< Ts > &  rhs)
inline

Definition at line 144 of file small_shared_n_way_ptr.h.

◆ operator=() [2/2]

template<typename... Ts>
small_shared_n_way_ptrt& small_shared_n_way_ptrt< Ts >::operator= ( small_shared_n_way_ptrt< Ts > &&  rhs)
inline

Definition at line 153 of file small_shared_n_way_ptr.h.

◆ reset()

template<typename... Ts>
void small_shared_n_way_ptrt< Ts >::reset ( void  )
inline

Clears this shared pointer.

Decreases the use count of the pointed-to object (if any) by one.

Definition at line 168 of file small_shared_n_way_ptr.h.

◆ swap()

template<typename... Ts>
void small_shared_n_way_ptrt< Ts >::swap ( small_shared_n_way_ptrt< Ts > &  rhs)
inline

Definition at line 174 of file small_shared_n_way_ptr.h.

◆ use_count()

template<typename... Ts>
use_countt small_shared_n_way_ptrt< Ts >::use_count ( ) const
inline

Get the use count of the pointed-to object.

Returns
the use count of the pointed-to object

Definition at line 184 of file small_shared_n_way_ptr.h.

Member Data Documentation

◆ num_types

template<typename... Ts>
const std::size_t small_shared_n_way_ptrt< Ts >::num_types
static
Initial value:
=
std::tuple_size<std::tuple<Ts...>>::value

Definition at line 93 of file small_shared_n_way_ptr.h.

◆ p

template<typename... Ts>
pointee_baset* small_shared_n_way_ptrt< Ts >::p = nullptr
private

Definition at line 257 of file small_shared_n_way_ptr.h.

◆ use_countt

template<typename... Ts>
decltype(std::declval<typename get_typet<0, Ts...>::type>() .get_use_count()) typedef small_shared_n_way_ptrt< Ts >::use_countt

Definition at line 101 of file small_shared_n_way_ptr.h.


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