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

A 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

 Proxy (const T &dest)
 Create a Proxy<T> to a static reference. More...
 
template<typename U >
 Proxy (const LifeCycle< U > &dest)
 Create a Proxy<T> to a LifeCycle<U> instance (dynamic reference). More...
 
T & operator* ()
 Return a reference to the proxified T instance.
 
T * operator-> ()
 Overloaded -> operator, allowing access to proxified type T instance members.
 
bool is_dynamic () const
 Tell if this Proxy 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.
 
AbstractLifeCycleManagermanager () const
 The LifeCycleManager managing the proxified LifeCycle<U>, or nullptr if a static instance was proxified.
 

Friends

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

Detailed Description

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

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

This allows to define a method which argument does not have to care whether the object passed should be dynamic or static.

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

Definition at line 458 of file lifecycle.h.

Constructor & Destructor Documentation

◆ Proxy() [1/2]

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

Create a Proxy<T> to a static reference.

Parameters
destthe reference to a T instance to proxify.

Definition at line 465 of file lifecycle.h.

◆ Proxy() [2/2]

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

Create a Proxy<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 be automatically tracked by this Proxy<T>.
See also
LifeCycle

Definition at line 479 of file lifecycle.h.

Member Function Documentation

◆ is_dynamic()

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

Tell if this Proxy 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 532 of file lifecycle.h.


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