1#ifndef SENSESP_SYSTEM_VALUE_PRODUCER_H_
2#define SENSESP_SYSTEM_VALUE_PRODUCER_H_
4#include <ArduinoJson.h>
13template <
typename C,
typename P>
46 template <
typename VConsumer>
47 typename std::enable_if<
48 std::is_base_of<ValueConsumer<typename VConsumer::input_type>, VConsumer>::value &&
49 std::is_convertible<T, typename VConsumer::input_type>::value,
50 std::shared_ptr<VConsumer>
53 using CInput =
typename VConsumer::input_type;
55 std::weak_ptr<VConsumer> weak_consumer = consumer;
56 this->
attach([
this, weak_consumer]() {
57 if (
auto consumer = weak_consumer.lock()) {
58 consumer->set(
static_cast<CInput
>(this->
get()));
64 template <
typename VConsumer>
65 typename std::enable_if<
66 std::is_base_of<ValueConsumer<typename VConsumer::input_type>, VConsumer>::value &&
67 std::is_convertible<T, typename VConsumer::input_type>::value,
71 using CInput =
typename VConsumer::input_type;
72 this->
attach([
this, consumer]() {
73 consumer->set(
static_cast<CInput
>(this->
get()));
78 template <
typename VConsumer>
79 typename std::enable_if<
80 std::is_base_of<ValueConsumer<typename VConsumer::input_type>, VConsumer>::value &&
81 std::is_convertible<T, typename VConsumer::input_type>::value,
91 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 any sensor or piece of code that outputs a value for consumption elsewhere.
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, VConsumer * >::type connect_to(VConsumer &consumer)
virtual const T & get() const
void emit(const T &new_value)
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, VConsumer * >::type connect_to(VConsumer *consumer)
ValueProducer(const T &initial_value)
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, std::shared_ptr< VConsumer > >::type connect_to(std::shared_ptr< VConsumer > consumer)
Connect a producer to a transform with a different input type.
ValueProducer< bool > BoolProducer
ValueProducer< float > FloatProducer
ValueProducer< int > IntProducer
ValueProducer< String > StringProducer