FastArduino
v1.9 alpha
C++ library to build fast but small Arduino/AVR projects
|
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 > &) |
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.
T
instance incurs overhead (data size, code size and speed), you should use LightProxy<T>
only when it makes sense.T | the type of the object proxied |
Definition at line 642 of file lifecycle.h.
|
inline |
Create a LightProxy<T>
to a static reference.
dest | the reference to a T instance to proxify. |
Definition at line 649 of file lifecycle.h.
|
inline |
Create a LightProxy<T>
to a LifeCycle<U>
instance (dynamic reference).
U | the type of reference held by dest ; must be T or a subclass of T , otherwise code will not compile. |
dest | the reference to a LifeCycle<U> instance to proxify; if dest is later moved, it will eb automatically tracked by this Proxy<T> . |
Definition at line 662 of file lifecycle.h.
|
inlineexplicit |
Create a LightProxy<T>
from a Proxy<T>
.
proxy | the original Proxy<T> to copy into this LightProxy |
Definition at line 674 of file lifecycle.h.
|
inline |
Return a pointer to the proxified T
instance.
manager | a 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.
|
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.