Loading...
Searching...
No Matches
fastjet::SharedPtr< T > Class Template Reference
Advanced usage

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>`

Inheritance diagram for fastjet::SharedPtr< T >:
[legend]

## 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

## Detailed Description

template<class T>
class fastjet::SharedPtr< T >

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

- the ability to force an update of the count with the set_count(...) member.

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

- conversion from weak and auto pointers
- support for deleters and allocators
- static, constant and dynamic casts
- constructor and assignment sharing ownership with a shared pointer r but storing a different pointer than r (needed for the previous item)

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.

## Constructor & Destructor Documentation

## SharedPtr() [1/3]

template<class T>

fastjet::SharedPtr< T >::SharedPtr | ( |  | ) |

inline

default ctor

Definition at line 347 of file SharedPtr.hh.

## SharedPtr() [2/3]

template<class T>
template<class Y>

fastjet::SharedPtr< T >::SharedPtr | ( | Y * | ptr | ) |

inline explicit

initialise with the main data

Parameters

  t | : the object we want a smart pointer to

Definition at line 351 of file SharedPtr.hh.

## SharedPtr() [3/3]

template<class T>

fastjet::SharedPtr< T >::SharedPtr | ( | SharedPtr< T > const & | share | ) |

inline

overload the copy ctor so that it updates count

Parameters

  share | : the object we want to copy

Definition at line 357 of file SharedPtr.hh.

## ~SharedPtr()

template<class T>

fastjet::SharedPtr< T >::~SharedPtr | ( |  | ) |

inline

default dtor

Definition at line 373 of file SharedPtr.hh.

## Member Function Documentation

## reset() [1/3]

template<class T>

void fastjet::SharedPtr< T >::reset | ( |  | ) |

inline

reset the pointer to default value (NULL)

Definition at line 381 of file SharedPtr.hh.

## reset() [2/3]

template<class T>
template<class Y>

void fastjet::SharedPtr< T >::reset | ( | Y * | ptr | ) |

inline

reset from a pointer

Definition at line 390 of file SharedPtr.hh.

## reset() [3/3]

template<class T>
template<class Y>

void fastjet::SharedPtr< T >::reset | ( | SharedPtr< Y > const & | share | ) |

inline

do a smart copy

Parameters

  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.

## operator=() [1/2]

template<class T>

SharedPtr & fastjet::SharedPtr< T >::operator= | ( | SharedPtr< T > const & | share | ) |

inline

overload the = operator so that it updates count

Parameters

  share | : the object we want to copy

Definition at line 426 of file SharedPtr.hh.

## operator=() [2/2]

template<class T>
template<class Y>

SharedPtr & fastjet::SharedPtr< T >::operator= | ( | SharedPtr< Y > const & | share | ) |

inline

overload the = operator so that it updates count

Parameters

  share | : the object we want to copy

Definition at line 433 of file SharedPtr.hh.

## operator()()

template<class T>

T * fastjet::SharedPtr< T >::operator() | ( |  | ) | const

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.

## operator*()

template<class T>

T & fastjet::SharedPtr< T >::operator* | ( |  | ) | const

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.

## operator->()

template<class T>

T * fastjet::SharedPtr< T >::operator-> | ( |  | ) | const

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.

## get()

template<class T>

T * fastjet::SharedPtr< T >::get | ( |  | ) | const

inline

get the stored pointer

Definition at line 473 of file SharedPtr.hh.

## unique()

template<class T>

bool fastjet::SharedPtr< T >::unique | ( |  | ) | const

inline

check if the instance is unique

Definition at line 479 of file SharedPtr.hh.

## use_count()

template<class T>

long fastjet::SharedPtr< T >::use_count | ( |  | ) | const

inline

return the number of counts

Definition at line 484 of file SharedPtr.hh.

## operator bool()

template<class T>

fastjet::SharedPtr< T >::operator bool | ( |  | ) | const

inline explicit

conversion to bool This will allow you to use the indirection nicely

Definition at line 494 of file SharedPtr.hh.

## swap()

template<class T>

void fastjet::SharedPtr< T >::swap | ( | SharedPtr< T > & | share | ) |

inline

exchange the content of the two pointers

Definition at line 499 of file SharedPtr.hh.

## set_count()

template<class T>

void fastjet::SharedPtr< T >::set_count | ( | const long & | count | ) |

inline

force the count to be set to a specified value

Parameters

  count | the value that we need to reset to

Definition at line 507 of file SharedPtr.hh.

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

- include/fastjet/SharedPtr.hh