CBMC
|
This class is similar to small_shared_ptrt and boost's intrusive_ptr. More...
#include <small_shared_n_way_ptr.h>
Public Types | |
typedef small_shared_n_way_pointee_baset< num_types, use_countt > | pointee_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_ptrt & | operator= (const small_shared_n_way_ptrt &rhs) |
small_shared_n_way_ptrt & | operator= (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_baset * | get () 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_baset * | p = nullptr |
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).
Ts | parameter 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.
typedef small_shared_n_way_pointee_baset<num_types, use_countt> small_shared_n_way_ptrt< Ts >::pointee_baset |
Definition at line 103 of file small_shared_n_way_ptr.h.
|
default |
|
inline |
Definition at line 127 of file small_shared_n_way_ptr.h.
|
inline |
Definition at line 137 of file small_shared_n_way_ptr.h.
|
inline |
Definition at line 161 of file small_shared_n_way_ptr.h.
|
inlineexplicitprivate |
Definition at line 237 of file small_shared_n_way_ptr.h.
|
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>.
I | index of a type in the parameter pack Ts |
p | pointer to an object of type Ts[I] |
Definition at line 116 of file small_shared_n_way_ptr.h.
|
inlineprivate |
Definition at line 241 of file small_shared_n_way_ptr.h.
|
inline |
Get base type pointer to the managed object.
Definition at line 203 of file small_shared_n_way_ptr.h.
|
inline |
Get pointer to the managed object.
Definition at line 212 of file small_shared_n_way_ptr.h.
|
inline |
Check if converting the held raw pointer to type Ts[I] is valid.
I | index into the parameter pack Ts |
Definition at line 193 of file small_shared_n_way_ptr.h.
|
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.
|
inlineexplicit |
Definition at line 230 of file small_shared_n_way_ptr.h.
|
inline |
Definition at line 144 of file small_shared_n_way_ptr.h.
|
inline |
Definition at line 153 of file small_shared_n_way_ptr.h.
|
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.
|
inline |
Definition at line 174 of file small_shared_n_way_ptr.h.
|
inline |
Get the use count of the pointed-to object.
Definition at line 184 of file small_shared_n_way_ptr.h.
|
static |
Definition at line 93 of file small_shared_n_way_ptr.h.
|
private |
Definition at line 257 of file small_shared_n_way_ptr.h.
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.