ros2_control - rolling
Public Types | Public Member Functions | List of all members
realtime_tools::RealtimeBoxBestEffort< T, mutex_type > Class Template Reference

#include <realtime_box_best_effort.h>

Public Types

using mutex_t = mutex_type
 
using type = T
 

Public Member Functions

constexpr RealtimeBoxBestEffort (const T &init=T{})
 
constexpr RealtimeBoxBestEffort (const T &&init)
 
template<typename U = T>
constexpr RealtimeBoxBestEffort (const std::initializer_list< U > &init, std::enable_if_t< std::is_constructible_v< U, std::initializer_list >>)
 
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr< U >, bool > trySet (const T &value)
 set a new content with best effort More...
 
bool trySet (const std::function< void(T &)> &func)
 access the content readable with best effort More...
 
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr< U >, std::optional< U > > tryGet () const
 get the content with best effort More...
 
bool tryGet (const std::function< void(const T &)> &func)
 access the content (r) with best effort More...
 
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr< U >, void > set (const T &value)
 set the content and wait until the mutex could be locked (RealtimeBox behavior) More...
 
void set (const std::function< void(T &)> &func)
 access the content (rw) and wait until the mutex could locked
 
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr< U >, U > get () const
 get the content and wait until the mutex could be locked (RealtimeBox behaviour) More...
 
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr< U >, void > get (T &in) const
 get the content and wait until the mutex could be locked More...
 
void get (const std::function< void(const T &)> &func)
 access the content (r) and wait until the mutex could be locked More...
 
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr< U >, void > operator= (const T &value)
 provide a custom assignment operator for easier usage More...
 
template<typename U = T, typename = typename std::enable_if_t<!is_ptr_or_smart_ptr<U>>>
 operator T () const
 provide a custom conversion operator More...
 
template<typename U = T, typename = typename std::enable_if_t<!is_ptr_or_smart_ptr<U>>>
 operator std::optional< T > () const
 provide a custom conversion operator More...
 
const mutex_t & getMutex () const
 
mutex_t & getMutex ()
 

Detailed Description

template<class T, typename mutex_type = std::mutex>
class realtime_tools::RealtimeBoxBestEffort< T, mutex_type >

A Box that ensures thread safe access to the boxed contents. Access is best effort. If it can not lock it will return.

NOTE about pointers: You can use pointers with this box but the access will be different. Only use the get/set methods that take function pointer for accessing the internal value.

Member Function Documentation

◆ get() [1/3]

template<class T , typename mutex_type = std::mutex>
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr<U>, U> realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::get ( ) const
inline

get the content and wait until the mutex could be locked (RealtimeBox behaviour)

Returns
copy of the value

◆ get() [2/3]

template<class T , typename mutex_type = std::mutex>
void realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::get ( const std::function< void(const T &)> &  func)
inline

access the content (r) and wait until the mutex could be locked

Note
only safe way to access pointer type content (r)
same signature as in the existing RealtimeBox<T>

◆ get() [3/3]

template<class T , typename mutex_type = std::mutex>
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr<U>, void> realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::get ( T &  in) const
inline

get the content and wait until the mutex could be locked

Note
same signature as in the existing RealtimeBox<T>

◆ operator std::optional< T >()

template<class T , typename mutex_type = std::mutex>
template<typename U = T, typename = typename std::enable_if_t<!is_ptr_or_smart_ptr<U>>>
realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::operator std::optional< T > ( ) const
inline

provide a custom conversion operator

Note
Can be used from non-RT and RT contexts

◆ operator T()

template<class T , typename mutex_type = std::mutex>
template<typename U = T, typename = typename std::enable_if_t<!is_ptr_or_smart_ptr<U>>>
realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::operator T ( ) const
inline

provide a custom conversion operator

Note
Can only be used from non-RT!

◆ operator=()

template<class T , typename mutex_type = std::mutex>
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr<U>, void> realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::operator= ( const T &  value)
inline

provide a custom assignment operator for easier usage

Note
only to be used from non-RT!

◆ set()

template<class T , typename mutex_type = std::mutex>
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr<U>, void> realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::set ( const T &  value)
inline

set the content and wait until the mutex could be locked (RealtimeBox behavior)

Returns
true

◆ tryGet() [1/2]

template<class T , typename mutex_type = std::mutex>
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr<U>, std::optional<U> > realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::tryGet ( ) const
inline

get the content with best effort

Returns
std::nullopt if content could not be access, otherwise the content is returned

◆ tryGet() [2/2]

template<class T , typename mutex_type = std::mutex>
bool realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::tryGet ( const std::function< void(const T &)> &  func)
inline

access the content (r) with best effort

Returns
false if the mutex could not be locked
Note
only safe way to access pointer type content (r)

◆ trySet() [1/2]

template<class T , typename mutex_type = std::mutex>
bool realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::trySet ( const std::function< void(T &)> &  func)
inline

access the content readable with best effort

Returns
false if the mutex could not be locked
Note
only safe way to access pointer type content (rw)

◆ trySet() [2/2]

template<class T , typename mutex_type = std::mutex>
template<typename U = T>
std::enable_if_t<!is_ptr_or_smart_ptr<U>, bool> realtime_tools::RealtimeBoxBestEffort< T, mutex_type >::trySet ( const T &  value)
inline

set a new content with best effort

Returns
false if mutex could not be locked
Note
disabled for pointer types

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