Helper to check if an object has changed. Thread-safe. More...
#include <ChangeMonitor.h>
Public Member Functions | |
std::optional< Data_t > | update (Data_t const ¤tObj) |
Returns the old object if different from newObj . More... | |
std::optional< Data_t > | operator() (Data_t const ¤tObj) |
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_t > | update (Data_t const ¤tObj) |
Returns the old object if different from newObj . More... | |
std::optional< Data_t > | operator() (Data_t const ¤tObj) |
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... | |
Helper to check if an object has changed. Thread-safe.
T | type of the object |
Comp | type of the comparison between T objects |
This class operates like ChangeMonitor
, but it is made thread-safe by the use of a mutex.
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.
|
private |
Definition at line 164 of file ChangeMonitor.h.
|
private |
Definition at line 165 of file ChangeMonitor.h.
|
inline |
Returns whether a reference value is present.
Definition at line 191 of file ChangeMonitor.h.
|
inline |
As update()
.
Definition at line 187 of file ChangeMonitor.h.
|
inline |
Returns the reference value; undefined if hasReference()
is false
.
Definition at line 197 of file ChangeMonitor.h.
|
inline |
Returns the old object if different from newObj
.
currentObj | the current object value |
currentObj
, or no value ChangeMonitor::update()
See ChangeMonitor::update()
for details.
Definition at line 183 of file ChangeMonitor.h.
|
mutableprivate |
Definition at line 167 of file ChangeMonitor.h.