Skip to content
Snippets Groups Projects
Commit a26f9a0a authored by Sebastian Gaida's avatar Sebastian Gaida
Browse files

[#14] add event struct

added event struct to projekt
supports lambda functionality of event handling
main of first triangle will add a example
parent 07f72bd7
No related branches found
No related tags found
1 merge request!25Resolve "EventPoll mit Lambdas"
...@@ -51,4 +51,6 @@ set(vkcv_sources ...@@ -51,4 +51,6 @@ set(vkcv_sources
${vkcv_source}/vkcv/Framebuffer.hpp ${vkcv_source}/vkcv/Framebuffer.hpp
${vkcv_source}/vkcv/Framebuffer.cpp ${vkcv_source}/vkcv/Framebuffer.cpp
${vkcv_include}/vkcv/Event.hpp
) )
#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;
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment