diff options
Diffstat (limited to 'src/example')
-rw-r--r-- | src/example/proxy.cpp | 13 | ||||
-rw-r--r-- | src/example/savemgr.cpp | 22 |
2 files changed, 25 insertions, 10 deletions
diff --git a/src/example/proxy.cpp b/src/example/proxy.cpp index 7c2cb8d..0be4fac 100644 --- a/src/example/proxy.cpp +++ b/src/example/proxy.cpp @@ -23,14 +23,13 @@ int main() { int real_value = 0; ValueBroker<int> broker { - real_value, - [] (int & value, const int & target) { - dbg_logf("set %s to %s", to_string(value).c_str(), to_string(target).c_str()); - value = target; + [&real_value] (const int & target) { + dbg_logf("set %s to %s", to_string(real_value).c_str(), to_string(target).c_str()); + real_value = target; }, - [] (int & value) -> const int & { - dbg_logf("get %s", to_string(value).c_str()); - return value; + [&real_value] () -> const int & { + dbg_logf("get %s", to_string(real_value).c_str()); + return real_value; }, }; diff --git a/src/example/savemgr.cpp b/src/example/savemgr.cpp index 2c03e3a..6d011e5 100644 --- a/src/example/savemgr.cpp +++ b/src/example/savemgr.cpp @@ -7,23 +7,39 @@ #include <crepe/util/log.h> #include <crepe/util/Proxy.h> #include <crepe/api/SaveManager.h> +#include <crepe/api/Config.h> using namespace crepe; using namespace crepe::api; using namespace crepe::util; +// unrelated setup code +int _ = [] () { + // make sure all log messages get printed + auto & cfg = Config::get_instance(); + cfg.log.level = util::LogLevel::TRACE; + + return 0; // satisfy compiler +} (); + int main() { const char * key = "mygame.test"; SaveManager & mgr = SaveManager::get_instance(); - ValueBroker<unsigned int> & prop = mgr.get<unsigned int>(key, 0); - Proxy<unsigned int> val = mgr.get<unsigned int>(key, 0); + dbg_logf("has key = %s", mgr.has(key) ? "true" : "false"); + ValueBroker<int> prop = mgr.get<int>(key, 0); + Proxy<int> val = mgr.get<int>(key, 0); + dbg_logf("val = %d", mgr.get<int>(key).get()); prop.set(1); + dbg_logf("val = %d", mgr.get<int>(key).get()); val = 2; - mgr.set<unsigned int>(key, 3); + dbg_logf("val = %d", mgr.get<int>(key).get()); + mgr.set<int>(key, 3); + dbg_logf("val = %d", mgr.get<int>(key).get()); + dbg_logf("has key = %s", mgr.has(key) ? "true" : "false"); assert(true == mgr.has(key)); return 0; |