FastArduino  v1.9 alpha
C++ library to build fast but small Arduino/AVR projects
lifecycle::LightProxy< T > Class Template Reference

A light proxy class that encapsulates access to a fixed T instance, or to a dynamic LifeCycle<T> instance. More...

#include <fastarduino/lifecycle.h>

Public Member Functions

 LightProxy (const T &dest)
 Create a LightProxy<T> to a static reference. More...
 
template<typename U >
 LightProxy (const LifeCycle< U > &dest)
 Create a LightProxy<T> to a LifeCycle<U> instance (dynamic reference). More...
 
 LightProxy (const Proxy< T > &proxy)
 Create a LightProxy<T> from a Proxy<T>. More...
 
T * operator() (const AbstractLifeCycleManager *manager=nullptr) const
 Return a pointer to the proxified T instance. More...
 
bool is_dynamic () const
 Tell if this LightProxy is dynamic or static. More...
 
uint8_t id () const
 The identifier of the proxified LifeCycle<U> or 0 if a static instance was proxified.
 
T * destination () const
 A pointer to the static instance proxified, or nullptr if a dynamic instance (a LifeCycle<U>) was proxified.
 

Friends

bool operator== (const LightProxy< T > &, const LightProxy< T > &)
 
bool operator!= (const LightProxy< T > &, const LightProxy< T > &)
 

Detailed Description

template<typename T>
class lifecycle::LightProxy< T >

A light proxy class that encapsulates access to a fixed T instance, or to a dynamic LifeCycle<T> instance.

Each instance uses 2 bytes, instead of 3 bytes for a Proxy instance. The downside is that a dynamic LightProxy (i.e. constructed with a LifeCycle<T>) has to be passed the proper LifeCycleManager every time we want to get the pointer to the actual proxied instance.

Warning
Since proxying a T instance incurs overhead (data size, code size and speed), you should use LightProxy<T> only when it makes sense.
Template Parameters
Tthe type of the object proxied
See also
Proxy

Definition at line 642 of file lifecycle.h.

Constructor & Destructor Documentation

◆ LightProxy() [1/3]

template<typename T >
lifecycle::LightProxy< T >::LightProxy ( const T &  dest)
inline

Create a LightProxy<T> to a static reference.

Parameters
destthe reference to a T instance to proxify.

Definition at line 649 of file lifecycle.h.

◆ LightProxy() [2/3]

template<typename T >
template<typename U >
lifecycle::LightProxy< T >::LightProxy ( const LifeCycle< U > &  dest)
inline

Create a LightProxy<T> to a LifeCycle<U> instance (dynamic reference).

Template Parameters
Uthe type of reference held by dest; must be T or a subclass of T, otherwise code will not compile.
Parameters
destthe reference to a LifeCycle<U> instance to proxify; if dest is later moved, it will eb automatically tracked by this Proxy<T>.
See also
LifeCycle

Definition at line 662 of file lifecycle.h.

◆ LightProxy() [3/3]

template<typename T >
lifecycle::LightProxy< T >::LightProxy ( const Proxy< T > &  proxy)
inlineexplicit

Create a LightProxy<T> from a Proxy<T>.

Parameters
proxythe original Proxy<T> to copy into this LightProxy
See also
Proxy

Definition at line 674 of file lifecycle.h.

Member Function Documentation

◆ operator()()

template<typename T >
T* lifecycle::LightProxy< T >::operator() ( const AbstractLifeCycleManager manager = nullptr) const
inline

Return a pointer to the proxified T instance.

Parameters
managera pointer to the LifeCycleManager which was used to register the underlying LifeCycle<T> instance; can be nullptr if this is a static proxy. Behaviour is undefined if nullptr and this LightProxy is dynamic.

Definition at line 712 of file lifecycle.h.

◆ is_dynamic()

template<typename T >
bool lifecycle::LightProxy< T >::is_dynamic ( ) const
inline

Tell if this LightProxy is dynamic or static.

A dynamic proxy was constructed with a LifeCycle<T> instance and thus ensures that the actual instance will aways be referenced even if it gets moved. A static proxy was constructed directly with a T instance.

Definition at line 728 of file lifecycle.h.


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