SensESP 3.4.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::ValueProducer< T > Class Template Reference

A base class for any sensor or piece of code that outputs a value for consumption elsewhere. More...

#include <sensesp/system/valueproducer.h>

Inherits sensesp::Observable.

Inherited by sensesp::ObservableValue< SKWSConnectionState >, sensesp::ObservableValue< int >, sensesp::ObservableValue< String >, sensesp::ObservableValue< int8_t >, sensesp::ObservableValue< uint16_t >, sensesp::ObservableValue< uint64_t >, sensesp::ObservableValue< float >, sensesp::Sensor< bool > [virtual], sensesp::Sensor< int > [virtual], sensesp::Transform< std::tuple< float, float, float >, float >, sensesp::Transform< bool, ClickTypes >, sensesp::Transform< std::tuple< float, float >, float >, sensesp::Transform< T, T >, sensesp::Transform< int, float >, sensesp::Transform< float, String >, sensesp::Transform< IN, OUT >, sensesp::Transform< float, float >, sensesp::Transform< FROM, TO >, sensesp::Transform< T, Nullable< T > >, sensesp::Transform< float, int >, sensesp::Transform< String, String >, sensesp::Transform< String, bool >, sensesp::Transform< C, bool >, sensesp::Transform< T, double >, sensesp::Transform< time_t, String >, sensesp::Transform< bool, String >, sensesp::Transform< int, int >, sensesp::ObservableValue< T >, sensesp::SKPutRequestListener< T >, sensesp::SKValueListener< T >, and sensesp::Sensor< T > [virtual].

Public Member Functions

 ValueProducer ()
 
 ValueProducer (const T &initial_value)
 
virtual const T & get () const
 
template<typename VConsumer >
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.
 
template<typename VConsumer >
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)
 
template<typename VConsumer >
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)
 
void emit (const T &new_value)
 
- Public Member Functions inherited from sensesp::Observable
 Observable ()
 
 Observable (Observable &&other)
 Move constructor.
 
void notify ()
 
int attach (std::function< void()> observer)
 Attach an observer callback.
 
void detach (int id)
 Remove a previously attached observer by its ID.
 

Protected Attributes

output_
 

Detailed Description

template<typename T>
class sensesp::ValueProducer< T >

A base class for any sensor or piece of code that outputs a value for consumption elsewhere.

They are Observable, allowing code to be notified whenever a new value is available. They can be connected directly to ValueConsumers of the same type using the connect_to() method.

See also
ValueConsumer

Definition at line 25 of file valueproducer.h.

Constructor & Destructor Documentation

◆ ValueProducer() [1/2]

template<typename T >
sensesp::ValueProducer< T >::ValueProducer ( )
inline

Definition at line 27 of file valueproducer.h.

◆ ValueProducer() [2/2]

template<typename T >
sensesp::ValueProducer< T >::ValueProducer ( const T &  initial_value)
inline

Definition at line 28 of file valueproducer.h.

Member Function Documentation

◆ connect_to() [1/3]

template<typename T >
template<typename VConsumer >
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 sensesp::ValueProducer< T >::connect_to ( std::shared_ptr< VConsumer >  consumer)
inline

Connect a producer to a transform with a different input type.

This allows you to connect a producer to a transform with a different input type. Automatic type conversion is performed.

Template Parameters
VConsumerValueConsumer type
CInputConsumer input type
Parameters
consumer_producerTransform object to connect to
Returns
std::shared_ptr<VConsumer> The connected consumer

Definition at line 52 of file valueproducer.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_to() [2/3]

template<typename T >
template<typename VConsumer >
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, VConsumer * >::type sensesp::ValueProducer< T >::connect_to ( VConsumer &  consumer)
inline

Definition at line 82 of file valueproducer.h.

Here is the call graph for this function:

◆ connect_to() [3/3]

template<typename T >
template<typename VConsumer >
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, VConsumer * >::type sensesp::ValueProducer< T >::connect_to ( VConsumer *  consumer)
inline

Definition at line 68 of file valueproducer.h.

Here is the call graph for this function:

◆ emit()

template<typename T >
void sensesp::ValueProducer< T >::emit ( const T &  new_value)
inline

Definition at line 89 of file valueproducer.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get()

template<typename T >
virtual const T & sensesp::ValueProducer< T >::get ( ) const
inlinevirtual

Returns the current value of this producer

Definition at line 33 of file valueproducer.h.

Here is the caller graph for this function:

Member Data Documentation

◆ output_

template<typename T >
T sensesp::ValueProducer< T >::output_
protected

The current value of this producer is stored here in this output member (unless descendant classes override ValueProducer::get())

Definition at line 99 of file valueproducer.h.


The documentation for this class was generated from the following files: