Template Class RealtimeBoxBestEffort

Class Documentation

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

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.

Public Types

using mutex_t = mutex_type
using type = T

Public Functions

inline explicit constexpr RealtimeBoxBestEffort(const T &init = T{})
inline explicit constexpr RealtimeBoxBestEffort(const T &&init)
template<typename U = T>
inline constexpr RealtimeBoxBestEffort(const std::initializer_list<U> &init, std::enable_if_t<std::is_constructible_v<U, std::initializer_list<U>>>)
template<typename U = T>
inline std::enable_if_t<!is_ptr_or_smart_ptr<U>, bool> trySet(const T &value)

set a new content with best effort

Note

disabled for pointer types

Returns:

false if mutex could not be locked

inline bool trySet(const std::function<void(T&)> &func)

access the content readable with best effort

Note

only safe way to access pointer type content (rw)

Returns:

false if the mutex could not be locked

template<typename U = T>
inline std::enable_if_t<!is_ptr_or_smart_ptr<U>, std::optional<U>> tryGet() const

get the content with best effort

Returns:

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

inline bool tryGet(const std::function<void(const T&)> &func)

access the content (r) with best effort

Note

only safe way to access pointer type content (r)

Returns:

false if the mutex could not be locked

template<typename U = T>
inline 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)

Returns:

true

inline void set(const std::function<void(T&)> &func)

access the content (rw) and wait until the mutex could locked

template<typename U = T>
inline 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)

Returns:

copy of the value

template<typename U = T>
inline 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

Note

same signature as in the existing RealtimeBox<T>

inline void get(const std::function<void(const T&)> &func)

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

Note

only safe way to access pointer type content (r)

Note

same signature as in the existing RealtimeBox<T>

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

provide a custom assignment operator for easier usage

Note

only to be used from non-RT!

template<typename U = T, typename = typename std::enable_if_t<!is_ptr_or_smart_ptr<U>>>
inline operator T() const

provide a custom conversion operator

Note

Can only be used from non-RT!

template<typename U = T, typename = typename std::enable_if_t<!is_ptr_or_smart_ptr<U>>>
inline operator std::optional<T>() const

provide a custom conversion operator

Note

Can be used from non-RT and RT contexts

inline const mutex_t &getMutex() const
inline mutex_t &getMutex()