From e0b1ddae296037376948a4c6f200d89e6d1ba81e Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 26 Oct 2024 15:58:39 +0200 Subject: WIP save manager --- src/example/CMakeLists.txt | 3 +++ src/example/proxy.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++ src/example/savemgr.cpp | 27 ++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/example/proxy.cpp create mode 100644 src/example/savemgr.cpp (limited to 'src/example') diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index fea6f60..8158d60 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -24,3 +24,6 @@ add_example(rendering) add_example(asset_manager) add_example(particle) add_example(physics) +add_example(savemgr) +add_example(proxy) + diff --git a/src/example/proxy.cpp b/src/example/proxy.cpp new file mode 100644 index 0000000..7e2efa5 --- /dev/null +++ b/src/example/proxy.cpp @@ -0,0 +1,47 @@ +/** \file + * + * Standalone example for usage of the proxy type + */ + +#include +#include +#include + +using namespace std; +using namespace crepe; +using namespace crepe::util; + +template +class MyProxyHandler : public ProxyHandler { +public: + virtual void set(const T & val) { + dbg_logf("set %s", to_string(val).c_str()); + this->val = val; + } + + virtual const T & get() { + dbg_logf("get %s", to_string(this->val).c_str()); + return this->val; + } + +private: + T val = 0; +}; + +void test_ro(const int & val) { } +void test_rw(int & val) { } + +int main() { + auto & cfg = api::Config::get_instance(); + cfg.log.level = util::LogLevel::DEBUG; + + Proxy val(make_unique>()); + + val = 54; + + test_ro(val); // this is allowed + // test_rw(val); // this should throw a compile error + + return 0; +} + diff --git a/src/example/savemgr.cpp b/src/example/savemgr.cpp new file mode 100644 index 0000000..810947d --- /dev/null +++ b/src/example/savemgr.cpp @@ -0,0 +1,27 @@ +/** \file + * + * Standalone example for usage of the save manager + */ + +#include +#include +#include + +using namespace crepe; +using namespace crepe::api; +using namespace crepe::util; + +int main() { + const char * key = "mygame.test"; + SaveManager & mgr = SaveManager::get_instance(); + + auto & prop = mgr.get(key, 1); + prop = 2; + + mgr.set(key, 3); + + assert(true == mgr.has(key)); + + return 0; +} + -- cgit v1.2.3