1#ifndef SENSESP_SYSTEM_VALUE_PRODUCER_H_
2#define SENSESP_SYSTEM_VALUE_PRODUCER_H_
4#include <ArduinoJson.h>
12template <
typename C,
typename P>
39 this->
attach([
this, consumer]() { consumer->
set(this->
get()); });
42 this->
attach([
this, consumer]() { consumer.
set(this->
get()); });
54 template <
typename CT>
56 this->
attach([
this, consumer]() { consumer->
set(CT(this->
get())); });
58 template <
typename CT>
60 this->
attach([
this, consumer]() { consumer.
set(CT(this->
get())); });
69 template <
typename T2>
71 this->
attach([
this, consumer_producer]() {
72 consumer_producer->
set(T(this->
get()));
74 return consumer_producer;
76 template <
typename T2>
79 [
this, consumer_producer]() { consumer_producer.
set(T(this->
get())); });
80 return &consumer_producer;
94 template <
typename TT,
typename T2>
96 this->
attach([
this, consumer_producer]() {
97 consumer_producer->
set(TT(this->
get()));
99 return consumer_producer;
101 template <
typename TT,
typename T2>
103 this->
attach([
this, consumer_producer]() {
104 consumer_producer->
set(TT(this->
get()));
106 return &consumer_producer;
112 void emit(
const T& new_value) {
A base class which allow observers to attach callbacks to themselves. The callbacks will be called wh...
void attach(std::function< void()> observer)
A base class for piece of code (like a transform) that accepts data for input. ValueConsumers can acc...
virtual void set(const T &new_value)
A base class for any sensor or piece of code that outputs a value for consumption elsewhere.
void connect_to(ValueConsumer< T > *consumer)
void connect_to(ValueConsumer< CT > &consumer)
Transform< T, T2 > * connect_to(Transform< T, T2 > &consumer_producer)
Transform< T, T2 > * connect_to(Transform< T, T2 > *consumer_producer)
virtual const T & get() const
void emit(const T &new_value)
void connect_to(ValueConsumer< T > &consumer)
Transform< TT, T2 > * connect_to(Transform< TT, T2 > &consumer_producer)
ValueProducer(const T &initial_value)
void connect_to(ValueConsumer< CT > *consumer)
Connect a producer to a consumer of a different type.
Transform< TT, T2 > * connect_to(Transform< TT, T2 > *consumer_producer)
Connect a producer to a transform with a different input type.
ValueProducer< bool > BoolProducer
ValueProducer< float > FloatProducer
ValueProducer< int > IntProducer
ValueProducer< String > StringProducer