SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
observablevalue.h
Go to the documentation of this file.
1#ifndef _observablevalue_H
2#define _observablevalue_H
3
4#include "observable.h"
5#include "valueproducer.h"
6
7namespace sensesp {
8
9// forward declaration for the operator overloading functions
10template <class T>
11class ObservableValue;
12
13template <class T>
14bool operator==(ObservableValue<T> const& lhs, T const& rhs) {
15 return lhs.output == rhs;
16}
17
18template <class T>
19bool operator!=(ObservableValue<T> const& lhs, T const& rhs) {
20 return lhs.output != rhs;
21}
22
26template <class T>
27class ObservableValue : public ValueProducer<T> {
28 public:
30
31 ObservableValue(const T& value) { ValueProducer<T>::output = value; }
32
33 void set(const T& value) { this->ValueProducer<T>::emit(value); }
34
35 const T& operator=(const T& value) {
36 set(value);
37 return value;
38 }
39
40 template <class U>
41 friend bool operator==(ObservableValue<U> const& lhs, U const& rhs);
42 template <class U>
43 friend bool operator!=(ObservableValue<U> const& lhs, U const& rhs);
44};
45
46} // namespace sensesp
47
48#endif
Construct a new transform based on a single function.
A value that notifies its observers if it gets changed.
friend bool operator==(ObservableValue< U > const &lhs, U const &rhs)
friend bool operator!=(ObservableValue< U > const &lhs, U const &rhs)
ObservableValue(const T &value)
const T & operator=(const T &value)
void set(const T &value)
A base class for any sensor or piece of code that outputs a value for consumption elsewhere.
void emit(T new_value)
bool operator!=(ObservableValue< T > const &lhs, T const &rhs)
bool operator==(ObservableValue< T > const &lhs, T const &rhs)