Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lampda::modes::ContextTy< LocalBasicMode, ModeManager >::KeyProxy< _key, T > Struct Template Reference

(store) Binds a local variable of type T to key in storage (with automatic read & save) More...

#include <context_type.hpp>

Public Member Functions

void LMBD_INLINE setValue (T value)
 (optional) Set local to value then write key to store
 
bool LMBD_INLINE getValue ()
 (optional) Read key from store, return True if local was written
 
void LMBD_INLINE getValue (T defVal)
 (optional) Read key value, if not found, set local to defVal
 
bool LMBD_INLINE hasValue ()
 (optional) Return True if key is set in store, False if unknown
 
 KeyProxy (T &local)
 Use ContextTy::storageFor to construct a KeyProxy bound to local.
 

Public Attributes

T & local
 Local variable reference bound to KeyProxy.
 

Static Public Attributes

static constexpr StoreEnum key = _key
 Enumeration value uniquely identifying where local will be stored.
 

Detailed Description

template<typename LocalBasicMode, typename ModeManager>
template<StoreEnum _key, typename T>
struct lampda::modes::ContextTy< LocalBasicMode, ModeManager >::KeyProxy< _key, T >

(store) Binds a local variable of type T to key in storage (with automatic read & save)

Before using this, you must define in your mode the following:

struct MyMode : public modes::BasicMode {
enum class Store : uint16_t {
keyA,
keyB
};
static constexpr uint32_t storeId = modes::store::hash("MyMode");
// ... (other stuff from your mode) ...
};
Parent object for all custom user modes.
Definition: mode_type.hpp:53

You will then be able to bind persistent storage to a local variable:

static void loop(auto& ctx) {
float a = 1.5; // default value
// load value for "a" at "keyA" from storage if available
auto storeA = ctx.template storageFor<keyA>(a);
// ... (do some other stuff) ...
a += 1.0;
// no need to explicitly* save "a" (done automatically)
}
// *when storeA is destroyed, storage for "a" is updated
void LMBD_INLINE loop()
Binds to local BasicMode::loop()
Definition: context_type.hpp:644

Other advanced use-cases are left undocumented, for experienced users :)


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