SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
valueconsumer.h
Go to the documentation of this file.
1#ifndef SENSESP_SYSTEM_VALUECONSUMER_H_
2#define SENSESP_SYSTEM_VALUECONSUMER_H_
3
4#include "sensesp.h"
5
6#include <ArduinoJson.h>
7#include <stdint.h>
8
9namespace sensesp {
10
11template <typename T>
12class ValueProducer;
13
21template <typename T>
23 public:
24 using input_type = T;
32 virtual void set(const T& new_value) {}
33
34 [[deprecated("Use set() instead")]]
35 virtual void set_input(const T& new_value) {
36 set(new_value);
37 }
38
39 // Pointer safety cannot be guaranteed because we don't know whether
40 // "this" is a shared pointer.
41 [[deprecated("Use ValueProducer<T>::connect_to instead")]]
43 producer->attach([producer, this]() { this->set(producer->get()); });
44 }
45};
46
51
52} // namespace sensesp
53
54#endif
void attach(std::function< void()> observer)
Definition observable.h:29
A base class for piece of code (like a transform) that accepts data for input. ValueConsumers can acc...
void connect_from(ValueProducer< T > *producer)
virtual void set(const T &new_value)
virtual void set_input(const T &new_value)
A base class for any sensor or piece of code that outputs a value for consumption elsewhere.
virtual const T & get() const
ValueConsumer< bool > BoolConsumer
ValueConsumer< float > FloatConsumer
ValueConsumer< String > StringConsumer
ValueConsumer< int > IntConsumer