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;
56 this->
attach([
this, consumer]() {
57 consumer->set(
static_cast<CInput
>(this->
get()));
62 template <
typename VConsumer>
63 typename std::enable_if<
64 std::is_base_of<ValueConsumer<typename VConsumer::input_type>, VConsumer>::value &&
65 std::is_convertible<T, typename VConsumer::input_type>::value,
69 using CInput =
typename VConsumer::input_type;
70 this->
attach([
this, consumer]() {
71 consumer->set(
static_cast<CInput
>(this->
get()));
76 template <
typename VConsumer>
77 typename std::enable_if<
78 std::is_base_of<ValueConsumer<typename VConsumer::input_type>, VConsumer>::value &&
79 std::is_convertible<T, typename VConsumer::input_type>::value,
89 void emit(
const T& new_value) {
int attach(std::function< void()> observer)
Attach an observer callback.
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