EventAnalysis  1.3.0
Public Member Functions | Private Attributes | List of all members
EA::observer_ptr< T > Class Template Reference

A smart pointer not owning the wrapped object. More...

#include <ObserverPtr.h>

Inheritance diagram for EA::observer_ptr< T >:
EA::ObjPtr< T >

Public Member Functions

 observer_ptr ()
 Default constructor. More...
 
 observer_ptr (std::nullptr_t)
 Null constructor. More...
 
template<typename W >
 observer_ptr (const observer_ptr< W > p)
 Copy constructor. More...
 
template<typename W >
observer_ptroperator= (const observer_ptr< W > &p)
 Assignment operator. More...
 
template<typename W >
 observer_ptr (W *p)
 Constructor from raw pointer. More...
 
template<typename W >
observer_ptroperator= (W *p)
 Assignment operator from raw pointer. More...
 
template<typename W >
 observer_ptr (const std::unique_ptr< W > &p)
 Constructor from std::unique_ptr. More...
 
template<typename W >
observer_ptroperator= (const std::unique_ptr< W > &p)
 Assignment operator from std::unique_ptr. More...
 
template<typename W >
 observer_ptr (const std::shared_ptr< W > p)
 Constructor from std::shared_ptr. More...
 
template<typename W >
observer_ptroperator= (const std::shared_ptr< W > &p)
 Assignment operator from std::shared_ptr. More...
 
 operator bool () const
 Conversion to boolean. More...
 
 operator int () const =delete
 
template<typename W >
 operator W* ()
 Conversion to raw pointer. More...
 
T * get () const
 Getter for pointed address. More...
 
T * operator-> () const
 Arrow operator. More...
 
T & operator* () const
 Indirection operator. More...
 

Private Attributes

T * _ptr
 Comparison with observer_ptr. More...
 

Detailed Description

template<typename T>
class EA::observer_ptr< T >

A smart pointer not owning the wrapped object.

This class is a simple smart pointer inspired by the std::observer_ptr class which will be part of the C++17 standard. This implementation is meant to be used as long as the C++17 standard is not available or not required for this project.

Constructor & Destructor Documentation

◆ observer_ptr() [1/6]

template<typename T>
EA::observer_ptr< T >::observer_ptr ( )
inline

Default constructor.

Builds an observer_ptr pointing to nullptr.

◆ observer_ptr() [2/6]

template<typename T>
EA::observer_ptr< T >::observer_ptr ( std::nullptr_t  )
inline

Null constructor.

Builds an observer_ptr pointing to VULL.

Parameters
nullptrpointer.

◆ observer_ptr() [3/6]

template<typename T>
template<typename W >
EA::observer_ptr< T >::observer_ptr ( const observer_ptr< W >  p)
inline

Copy constructor.

Parameters
pThe observer_ptr to be copied.

◆ observer_ptr() [4/6]

template<typename T>
template<typename W >
EA::observer_ptr< T >::observer_ptr ( W *  p)
inline

Constructor from raw pointer.

Builds an observer_ptr pointing to address passed as argument. The template argument type W must either exactly match the type T or be a child class of T.

Parameters
pRaw pointer to be wrapped.

◆ observer_ptr() [5/6]

template<typename T>
template<typename W >
EA::observer_ptr< T >::observer_ptr ( const std::unique_ptr< W > &  p)
inline

Constructor from std::unique_ptr.

Builds an observer_ptr pointing to the same object pointed by #p. The template argument type W must either exactly match the type T or be a child class of T.

Parameters
pRaw pointer to be wrapped.

◆ observer_ptr() [6/6]

template<typename T>
template<typename W >
EA::observer_ptr< T >::observer_ptr ( const std::shared_ptr< W >  p)
inline

Constructor from std::shared_ptr.

Builds an observer_ptr pointing to the same object pointed by #p. The template argument type W must either exactly match the type T or be a child class of T.

Parameters
pstd::shared_ptr pointing to the desired object.

Member Function Documentation

◆ get()

template<typename T>
T* EA::observer_ptr< T >::get ( ) const
inline

Getter for pointed address.

Returns
The address the observer_ptr is pointing at.

◆ operator bool()

template<typename T>
EA::observer_ptr< T >::operator bool ( ) const
inline

Conversion to boolean.

◆ operator int()

template<typename T>
EA::observer_ptr< T >::operator int ( ) const
delete

◆ operator W*()

template<typename T>
template<typename W >
EA::observer_ptr< T >::operator W* ( )
inline

Conversion to raw pointer.

The template argument type W must either exactly match the type T or be a child class of T.

◆ operator*()

template<typename T>
T& EA::observer_ptr< T >::operator* ( ) const
inline

Indirection operator.

Returns
Reference to the pointed object.

◆ operator->()

template<typename T>
T* EA::observer_ptr< T >::operator-> ( ) const
inline

Arrow operator.

Returns
Raw pointer to the pointed object.

◆ operator=() [1/4]

template<typename T>
template<typename W >
observer_ptr& EA::observer_ptr< T >::operator= ( const observer_ptr< W > &  p)
inline

Assignment operator.

Parameters
pThe lhs observer_ptr.
Returns
*this.

◆ operator=() [2/4]

template<typename T>
template<typename W >
observer_ptr& EA::observer_ptr< T >::operator= ( W *  p)
inline

Assignment operator from raw pointer.

The wrapped pointer is set to the given argument. The template argument type W must either exactly match the type T or be a child class of T.

Parameters
pThe lhs raw pointer.
Returns
*this.

◆ operator=() [3/4]

template<typename T>
template<typename W >
observer_ptr& EA::observer_ptr< T >::operator= ( const std::unique_ptr< W > &  p)
inline

Assignment operator from std::unique_ptr.

Makes the observer_ptr point to the same object pointed by #p. The template argument type W must either exactly match the type T or be a child class of T.

Parameters
pThe lhs std::unique_ptr.
Returns
*this.

◆ operator=() [4/4]

template<typename T>
template<typename W >
observer_ptr& EA::observer_ptr< T >::operator= ( const std::shared_ptr< W > &  p)
inline

Assignment operator from std::shared_ptr.

Makes the observer_ptr point to the same object pointed by #p. The template argument type W must either exactly match the type T or be a child class of T.

Parameters
pThe lhs std::shared_ptr.
Returns
*this.

Member Data Documentation

◆ _ptr

template<typename T>
T* EA::observer_ptr< T >::_ptr
private

Comparison with observer_ptr.

The template argument type W must either exactly match the type T or be a child class of T.

Parameters
pThe lhs observer_ptr.
Returns
true if lhs and rhs point to the same address.

Comparison with raw pointer.

The template argument type W must either exactly match the type T or be a child class of T.

Parameters
pThe lhs observer_ptr.
Returns
true if lhs and rhs point to the same address.

Comparison with std::unique_ptr.

The template argument type W must either exactly match the type T or be a child class of T.

Parameters
pThe lhs std::unique_ptr.
Returns
true if lhs and rhs point to the same address.

Comparison with std::shared_ptr.

The template argument type W must either exactly match the type T or be a child class of T.

Parameters
pThe lhs std::shared_ptr.
Returns
true if lhs and rhs point to the same address.

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