PLaSK library
|
Base class for all Receivers. More...
#include <plask/provider/provider.hpp>
Public Types | |
typedef Receiver< ProviderT > | Base |
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 char * | providerName () const |
Receiver & | operator= (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. | |
ProviderT * | getProvider () |
Current provider getter. | |
const ProviderT * | getProvider () 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) | |
ProviderT * | provider |
Pointer to connected provider. Can be nullptr if no provider is connected. | |
Static Public Attributes | |
static constexpr const char * | PROVIDER_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. | |
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)
ProviderT | type of provider, can has defined ProviderT::ConstProviderType to receiver setConst method work. |
Definition at line 250 of file provider.hpp.
Definition at line 261 of file provider.hpp.
Type of the corresponding provider.
Definition at line 274 of file provider.hpp.
|
delete |
|
inline |
Construct Receiver without connected provider and with set changed flag.
Definition at line 280 of file provider.hpp.
Destructor. Disconnect from provider.
Definition at line 283 of file provider.hpp.
|
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.
NoProvider | when provider is not available |
Definition at line 445 of file provider.hpp.
|
inline |
Connect a method to changed signal.
obj,method | slot to connect, object and it's method |
at | specifies where the slot should be connected:
|
Definition at line 425 of file provider.hpp.
|
inline |
Disconnect a method from changed signal.
Definition at line 431 of file provider.hpp.
|
inline |
NoProvider | when provider is not available |
Definition at line 375 of file provider.hpp.
|
inline |
Set change flag and call providerValueChanged with given reason
.
reason | passed to providerValueChanged signal |
Definition at line 296 of file provider.hpp.
|
inline |
Current provider getter.
nullptr
if there is no connected provider Definition at line 361 of file provider.hpp.
|
inline |
Current provider getter.
nullptr
if there is no connected provider Definition at line 367 of file provider.hpp.
|
inline |
Definition at line 370 of file provider.hpp.
|
inline |
Get value from provider using its operator().
NoProvider | when provider is not available |
NoValue | when provider can't give value (is uninitialized, etc.) |
Definition at line 387 of file provider.hpp.
|
delete |
|
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.
Definition at line 398 of file provider.hpp.
|
inlinevirtual |
Definition at line 265 of file provider.hpp.
|
inline |
Set provider for this to provider of constant.
Use ProviderT::ConstProviderType as provider of const type.
constProviderConstructorArgs | parameters passed to ProviderT::ConstProviderType constructor |
Definition at line 413 of file provider.hpp.
|
inline |
Change provider.
If new provider is different from current one then changed flag is set.
provider | new provider |
Definition at line 329 of file provider.hpp.
|
inline |
Change provider.
If new provider is different from current one then changed flag is set.
provider | new provider, can be nullptr to only disconnect from current provider. |
newProviderIsPrivate | true only if provider is private for this and will be deleted by this receiver |
Definition at line 305 of file provider.hpp.
|
inline |
Change provider.
If new provider is different from current one then changed flag is set.
provider | new provider, will be deleted by this receiver |
Definition at line 337 of file provider.hpp.
|
protected |
Is true
only if provider is private and will be deleted by this receiver.
Definition at line 257 of file provider.hpp.
ProviderT* plask::Receiver< ProviderT >::provider |
Pointer to connected provider. Can be nullptr if no provider is connected.
Definition at line 277 of file provider.hpp.
|
staticconstexpr |
Name of provider.
Definition at line 264 of file provider.hpp.
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.