PLaSK library
Loading...
Searching...
No Matches
plask::Receiver< ProviderT > Class Template Reference

Base class for all Receivers. More...

#include <plask/provider/provider.hpp>

Inheritance diagram for plask::Receiver< ProviderT >:
[legend]
Collaboration diagram for plask::Receiver< ProviderT >:
[legend]

Public Types

typedef Receiver< ProviderTBase
 
typedef ProviderT ProviderType
 Type of the corresponding provider.
 
- Public Types inherited from plask::ReceiverBase
enum class  ChangeReason { REASON_DELETE , REASON_VALUE , REASON_PROVIDER }
 The reason of change of provider value. More...
 

Public Member Functions

virtual const charproviderName () const
 
Receiveroperator= (const Receiver &)=delete
 
 Receiver (const Receiver &)=delete
 
 Receiver ()
 Construct Receiver without connected provider and with set changed flag.
 
virtual ~Receiver ()
 Destructor. Disconnect from provider.
 
void fireChanged (ChangeReason reason)
 Set change flag and call providerValueChanged with given reason.
 
void setProvider (ProviderT *provider, bool newProviderIsPrivate=false)
 Change provider.
 
void setProvider (ProviderT &provider)
 Change provider.
 
void setProvider (std::unique_ptr< ProviderT > &&provider)
 Change provider.
 
ProviderTgetProvider ()
 Current provider getter.
 
const ProviderTgetProvider () const
 Current provider getter.
 
bool hasProvider () const
 
void ensureHasProvider () const
 
template<typename ... Args>
auto operator() (const Args &... params) const -> decltype((*provider)(params...))
 Get value from provider using its operator().
 
template<typename ... Args>
auto optional (const Args &... params) const -> plask::optional< decltype((*provider)(params...))>
 Get value from provider using its operator().
 
template<typename ... ConstProviderConstructorArgs>
void setConstValue (ConstProviderConstructorArgs &&... constProviderConstructorArgs)
 Set provider for this to provider of constant.
 
template<typename ClassT , typename methodT >
boost::signals2::connection changedConnectMethod (ClassT *obj, methodT method, boost::signals2::connect_position at=boost::signals2::at_back)
 Connect a method to changed signal.
 
template<typename ClassT , typename methodT >
void changedDisconnectMethod (ClassT *obj, methodT method)
 Disconnect a method from changed signal.
 
- Public Member Functions inherited from plask::ReceiverBase
virtual ~ReceiverBase ()
 

Public Attributes

boost::signals2::signal< void(ReceiverBase &src, ChangeReason reason)> providerValueChanged
 Signal called when provider value or provider was changed (called by onChange)
 
ProviderTprovider
 Pointer to connected provider. Can be nullptr if no provider is connected.
 

Static Public Attributes

static constexpr const charPROVIDER_NAME = ProviderT::NAME
 Name of provider.
 

Protected Member Functions

void beforeGetValue () const
 Check if value can be read and throw exception if not.
 

Protected Attributes

bool _hasPrivateProvider
 Is true only if provider is private and will be deleted by this receiver.
 

Detailed Description

template<typename ProviderT>
class plask::Receiver< ProviderT >

Base class for all Receivers.

Implement listener (observer) pattern (is listener for providers). Delegate all operator() calling to provider.

For most providers types, Receiver type can be defined as: Receiver<ProviderClass>; (where ProviderClass is type of provider class)

Template Parameters
ProviderTtype of provider, can has defined ProviderT::ConstProviderType to receiver setConst method work.
See also
Providers and receivers

Definition at line 250 of file provider.hpp.

Member Typedef Documentation

◆ Base

Definition at line 261 of file provider.hpp.

◆ ProviderType

Type of the corresponding provider.

Definition at line 274 of file provider.hpp.

Constructor & Destructor Documentation

◆ Receiver() [1/2]

template<typename ProviderT >
plask::Receiver< ProviderT >::Receiver ( const Receiver< ProviderT > &  )
delete

◆ Receiver() [2/2]

template<typename ProviderT >
plask::Receiver< ProviderT >::Receiver ( )
inline

Construct Receiver without connected provider and with set changed flag.

Definition at line 280 of file provider.hpp.

◆ ~Receiver()

template<typename ProviderT >
virtual plask::Receiver< ProviderT >::~Receiver ( )
inlinevirtual

Destructor. Disconnect from provider.

Definition at line 283 of file provider.hpp.

Member Function Documentation

◆ beforeGetValue()

template<typename ProviderT >
void plask::Receiver< ProviderT >::beforeGetValue ( ) const
inlineprotected

Check if value can be read and throw exception if not.

Set changed flag to false.

Subclass can call this just before reading value.

Exceptions
NoProviderwhen provider is not available

Definition at line 445 of file provider.hpp.

◆ changedConnectMethod()

template<typename ProviderT >
boost::signals2::connection plask::Receiver< ProviderT >::changedConnectMethod ( ClassT obj,
methodT  method,
boost::signals2::connect_position  at = boost::signals2::at_back 
)
inline

Connect a method to changed signal.

Parameters
obj,methodslot to connect, object and it's method
atspecifies where the slot should be connected:
  • boost::signals2::at_front indicates that the slot will be connected at the front of the list or group of slots
  • boost::signals2::at_back (default) indicates that the slot will be connected at the back of the list or group of slots

Definition at line 425 of file provider.hpp.

◆ changedDisconnectMethod()

template<typename ProviderT >
void plask::Receiver< ProviderT >::changedDisconnectMethod ( ClassT obj,
methodT  method 
)
inline

Disconnect a method from changed signal.

Definition at line 431 of file provider.hpp.

◆ ensureHasProvider()

template<typename ProviderT >
void plask::Receiver< ProviderT >::ensureHasProvider ( ) const
inline
Exceptions
NoProviderwhen provider is not available

Definition at line 375 of file provider.hpp.

◆ fireChanged()

template<typename ProviderT >
void plask::Receiver< ProviderT >::fireChanged ( ChangeReason  reason)
inline

Set change flag and call providerValueChanged with given reason.

Parameters
reasonpassed to providerValueChanged signal

Definition at line 296 of file provider.hpp.

◆ getProvider() [1/2]

template<typename ProviderT >
ProviderT * plask::Receiver< ProviderT >::getProvider ( )
inline

Current provider getter.

Returns
current provider or nullptr if there is no connected provider

Definition at line 361 of file provider.hpp.

◆ getProvider() [2/2]

template<typename ProviderT >
const ProviderT * plask::Receiver< ProviderT >::getProvider ( ) const
inline

Current provider getter.

Returns
current provider or nullptr if there is no connected provider

Definition at line 367 of file provider.hpp.

◆ hasProvider()

template<typename ProviderT >
bool plask::Receiver< ProviderT >::hasProvider ( ) const
inline
Returns
true if there is any provider connected

Definition at line 370 of file provider.hpp.

◆ operator()()

template<typename ProviderT >
template<typename ... Args>
auto plask::Receiver< ProviderT >::operator() ( const Args &...  params) const -> decltype((*provider)(params...))
inline

Get value from provider using its operator().

Returns
value from provider
Exceptions
NoProviderwhen provider is not available
NoValuewhen provider can't give value (is uninitialized, etc.)

Definition at line 387 of file provider.hpp.

◆ operator=()

◆ optional()

template<typename ProviderT >
template<typename ... Args>
auto plask::Receiver< ProviderT >::optional ( const Args &...  params) const -> plask::optional<decltype((*provider)(params...))>
inline

Get value from provider using its operator().

If value can't be got (there is no provider or provider can't give value) empty optional is returned.

Returns
value from provider or empty optional if value couldn't be got

Definition at line 398 of file provider.hpp.

◆ providerName()

template<typename ProviderT >
virtual const char * plask::Receiver< ProviderT >::providerName ( ) const
inlinevirtual

Definition at line 265 of file provider.hpp.

◆ setConstValue()

template<typename ProviderT >
template<typename ... ConstProviderConstructorArgs>
void plask::Receiver< ProviderT >::setConstValue ( ConstProviderConstructorArgs &&...  constProviderConstructorArgs)
inline

Set provider for this to provider of constant.

Use ProviderT::ConstProviderType as provider of const type.

Parameters
constProviderConstructorArgsparameters passed to ProviderT::ConstProviderType constructor

Definition at line 413 of file provider.hpp.

◆ setProvider() [1/3]

template<typename ProviderT >
void plask::Receiver< ProviderT >::setProvider ( ProviderT provider)
inline

Change provider.

If new provider is different from current one then changed flag is set.

Parameters
providernew provider

Definition at line 329 of file provider.hpp.

◆ setProvider() [2/3]

template<typename ProviderT >
void plask::Receiver< ProviderT >::setProvider ( ProviderT provider,
bool  newProviderIsPrivate = false 
)
inline

Change provider.

If new provider is different from current one then changed flag is set.

Parameters
providernew provider, can be nullptr to only disconnect from current provider.
newProviderIsPrivatetrue only if provider is private for this and will be deleted by this receiver

Definition at line 305 of file provider.hpp.

◆ setProvider() [3/3]

template<typename ProviderT >
void plask::Receiver< ProviderT >::setProvider ( std::unique_ptr< ProviderT > &&  provider)
inline

Change provider.

If new provider is different from current one then changed flag is set.

Parameters
providernew provider, will be deleted by this receiver

Definition at line 337 of file provider.hpp.

Member Data Documentation

◆ _hasPrivateProvider

template<typename ProviderT >
bool plask::Receiver< ProviderT >::_hasPrivateProvider
protected

Is true only if provider is private and will be deleted by this receiver.

Definition at line 257 of file provider.hpp.

◆ provider

Pointer to connected provider. Can be nullptr if no provider is connected.

Definition at line 277 of file provider.hpp.

◆ PROVIDER_NAME

template<typename ProviderT >
constexpr const char* plask::Receiver< ProviderT >::PROVIDER_NAME = ProviderT::NAME
staticconstexpr

Name of provider.

Definition at line 264 of file provider.hpp.

◆ providerValueChanged

template<typename ProviderT >
boost::signals2::signal<void(ReceiverBase& src, ChangeReason reason)> plask::Receiver< ProviderT >::providerValueChanged

Signal called when provider value or provider was changed (called by onChange)

Definition at line 268 of file provider.hpp.


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