From a26f9a0ae7ac2fdbd66b635a11df23fe76f554f7 Mon Sep 17 00:00:00 2001
From: Sebastian Gaida <gaida@ca-digit.com>
Date: Thu, 20 May 2021 15:12:19 +0200
Subject: [PATCH] [#14] add event struct

added event struct to projekt
supports lambda functionality of event handling
main of first triangle will add a example
---
 config/Sources.cmake   |  2 ++
 include/vkcv/Event.hpp | 62 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)
 create mode 100644 include/vkcv/Event.hpp

diff --git a/config/Sources.cmake b/config/Sources.cmake
index 0d0a3787..9d2c7b1f 100644
--- a/config/Sources.cmake
+++ b/config/Sources.cmake
@@ -51,4 +51,6 @@ set(vkcv_sources
         
         ${vkcv_source}/vkcv/Framebuffer.hpp
         ${vkcv_source}/vkcv/Framebuffer.cpp
+
+		${vkcv_include}/vkcv/Event.hpp
 )
diff --git a/include/vkcv/Event.hpp b/include/vkcv/Event.hpp
new file mode 100644
index 00000000..2d30059c
--- /dev/null
+++ b/include/vkcv/Event.hpp
@@ -0,0 +1,62 @@
+#pragma once
+
+namespace vkcv {
+
+    template<typename... T>
+    struct event_function {
+        typedef std::function<void(T...)> type;
+    };
+
+    /**
+     * template for event handling
+     * @tparam T parameter list
+     */
+    template<typename... T>
+    struct event {
+    private:
+        std::vector<typename event_function<T...>::type> m_handles;
+
+    public:
+
+        /**
+         * calls all function handles with the given arguments
+         * @param arguments of the given function
+         */
+        void operator()(T... arguments) {
+            for (auto &handle : this->m_handles) {
+                handle(arguments...);
+            }
+        }
+
+        /**
+         * adds a function handle to the event to be called
+         * @param handle of the function
+         */
+        void add(typename event_function<T...>::type handle) {
+            this->m_handles.push_back(handle);
+        }
+
+        /**
+         * removes a function handle of the event
+         * @param handle of the function
+         */
+        void remove(typename event_function<T...>::type handle) {
+            this->m_handles.erase(
+                    remove(this->m_handles.begin(), this->m_handles.end(), handle),
+                    this->m_handles.end()
+            );
+        }
+
+        event() = default;
+
+        event(const event &other) = delete;
+
+        event(event &&other) = delete;
+
+        ~event() = default;
+
+        event &operator=(const event &other) = delete;
+
+        event &operator=(event &&other) = delete;
+    };
+}
-- 
GitLab