All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Types | Private Attributes | List of all members
icarus::ns::util::ThreadSafeChangeMonitor< T, Comp > Class Template Reference

Helper to check if an object has changed. Thread-safe. More...

#include <ChangeMonitor.h>

Inheritance diagram for icarus::ns::util::ThreadSafeChangeMonitor< T, Comp >:
icarus::ns::util::ChangeMonitor< T, Comp >

Public Member Functions

std::optional< Data_tupdate (Data_t const &currentObj)
 Returns the old object if different from newObj. More...
 
std::optional< Data_toperator() (Data_t const &currentObj)
 As update(). More...
 
bool hasReference () const
 Returns whether a reference value is present. More...
 
Data_t const & reference () const
 
- Public Member Functions inherited from icarus::ns::util::ChangeMonitor< T, Comp >
 ChangeMonitor (Comparison_t comp=Comparison_t{})
 Default constructor: starts with no reference value. More...
 
 ChangeMonitor (Data_t const &ref, Comp comp=Comp{})
 Constructor: starts with ref as the reference value. More...
 
std::optional< Data_tupdate (Data_t const &currentObj)
 Returns the old object if different from newObj. More...
 
std::optional< Data_toperator() (Data_t const &currentObj)
 As update(). More...
 
bool hasReference () const
 Returns whether a reference value is present. More...
 
Data_t const & reference () const
 Returns the reference value; undefined if hasReference() is false. More...
 

Private Types

using Base_t = ChangeMonitor< T, Comp >
 
using Data_t = typename Base_t::Data_t
 

Private Attributes

std::mutex fLock
 

Additional Inherited Members

- Public Types inherited from icarus::ns::util::ChangeMonitor< T, Comp >
using Data_t = T
 Type of the object being monitored. More...
 
using Comparison_t = Comp
 Type of object for reference comparison. More...
 

Detailed Description

template<typename T, typename Comp = std::equal_to<T>>
class icarus::ns::util::ThreadSafeChangeMonitor< T, Comp >

Helper to check if an object has changed. Thread-safe.

Template Parameters
Ttype of the object
Comptype of the comparison between T objects

This class operates like ChangeMonitor, but it is made thread-safe by the use of a mutex.

Note
This class is actually only partially thread-safe: the member reference() is effectively not, since it returns a reference that can be then modified by another thread while accessed (read only) by another.

Definition at line 162 of file ChangeMonitor.h.

Member Typedef Documentation

template<typename T, typename Comp = std::equal_to<T>>
using icarus::ns::util::ThreadSafeChangeMonitor< T, Comp >::Base_t = ChangeMonitor<T, Comp>
private

Definition at line 164 of file ChangeMonitor.h.

template<typename T, typename Comp = std::equal_to<T>>
using icarus::ns::util::ThreadSafeChangeMonitor< T, Comp >::Data_t = typename Base_t::Data_t
private

Definition at line 165 of file ChangeMonitor.h.

Member Function Documentation

template<typename T, typename Comp = std::equal_to<T>>
bool icarus::ns::util::ThreadSafeChangeMonitor< T, Comp >::hasReference ( ) const
inline

Returns whether a reference value is present.

Definition at line 191 of file ChangeMonitor.h.

192  { std::lock_guard lg { fLock }; return Base_t::hasReference(); }
bool hasReference() const
Returns whether a reference value is present.
template<typename T, typename Comp = std::equal_to<T>>
std::optional<Data_t> icarus::ns::util::ThreadSafeChangeMonitor< T, Comp >::operator() ( Data_t const &  currentObj)
inline

As update().

Definition at line 187 of file ChangeMonitor.h.

188  { return update(currentObj); }
std::optional< Data_t > update(Data_t const &currentObj)
Returns the old object if different from newObj.
template<typename T, typename Comp = std::equal_to<T>>
Data_t const& icarus::ns::util::ThreadSafeChangeMonitor< T, Comp >::reference ( ) const
inline

Returns the reference value; undefined if hasReference() is false.

Note
While the method is thread-safe, it returns a reference to a mutable object.

Definition at line 197 of file ChangeMonitor.h.

198  { std::lock_guard lg { fLock }; return Base_t::reference(); }
Data_t const & reference() const
Returns the reference value; undefined if hasReference() is false.
template<typename T, typename Comp = std::equal_to<T>>
std::optional<Data_t> icarus::ns::util::ThreadSafeChangeMonitor< T, Comp >::update ( Data_t const &  currentObj)
inline

Returns the old object if different from newObj.

Parameters
currentObjthe current object value
Returns
the old reference if different from currentObj, or no value
See Also
ChangeMonitor::update()

See ChangeMonitor::update() for details.

Definition at line 183 of file ChangeMonitor.h.

184  { std::lock_guard lg { fLock }; return Base_t::update(currentObj); }
std::optional< Data_t > update(Data_t const &currentObj)
Returns the old object if different from newObj.

Member Data Documentation

template<typename T, typename Comp = std::equal_to<T>>
std::mutex icarus::ns::util::ThreadSafeChangeMonitor< T, Comp >::fLock
mutableprivate

Definition at line 167 of file ChangeMonitor.h.


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