ROSE 0.11.145.147
|
Reference-counting intrusive smart pointer.
This class implements a reference-counting pointer to an object that inherits from SharedObject. See SharedObject for a detailed description of how to prepare objects to be referenced by SharedPointer.
Usage is similar to std::shared_ptr
to the extent that the number of pointers pointing to an object is recorded somewhere, and when that reference count reaches zero the object is destroyed and freed by calling delete
. The main difference is that SharedPointer stores the reference count in the object itself (i.e., "intrusive"). The effects are:
std::shared_ptr
and boost::shared_ptr
.Some best practices (see also, SharedObject):
Use SharedPointer if you need utmost speed, and are able to modify the definition of the pointee class to inherit from SharedObject, and are willing to always allocate all such objects on the heap not the stack, and don't need weak or unique pointers to such objects. Otherwise default to using std::shared_ptr
et. al. (or boost::shared_ptr
for C++03 and earlier).
Thread safety: Similar to raw pointers. Different threads can access different pointers to the same object, but operations on the pointer itself (such as assignment, comparison with null, and dereferencing in the presence of other writers needs to be synchronized by the callers.
Definition at line 65 of file SharedPointer.h.
#include <Sawyer/SharedPointer.h>
Public Types | |
typedef T | Pointee |
Public Member Functions | |
template<class Y > | |
SharedPointer (Y *rawPtr) | |
Constructs a shared pointer for an object. | |
~SharedPointer () | |
Conditionally deletes the pointed-to object. | |
T & | operator* () const |
Reference to the pointed-to object. | |
T * | operator-> () const |
Dereference pointed-to object. | |
template<class U > | |
SharedPointer< U > | dynamicCast () const |
Dynamic cast. | |
bool | operator! () const |
Boolean complement. | |
operator unspecified_bool () const | |
Type for Boolean context. | |
Pointee * | getRawPointer () |
Obtain the pointed-to object. | |
Pointee * | getRawPointer () const |
SharedPointer (const Sawyer::Nothing &) | |
Constructs an empty shared pointer. | |
SharedPointer (std::nullptr_t) | |
Constructs an empty shared pointer. | |
SharedPointer (const SharedPointer &other) | |
Constructs a new pointer that shares ownership of the pointed-to object with the other pointer. | |
template<class Y > | |
SharedPointer (const SharedPointer< Y > &other) | |
Constructs a new pointer that shares ownership of the pointed-to object with the other pointer. | |
SharedPointer & | operator= (const SharedPointer &other) |
Assignment. | |
template<class Y > | |
SharedPointer & | operator= (const SharedPointer< Y > &other) |
Assignment. | |
SharedPointer & | operator= (const Sawyer::Nothing &) |
Assignment. | |
SharedPointer & | operator= (std::nullptr_t) |
Assignment. | |
template<class U > | |
bool | operator== (const SharedPointer< U > &other) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator!= (const SharedPointer< U > &other) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator< (const SharedPointer< U > &other) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator<= (const SharedPointer< U > &other) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator> (const SharedPointer< U > &other) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator>= (const SharedPointer< U > &other) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator== (const U *ptr) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator!= (const U *ptr) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator< (const U *ptr) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator<= (const U *ptr) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator> (const U *ptr) const |
Comparison of two pointers. | |
template<class U > | |
bool | operator>= (const U *ptr) const |
Comparison of two pointers. | |
typedef T Sawyer::SharedPointer< T >::Pointee |
Definition at line 67 of file SharedPointer.h.
|
inline |
Constructs an empty shared pointer.
Definition at line 120 of file SharedPointer.h.
|
inlineexplicit |
Constructs an empty shared pointer.
Definition at line 122 of file SharedPointer.h.
|
inlineexplicit |
Constructs an empty shared pointer.
Definition at line 124 of file SharedPointer.h.
|
inline |
Constructs a new pointer that shares ownership of the pointed-to object with the other
pointer.
The pointed-to object will only be deleted after both pointers are deleted.
Definition at line 131 of file SharedPointer.h.
|
inline |
Constructs a new pointer that shares ownership of the pointed-to object with the other
pointer.
The pointed-to object will only be deleted after both pointers are deleted.
Definition at line 135 of file SharedPointer.h.
|
inlineexplicit |
Constructs a shared pointer for an object.
If obj
is non-null then its reference count is incremented. It is possible to create any number of shared pointers to the same object using this constructor. The expression "delete obj" must be well formed and must not invoke undefined behavior.
Definition at line 146 of file SharedPointer.h.
|
inline |
Conditionally deletes the pointed-to object.
The object is deleted when its reference count reaches zero.
Definition at line 152 of file SharedPointer.h.
|
inline |
Assignment.
This pointer is caused to point to the same object as other
, decrementing the reference count for the object originally pointed to by this pointer and incrementing the reference count for the object pointed by other
.
Definition at line 160 of file SharedPointer.h.
|
inline |
Assignment.
This pointer is caused to point to the same object as other
, decrementing the reference count for the object originally pointed to by this pointer and incrementing the reference count for the object pointed by other
.
Definition at line 164 of file SharedPointer.h.
References Sawyer::SharedPointer< T >::getRawPointer().
|
inline |
Assignment.
This pointer is caused to point to nothing.
Definition at line 178 of file SharedPointer.h.
|
inline |
Assignment.
This pointer is caused to point to nothing.
Definition at line 184 of file SharedPointer.h.
|
inline |
Reference to the pointed-to object.
An assertion will fail if assertions are enabled and this method is invoked on an empty pointer.
Definition at line 194 of file SharedPointer.h.
References Sawyer::SharedPointer< T >::ownershipCount.
|
inline |
Dereference pointed-to object.
The pointed-to object is returned. Returns null for empty pointers.
Definition at line 201 of file SharedPointer.h.
References Sawyer::SharedPointer< T >::ownershipCount.
|
inline |
Dynamic cast.
Casts the specified pointer to a new pointer type using dynamic_cast.
Definition at line 211 of file SharedPointer.h.
Referenced by Sawyer::CommandLine::ListParser::nextMember(), Rose::BinaryAnalysis::InstructionSemantics::NullSemantics::SValue::promote(), Rose::BinaryAnalysis::InstructionSemantics::TaintSemantics::SValue::promote(), and Sawyer::CommandLine::StringSetParser::with().
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 221 of file SharedPointer.h.
References Sawyer::SharedPointer< T >::getRawPointer().
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 225 of file SharedPointer.h.
References Sawyer::SharedPointer< T >::getRawPointer().
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 229 of file SharedPointer.h.
References Sawyer::SharedPointer< T >::getRawPointer().
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 233 of file SharedPointer.h.
References Sawyer::SharedPointer< T >::getRawPointer().
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 237 of file SharedPointer.h.
References Sawyer::SharedPointer< T >::getRawPointer().
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 241 of file SharedPointer.h.
References Sawyer::SharedPointer< T >::getRawPointer().
|
inline |
Comparison of two pointers.
Compares the underlying pointer with the specified pointer.
Definition at line 251 of file SharedPointer.h.
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 255 of file SharedPointer.h.
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 259 of file SharedPointer.h.
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 263 of file SharedPointer.h.
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 267 of file SharedPointer.h.
|
inline |
Comparison of two pointers.
Comparisons operators compare the underlying pointers to objects.
Definition at line 271 of file SharedPointer.h.
|
inline |
Boolean complement.
This operator allows shared pointers to be used in situations like this:
Definition at line 284 of file SharedPointer.h.
|
inline |
Type for Boolean context.
Implicit conversion to a type that can be used in a boolean context such as an if
or while
statement. For instance:
Definition at line 311 of file SharedPointer.h.
|
inline |
Obtain the pointed-to object.
The pointed-to object is returned. Returns null for empty pointers. An idiom for getting a raw pointer for a shared pointer that's known to be non-null is to dereference the shared pointer and then take the address:
Definition at line 334 of file SharedPointer.h.
Referenced by Sawyer::SharedPointer< T >::operator!=(), Sawyer::SharedPointer< T >::operator<(), Sawyer::SharedPointer< T >::operator<=(), Sawyer::SharedPointer< T >::operator=(), Sawyer::SharedPointer< T >::operator==(), Sawyer::SharedPointer< T >::operator>(), and Sawyer::SharedPointer< T >::operator>=().
|
inline |
Definition at line 337 of file SharedPointer.h.