The Sparta Modeling Framework
|
Used for garbage collection, will delete the object it points to when all objects are finished using it. More...
#include <SpartaSharedPointer.hpp>
Public Types | |
using | element_type = PointerT |
Expected typedef for the resource type. | |
Public Member Functions | |
SpartaSharedPointer (PointerT *p=nullptr) noexcept | |
Construct a Reference Pointer with the given memory object. | |
constexpr | SpartaSharedPointer (std::nullptr_t) noexcept |
Constructor for SpartaSharedPointer<T> ptr = nullptr;. | |
template<class PointerT2 > | |
SpartaSharedPointer (const SpartaSharedPointer< PointerT2 > &orig) noexcept | |
Construct a reference pointer given another implicitly convertable reference pointer. | |
SpartaSharedPointer (const SpartaSharedPointer &orig) | |
Construct a reference pointer given another reference pointer. | |
SpartaSharedPointer (SpartaSharedPointer &&orig) | |
Take ownership of a reference pointer. | |
~SpartaSharedPointer () | |
Detach this shared pointer; if last, delete underlying object. | |
SpartaSharedPointer & | operator= (const SpartaSharedPointer &orig) |
Assignment operator. | |
SpartaSharedPointer & | operator= (SpartaSharedPointer &&orig) |
Assignment move operator. | |
bool | operator! () const |
The not ! operator. | |
operator bool () const | |
Boolean cast. | |
PointerT * | operator-> () const |
Dereference the RefPointer (const) | |
PointerT & | operator* () const |
Dereference the RefPointer (const) | |
PointerT * | get () const |
Get the underlying pointer. | |
void | reset (PointerT *p=nullptr) |
Reset this shared pointer. | |
uint32_t | use_count () const |
Get the current reference count. | |
Friends | |
class | SpartaSharedPointerAllocator< PointerT > |
class | SpartaWeakPointer< PointerT > |
template<typename PtrT , typename... Args> | |
SpartaSharedPointer< PtrT > | allocate_sparta_shared_pointer (SpartaSharedPointerAllocator< PtrT > &, Args &&...args) |
Used for garbage collection, will delete the object it points to when all objects are finished using it.
Simple, thread-unsafe class that will delete memory it points to when the last memory reference is deconstructed.
This class was created from the use case of typical model development: lots and lots of small, shared objects flowing through the simulation. Allocation/deallocation of std::shared_ptr
is a solution as well as Boost's shared_ptr
, but they serve a more general purpose and follow the principles of allocation traits and thread safety. This class does not. Because of the differentiated use case, this class is much faster (up to 6x faster) than using std::shared_ptr
.
In addition, the concept of a weak pointer is also supported via the SpartaWeakPointer found nested in this class.
Example usage:
This class can be used independently, or more efficiently with sparta::allocate_sparta_shared_pointer<T>. See sparta::SpartaSharedPointerAllocator for more information.
Definition at line 80 of file SpartaSharedPointer.hpp.
using sparta::SpartaSharedPointer< PointerT >::element_type = PointerT |
Expected typedef for the resource type.
Definition at line 113 of file SpartaSharedPointer.hpp.
|
inlineexplicitnoexcept |
Construct a Reference Pointer with the given memory object.
p | The memory that this reference pointer will take ownership of |
Construct a new Reference Pointer and take initial ownership of the given object pointer.
Definition at line 122 of file SpartaSharedPointer.hpp.
|
inlineconstexprnoexcept |
Constructor for SpartaSharedPointer<T> ptr = nullptr;.
nullptr_t |
Definition at line 130 of file SpartaSharedPointer.hpp.
|
inlinenoexcept |
Construct a reference pointer given another implicitly convertable reference pointer.
r | The other reference pointer |
The two reference pointers now share the common memory but the newly constructed reference pointer will interpret it as a different class
Definition at line 143 of file SpartaSharedPointer.hpp.
|
inline |
Construct a reference pointer given another reference pointer.
orig | The original pointer |
The two reference pointers now share the common memory
Definition at line 161 of file SpartaSharedPointer.hpp.
|
inline |
Take ownership of a reference pointer.
orig | The original pointer |
This SpartaSharedPointer now replaces orig. Orig becomes a nullptr with no references
Definition at line 176 of file SpartaSharedPointer.hpp.
|
inline |
Detach this shared pointer; if last, delete underlying object.
Definition at line 184 of file SpartaSharedPointer.hpp.
|
inline |
Get the underlying pointer.
Definition at line 271 of file SpartaSharedPointer.hpp.
|
inlineexplicit |
Boolean cast.
For operations like:
Definition at line 246 of file SpartaSharedPointer.hpp.
|
inline |
The not ! operator.
For operations like:
Definition at line 232 of file SpartaSharedPointer.hpp.
|
inline |
Dereference the RefPointer (const)
Definition at line 262 of file SpartaSharedPointer.hpp.
|
inline |
Dereference the RefPointer (const)
Definition at line 254 of file SpartaSharedPointer.hpp.
|
inline |
Assignment operator.
orig | The original pointer |
The two reference pointers now share the common memory
Definition at line 195 of file SpartaSharedPointer.hpp.
|
inline |
Assignment move operator.
orig | The original pointer to be moved |
The rvalue is assigned into this class, with this class unlinking itself from it's original pointer
Definition at line 214 of file SpartaSharedPointer.hpp.
|
inline |
Reset this shared pointer.
p | The new pointer |
Definition at line 279 of file SpartaSharedPointer.hpp.
|
inline |
Get the current reference count.
Definition at line 288 of file SpartaSharedPointer.hpp.
Definition at line 84 of file SpartaSharedPointer.hpp.
|
friend |
Definition at line 389 of file SpartaSharedPointer.hpp.
|
friend |
Definition at line 389 of file SpartaSharedPointer.hpp.