RobWorkProject  21.8.23-
Public Types | Public Member Functions | Related Functions | List of all members
Ptr< T > Class Template Reference

Ptr stores a pointer and optionally takes ownership of the value. More...

#include <Ptr.hpp>

Public Types

typedef std::shared_ptr< T > cpp_shared_ptr
 The type of a standard shared pointer.
 
typedef cpp_shared_ptr shared_ptr
 The internal type of shared pointer used.
 
typedef T * pointer
 Pointer type.
 
typedef T & reference
 Reference type.
 
typedef T value_type
 Value type.
 

Public Member Functions

 Ptr ()
 Default constructor yielding a NULL-pointer.
 
 Ptr (T *ptr)
 Do not take ownership of ptr. More...
 
 Ptr (cpp_shared_ptr ptr)
 Take ownership of ptr. More...
 
 ~Ptr ()
 destructor
 
template<class S >
Ptr< S > cast ()
 Cast the smart pointer to a different type. More...
 
template<class S >
Ptr< S > cast () const
 Cast the smart pointer to a different type. More...
 
template<class S >
Ptr< S > scast ()
 Cast the smart pointer statically to a different type. More...
 
template<class S >
Ptr< S > scast () const
 Cast the smart pointer statically to a different type. More...
 
template<class S >
 Ptr (Ptr< S > const &p, typename std::enable_if< std::is_base_of< T, S >::value >::type *=0)
 Construct smart pointer from other smart pointer. More...
 
pointer get () const
 The pointer stored in the object.
 
reference operator* () const
 Dereferencing operator.
 
pointer operator-> () const
 Member access operator.
 
 operator const void * () const
 Support for implicit conversion to bool.
 
Ptr< T > & operator= (cpp_shared_ptr &ptr)
 
template<class A >
bool operator== (const Ptr< A > &p) const
 equallity operator, this only tests if the pointers to the referenced objects are the same and NOT if the smart pointers are the same. More...
 
bool operator== (void *p) const
 Tests if the smart pointer points to the same instance as p.
 
bool operator!= (void *p) const
 Tests if the smart pointer points to different from the instance of p.
 
bool isShared () const
 check if this Ptr has shared ownership or none ownership More...
 
bool isNull () const
 checks if the pointer is null More...
 
cpp_shared_ptr getCppSharedPtr () const
 Returns the shared pointer used internally.
 
 operator cpp_shared_ptr () const
 Implicitly convert to std::shared_ptr type. More...
 
shared_ptr getSharedPtr () const
 Returns the shared pointer used internally.
 
Ptr< const T > cptr () const
 Get const Pointer. More...
 

Related Functions

(Note that these are not member functions.)

template<class T >
Ptr< T > ownedPtr (T *ptr)
 A Ptr that takes ownership over a raw pointer ptr.
 
template<class T >
std::vector< std::shared_ptr< T > > toStd (const std::vector< Ptr< T > > &ptrs)
 Convert a vector of Ptr to a vector of std::shared_ptr. More...
 
template<class T >
std::vector< Ptr< T > > fromStd (const std::vector< std::shared_ptr< T > > &ptrs)
 Convert a vector of std::shared_ptr to a vector of Ptr. More...
 

Detailed Description

template<class T>
class rw::core::Ptr< T >

Ptr stores a pointer and optionally takes ownership of the value.

Constructor & Destructor Documentation

◆ Ptr() [1/3]

Ptr ( T *  ptr)
inline

Do not take ownership of ptr.

ptr can be null.

The constructor is implicit on purpose.

◆ Ptr() [2/3]

Ptr ( cpp_shared_ptr  ptr)
inline

Take ownership of ptr.

ptr can be null.

The constructor is implicit on purpose.

◆ Ptr() [3/3]

Ptr ( Ptr< S > const &  p,
typename std::enable_if< std::is_base_of< T, S >::value >::type *  = 0 
)
inline

Construct smart pointer from other smart pointer.

Parameters
pthe other (compatible) smart pointer.

Member Function Documentation

◆ cast() [1/2]

Ptr< S > cast ( )
inline

Cast the smart pointer to a different type.

Returns
smart pointer that can be null if cast was not possible.

◆ cast() [2/2]

Ptr< S > cast ( ) const
inline

Cast the smart pointer to a different type.

Returns
smart pointer that can be null if cast was not possible.

◆ cptr()

Ptr< const T > cptr ( ) const
inline

Get const Pointer.

Returns
a copy in the form of Ptr<const T>;

◆ isNull()

bool isNull ( ) const
inline

checks if the pointer is null

Returns
Returns true if the pointer is null

◆ isShared()

bool isShared ( ) const
inline

check if this Ptr has shared ownership or none ownership

Returns
true if Ptr has shared ownership, false if it has no ownership.

◆ operator cpp_shared_ptr()

operator cpp_shared_ptr ( ) const
inline

Implicitly convert to std::shared_ptr type.

Returns
std::shared_ptr

◆ operator==()

bool operator== ( const Ptr< A > &  p) const
inline

equallity operator, this only tests if the pointers to the referenced objects are the same and NOT if the smart pointers are the same.

Parameters
p[in] smart pointer to compare with
Returns
true if the referenced objects are the same

◆ scast() [1/2]

Ptr< S > scast ( )
inline

Cast the smart pointer statically to a different type.

This is more efficient if it is already known that the object is of a certain type. If this is not known, please use the more safe cast() instead.

Returns
smart pointer that can be null if cast was not possible.

◆ scast() [2/2]

Ptr< S > scast ( ) const
inline

Cast the smart pointer statically to a different type.

This is more efficient if it is already known that the object is of a certain type. If this is not known, please use the more safe cast() instead.

Returns
smart pointer that can be null if cast was not possible.

Friends And Related Function Documentation

◆ fromStd()

std::vector< Ptr< T > > fromStd ( const std::vector< std::shared_ptr< T > > &  ptrs)
related

Convert a vector of std::shared_ptr to a vector of Ptr.

Parameters
ptrs[in] vector of std::shared_ptr.
Returns
a vector of Ptr with same size.

◆ toStd()

std::vector< std::shared_ptr< T > > toStd ( const std::vector< Ptr< T > > &  ptrs)
related

Convert a vector of Ptr to a vector of std::shared_ptr.

Parameters
ptrs[in] vector of Ptr.
Returns
a vector of std::shared_ptr with same size.

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