From ecc5761fa78ccb57db958467c3fc999aceadd409 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 27 Oct 2024 16:50:20 +0100 Subject: fix valuebroker/proxy system --- src/crepe/util/CMakeLists.txt | 2 ++ src/crepe/util/Proxy.h | 23 +++++++++++++++++++++++ src/crepe/util/Proxy.hpp | 22 ++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/crepe/util/Proxy.h create mode 100644 src/crepe/util/Proxy.hpp (limited to 'src/crepe/util') diff --git a/src/crepe/util/CMakeLists.txt b/src/crepe/util/CMakeLists.txt index bbeaad9..01d8f22 100644 --- a/src/crepe/util/CMakeLists.txt +++ b/src/crepe/util/CMakeLists.txt @@ -8,5 +8,7 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES color.h log.h fmt.h + Proxy.h + Proxy.hpp ) diff --git a/src/crepe/util/Proxy.h b/src/crepe/util/Proxy.h new file mode 100644 index 0000000..f8eb1f2 --- /dev/null +++ b/src/crepe/util/Proxy.h @@ -0,0 +1,23 @@ +#pragma once + +#include "ValueBroker.h" + +namespace crepe::util { + +template +class Proxy { +public: + Proxy & operator = (const T &); + operator const T & () const; + +public: + Proxy(ValueBroker &); + +private: + ValueBroker & broker; +}; + +} + +#include "Proxy.hpp" + diff --git a/src/crepe/util/Proxy.hpp b/src/crepe/util/Proxy.hpp new file mode 100644 index 0000000..5738d9c --- /dev/null +++ b/src/crepe/util/Proxy.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "Proxy.h" + +namespace crepe::util { + +template +Proxy::Proxy(ValueBroker & broker) : broker(broker) { } + +template +Proxy & Proxy::operator = (const T & val) { + this->broker.set(val); + return *this; +} + +template +Proxy::operator const T & () const { + return this->broker.get(); +} + +} + -- cgit v1.2.3