8 #ifndef ICARUSALG_UTILITIES_CHANGEMONITOR_H
9 #define ICARUSALG_UTILITIES_CHANGEMONITOR_H
19 namespace icarus::ns::util {
84 template <
typename T,
typename Comp = std::equal_to<T>>
114 auto lastObj = std::move(
fRefObj);
121 {
return update(currentObj); }
143 template <
typename T>
161 template <
typename T,
typename Comp = std::equal_to<T>>
188 {
return update(currentObj); }
204 template <
typename T>
212 #endif // ICARUSALG_UTILITIES_CHANGEMONITOR_H
Comparison_t fComp
Comparison used for reference testing.
ChangeMonitor(Comparison_t comp=Comparison_t{})
Default constructor: starts with no reference value.
bool same(Data_t const &A, Data_t const &B) const
Returns whether A and B represent the same value.
bool hasReference() const
Returns whether a reference value is present.
ChangeMonitor(Data_t const &ref, Comp comp=Comp{})
Constructor: starts with ref as the reference value.
Helper to check if an object has changed. Thread-safe.
std::optional< Data_t > operator()(Data_t const ¤tObj)
As update().
ChangeMonitor(T const &) -> ChangeMonitor< T >
bool hasReference() const
Returns whether a reference value is present.
std::optional< Data_t > operator()(Data_t const ¤tObj)
As update().
std::equal_to< icarus::trigger::icarus::trigger::BeamGateStruct > Comparison_t
Type of object for reference comparison.
std::optional< Data_t > update(Data_t const ¤tObj)
Returns the old object if different from newObj.
std::optional< Data_t > fRefObj
The last object seen.
Data_t const & reference() const
std::optional< Data_t > update(Data_t const ¤tObj)
Returns the old object if different from newObj.
icarus::trigger::icarus::trigger::BeamGateStruct Data_t
Type of the object being monitored.
Helper to check if an object has changed.
ThreadSafeChangeMonitor(T const &) -> ThreadSafeChangeMonitor< T >
Data_t const & reference() const
Returns the reference value; undefined if hasReference() is false.