aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/util')
-rw-r--r--src/crepe/util/CMakeLists.txt2
-rw-r--r--src/crepe/util/Proxy.h33
-rw-r--r--src/crepe/util/Proxy.hpp22
3 files changed, 57 insertions, 0 deletions
diff --git a/src/crepe/util/CMakeLists.txt b/src/crepe/util/CMakeLists.txt
index 3675bee..0fa4343 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
LogColor.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..fbfed0c
--- /dev/null
+++ b/src/crepe/util/Proxy.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "ValueBroker.h"
+
+namespace crepe {
+
+/**
+ * \brief Utility wrapper for \c ValueBroker
+ *
+ * This class can be used to to wrap a ValueBroker instance so it behaves like
+ * a regular variable.
+ *
+ * \tparam T Type of the underlying variable
+ */
+template <typename T>
+class Proxy {
+public:
+ //! Set operator
+ Proxy & operator = (const T &);
+ //! Get operator
+ operator const T & ();
+
+public:
+ Proxy(ValueBroker<T>);
+
+private:
+ ValueBroker<T> broker;
+};
+
+}
+
+#include "Proxy.hpp"
+
diff --git a/src/crepe/util/Proxy.hpp b/src/crepe/util/Proxy.hpp
new file mode 100644
index 0000000..4aec9e9
--- /dev/null
+++ b/src/crepe/util/Proxy.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "Proxy.h"
+
+namespace crepe {
+
+template <typename T>
+Proxy<T>::Proxy(ValueBroker<T> broker) : broker(broker) { }
+
+template <typename T>
+Proxy<T> & Proxy<T>::operator = (const T & val) {
+ this->broker.set(val);
+ return *this;
+}
+
+template <typename T>
+Proxy<T>::operator const T & () {
+ return this->broker.get();
+}
+
+}
+