Thunderbots Project
Loading...
Searching...
No Matches
ObserverSubjectAdapter< ObserverType, SubjectType > Class Template Reference

#include <observer_subject_adapter.hpp>

Inheritance diagram for ObserverSubjectAdapter< ObserverType, SubjectType >:
Collaboration diagram for ObserverSubjectAdapter< ObserverType, SubjectType >:

Public Types

using ConversionFunctionType = SubjectType(const ObserverType &)
 

Public Member Functions

 ObserverSubjectAdapter (std::function< ConversionFunctionType > conversion_function_)
 
virtual void receiveValue (ObserverType val) final
 
- Public Member Functions inherited from Observer< ObserverType >
 Observer (size_t buffer_size=DEFAULT_BUFFER_SIZE, bool log_buffer_full=true)
 
virtual void receiveValue (ObserverType val)
 
virtual double getDataReceivedPerSecond () final
 
- Public Member Functions inherited from Subject< SubjectType >
void registerObserver (std::shared_ptr< Observer< SubjectType > > observer)
 

Additional Inherited Members

- Static Public Attributes inherited from Observer< ObserverType >
static constexpr size_t TIME_BUFFER_SIZE
 
- Protected Member Functions inherited from Observer< ObserverType >
virtual std::optional< ObserverType > popMostRecentlyReceivedValue (Duration max_wait_time) final
 
virtual std::optional< ObserverType > popLeastRecentlyReceivedValue (Duration max_wait_time) final
 
- Protected Member Functions inherited from Subject< SubjectType >
virtual void sendValueToObservers (SubjectType val) final
 
- Static Protected Attributes inherited from Observer< ObserverType >
static constexpr size_t DEFAULT_BUFFER_SIZE
 

Detailed Description

template<typename ObserverType, typename SubjectType>
class ObserverSubjectAdapter< ObserverType, SubjectType >

ObserverSubjectAdapter is a class made to "adapt" a type emitted by a Subject to a different type consumed by an Observer with a conversion function passed in the constructor.

Based on the Adapter design pattern described here: https://refactoring.guru/design-patterns/adapter

Template Parameters
ObserverTypeThe type that this class observes, i.e. converted-from type
SubjectTypeThe type that this class is a subject of, i.e. converted-to type

Constructor & Destructor Documentation

◆ ObserverSubjectAdapter()

template<typename ObserverType , typename SubjectType >
ObserverSubjectAdapter ( std::function< ConversionFunctionType >  conversion_function_)
inlineexplicit

Constructs an ObserverSubjectAdapter with the given conversion function that consumes a const-ref of the observed type and returns the subject type.

Parameters
conversion_function_A function that converts ObserverType to SubjectType.

Member Function Documentation

◆ receiveValue()

template<typename ObserverType , typename SubjectType >
void receiveValue ( ObserverType  val)
finalvirtual

Receives a value, calls the conversion function on it, and sends it to the Observers of this object.

Parameters
vala value

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