Public Member Functions | Private Types | Private Attributes | List of all members
RTT::extras::ReadOnlyPointer< T > Class Template Reference

#include <ReadOnlyPointer.hpp>

Public Member Functions

T const * get () const
 
traits::const_reference operator* () const
 
T const * operator-> () const
 
 ReadOnlyPointer (T *ptr=0)
 
void reset (T *ptr)
 
T * try_write_access ()
 
bool valid () const
 
T * write_access ()
 

Private Types

typedef ROPtrInternal< T > Internal
 
typedef boost::call_traits< T > traits
 

Private Attributes

boost::intrusive_ptr< Internalinternal
 

Detailed Description

template<typename T>
class RTT::extras::ReadOnlyPointer< T >

Smart pointer that allows safe sharing of data between multiple threads

This smart pointer registers a memory area as being read-only. It can therefore be shared safely between threads without adding means of synchronization between the threads. Indeed: the value will not be changed between the threads.

If a thread wants to modify the value in-place (i.e. not do any copying), it can get ownership of the object referenced by the ReadOnlyPointer by calling ReadOnlyPointer::write_access. If this smart pointer if the only owner of the memory zone, then no copy will be done. Otherwise, one copy is done to satisfy the caller.

Definition at line 98 of file ReadOnlyPointer.hpp.

Member Typedef Documentation

template<typename T>
typedef ROPtrInternal<T> RTT::extras::ReadOnlyPointer< T >::Internal
private

Definition at line 100 of file ReadOnlyPointer.hpp.

template<typename T>
typedef boost::call_traits<T> RTT::extras::ReadOnlyPointer< T >::traits
private

Definition at line 102 of file ReadOnlyPointer.hpp.

Constructor & Destructor Documentation

template<typename T>
RTT::extras::ReadOnlyPointer< T >::ReadOnlyPointer ( T *  ptr = 0)
inline

Definition at line 105 of file ReadOnlyPointer.hpp.

Member Function Documentation

template<typename T>
T const* RTT::extras::ReadOnlyPointer< T >::get ( ) const
inline

Definition at line 115 of file ReadOnlyPointer.hpp.

template<typename T>
traits::const_reference RTT::extras::ReadOnlyPointer< T >::operator* ( ) const
inline

Definition at line 108 of file ReadOnlyPointer.hpp.

template<typename T>
T const* RTT::extras::ReadOnlyPointer< T >::operator-> ( ) const
inline

Definition at line 109 of file ReadOnlyPointer.hpp.

template<typename T>
void RTT::extras::ReadOnlyPointer< T >::reset ( T *  ptr)
inline

Modifies the value referenced by this smart pointer

After this call, ptr is owned by the smart pointer, and the caller should not modify the value referenced by ptr (i.e. it should be treated as read-only by the caller).

This does not change the other instances of ReadOnlyPointer that were referencing the same memory zone as this. I.e. after the following snippet, ptr2 refers to value2 and ptr1 to value1.

T* value1 = new T; T* value2 = new T; ReadOnlyPointer<T> ptr1(value1); ReadOnlyPointer<T> ptr2(ptr1); ptr2->reset(value2);

If this is the only owner of the object it refers to, this object will be deleted.

Definition at line 141 of file ReadOnlyPointer.hpp.

template<typename T>
T* RTT::extras::ReadOnlyPointer< T >::try_write_access ( )
inline

Gets write access to the pointed-to object if it does not require any copying

This method is like write_access, except that it will return NULL if a copy is needed

If non-NULL, it is the responsibility of the caller to delete the returned value.

Definition at line 180 of file ReadOnlyPointer.hpp.

template<typename T>
bool RTT::extras::ReadOnlyPointer< T >::valid ( ) const
inline

True if this refers to a non-NULL pointer

Definition at line 112 of file ReadOnlyPointer.hpp.

template<typename T>
T* RTT::extras::ReadOnlyPointer< T >::write_access ( )
inline

Gets write access to the pointed-to object.

If this is the only owner of that object, then no copy will be done and the pointer will be invalidated. Otherwise, the method returns a copy of the pointed-to object.

If the copy might be a problem, one can use try_write_access to get the object only when a copy is not needed.

It is the responsibility of the caller to delete the returned value.

Definition at line 212 of file ReadOnlyPointer.hpp.

Member Data Documentation

template<typename T>
boost::intrusive_ptr<Internal> RTT::extras::ReadOnlyPointer< T >::internal
private

Definition at line 101 of file ReadOnlyPointer.hpp.


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


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:43