Namespace podio::utils

namespace utils

Functions

template<typename T>
void swap(MaybeSharedPtr<T> &a, MaybeSharedPtr<T> &b)

Variables

static constexpr auto MarkOwned = detail::MarkOwnedTag{}
template<typename T>
class MaybeSharedPtr
#include <podio/utilities/MaybeSharedPtr.h>

“Semi-smart” pointer class for pointers that at some point during their lifetime might hand over management to another entity.

E.g. Objects that are added to a collection will hand over the management of their Obj* to collection. In such a case two things need to be considered:

  • Other Objects with the same Obj* instance should not delete the managed Obj*, even if the last Object goes out of scope

  • Even if the managed Obj* is gone (e.g. collection has gone out of scope or was cleared), the remaining Object instances should still be able to gracefully destruct, even if they are at this point merely an “empty husk” The MaybeSharedPtr achieves this by having an optional control block that controls the lifetime of itself and potentially the managed Obj*.

Public Functions

MaybeSharedPtr() = delete

There are no empty MaybeSharedPtrs.

inline explicit MaybeSharedPtr(T *p)

Constructor from raw pointer.

Assumes someone else manages the pointer already

inline explicit MaybeSharedPtr(T *p, detail::MarkOwnedTag)

Constructor from a raw pointer assuming ownership in the process.

inline MaybeSharedPtr(const MaybeSharedPtr &other)

Copy constructor.

inline MaybeSharedPtr &operator=(MaybeSharedPtr other)

Assignment operator.

inline MaybeSharedPtr(MaybeSharedPtr &&other)

Move constructor.

inline ~MaybeSharedPtr()

Destructor.

inline T *get() const

Get a raw pointer to the managed pointer.

Do not change anything concerning the management of the pointer

inline T *release()

Get a raw pointer to the managed pointer and assume ownership.

inline operator bool() const
inline T *operator->()
inline const T *operator->() const
inline T &operator*()
inline const T &operator*() const

Friends

template<typename U>
friend void swap(MaybeSharedPtr<U> &a, MaybeSharedPtr<U> &b)