diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-26 15:58:39 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-26 15:58:39 +0200 |
commit | e0b1ddae296037376948a4c6f200d89e6d1ba81e (patch) | |
tree | f70e5a9b73e0b10e5c9fe263e146e9884474ac0f /src/example/proxy.cpp | |
parent | 2d67cf09b80297d13f642afd7db13dba53ca2b9b (diff) |
WIP save manager
Diffstat (limited to 'src/example/proxy.cpp')
-rw-r--r-- | src/example/proxy.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
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 <crepe/api/Config.h> +#include <crepe/util/log.h> +#include <crepe/Proxy.h> + +using namespace std; +using namespace crepe; +using namespace crepe::util; + +template <typename T> +class MyProxyHandler : public ProxyHandler<T> { +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<int> val(make_unique<MyProxyHandler<int>>()); + + val = 54; + + test_ro(val); // this is allowed + // test_rw(val); // this should throw a compile error + + return 0; +} + |