Core/Signal: Add Signals (WIP)
Former-commit-id: eee55aa563f29c5604437f3c1a2b172af1a6410d
This commit is contained in:
parent
cab52dfcfd
commit
0f27930467
|
|
@ -0,0 +1,32 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_SIGNAL_HPP
|
||||||
|
#define NAZARA_SIGNAL_HPP
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
class NzSignal
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using Callback = std::function<void(Args...)>;
|
||||||
|
|
||||||
|
NzSignal() = default;
|
||||||
|
~NzSignal() = default;
|
||||||
|
|
||||||
|
void Connect(const Callback& func);
|
||||||
|
|
||||||
|
void operator()(Args&&... args);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Callback> m_callbacks;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include <Nazara/Core/Signal.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_SIGNAL_HPP
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void NzSignal<Args...>::Connect(const Callback& func)
|
||||||
|
{
|
||||||
|
m_callbacks.push_back(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
void NzSignal<Args...>::operator()(Args&&... args)
|
||||||
|
{
|
||||||
|
for (const Callback& func : m_callbacks)
|
||||||
|
func(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/DebugOff.hpp>
|
||||||
Loading…
Reference in New Issue