blob: 7e2efa546a0f9f0789175d50b033b9e14b6e309d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
}
|