FastJet 3.4.3
|
An implementation of shared pointers that is broadly similar to C++11 shared_ptr (https://en.cppreference.com/w/cpp/memory/shared_ptr). More...
#include <fastjet/SharedPtr.hh>
Classes | |
class | __SharedCountingPtr |
Public Member Functions | |
SharedPtr () | |
default ctor | |
template<class Y > | |
SharedPtr (Y *ptr) | |
initialise with the main data | |
SharedPtr (SharedPtr const &share) | |
overload the copy ctor so that it updates count | |
~SharedPtr () | |
default dtor | |
void | reset () |
reset the pointer to default value (NULL) | |
template<class Y > | |
void | reset (Y *ptr) |
reset from a pointer | |
template<class Y > | |
void | reset (SharedPtr< Y > const &share) |
do a smart copy | |
SharedPtr & | operator= (SharedPtr const &share) |
overload the = operator so that it updates count | |
template<class Y > | |
SharedPtr & | operator= (SharedPtr< Y > const &share) |
overload the = operator so that it updates count | |
T * | operator() () const |
return the pointer we're pointing to | |
T & | operator* () const |
indirection, get a reference to the stored pointer | |
T * | operator-> () const |
indirection, get the stored pointer | |
T * | get () const |
get the stored pointer | |
bool | unique () const |
check if the instance is unique | |
long | use_count () const |
return the number of counts | |
operator bool () const | |
conversion to bool This will allow you to use the indirection nicely | |
void | swap (SharedPtr &share) |
exchange the content of the two pointers | |
void | set_count (const long &count) |
force the count to be set to a specified value | |
An implementation of shared pointers that is broadly similar to C++11 shared_ptr (https://en.cppreference.com/w/cpp/memory/shared_ptr).
One key additional feature is
This effectively allows us to incorporate an offset in the count, which allows deletions to be triggered even when some pointers remain. We use this in particular for automatic deletion of a ClusterSequence when no pointers to its structure object remain other than those in the PseudoJets that are part of the ClusterSequence object itself.
Key features that are missing relative to C++11 are
In the last 2 cases, their implementation would require storing two pointers for every copies of the shared pointer, while our implementation only needs one. We did not implement them since we want to limit as much as possible memory and time consumption, and can easily avoid (at least for our needs so far) the casts.
The class has been tested against the boost (v1.42) implementation (for the parts that we have implemented).
Definition at line 341 of file SharedPtr.hh.
|
inline |
default ctor
Definition at line 347 of file SharedPtr.hh.
initialise with the main data
t | : the object we want a smart pointer to |
Definition at line 351 of file SharedPtr.hh.
|
inline |
overload the copy ctor so that it updates count
share | : the object we want to copy |
Definition at line 357 of file SharedPtr.hh.
|
inline |
default dtor
Definition at line 373 of file SharedPtr.hh.
|
inline |
reset the pointer to default value (NULL)
Definition at line 381 of file SharedPtr.hh.
reset from a pointer
Definition at line 390 of file SharedPtr.hh.
|
inline |
do a smart copy
share | : the object we want to copy Q? Do we need a non-template<Y> version as for the ctor and the assignment? |
Definition at line 402 of file SharedPtr.hh.
|
inline |
overload the = operator so that it updates count
share | : the object we want to copy |
Definition at line 426 of file SharedPtr.hh.
|
inline |
overload the = operator so that it updates count
share | : the object we want to copy |
Definition at line 433 of file SharedPtr.hh.
|
inline |
return the pointer we're pointing to
Since FastJet 3.2.0, this is depracated since it is no longer part of std::shared_ptr<T>. Use SharedPtr<T>::get() instead
Definition at line 446 of file SharedPtr.hh.
|
inline |
indirection, get a reference to the stored pointer
!!! WATCH OUT It fails to check the requirement that the stored pointer must not be NULL!! So you need explicitly to check the validity in your code
Definition at line 457 of file SharedPtr.hh.
|
inline |
indirection, get the stored pointer
!!! WATCH OUT It fails to check the requirement that the stored pointer must not be NULL!! So you need explicitly to check the validity in your code
Definition at line 467 of file SharedPtr.hh.
|
inline |
get the stored pointer
Definition at line 473 of file SharedPtr.hh.
|
inline |
check if the instance is unique
Definition at line 479 of file SharedPtr.hh.
|
inline |
return the number of counts
Definition at line 484 of file SharedPtr.hh.
|
inlineexplicit |
conversion to bool This will allow you to use the indirection nicely
Definition at line 494 of file SharedPtr.hh.
|
inline |
exchange the content of the two pointers
Definition at line 499 of file SharedPtr.hh.
|
inline |
force the count to be set to a specified value
count | the value that we need to reset to |
Definition at line 507 of file SharedPtr.hh.