Switch from Nz prefix to namespace Nz
What a huge commit Former-commit-id: 38ac5eebf70adc1180f571f6006192d28fb99897
This commit is contained in:
@@ -11,122 +11,124 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#define NazaraSignal(SignalName, ...) using SignalName ## Type = NzSignal<__VA_ARGS__>; \
|
||||
#define NazaraSignal(SignalName, ...) using SignalName ## Type = Nz::Signal<__VA_ARGS__>; \
|
||||
mutable SignalName ## Type SignalName
|
||||
|
||||
#define NazaraSlotType(Class, SignalName) Class::SignalName ## Type::ConnectionGuard
|
||||
#define NazaraSlot(Class, SignalName, SlotName) NazaraSlotType(Class, SignalName) SlotName
|
||||
|
||||
|
||||
template<typename... Args>
|
||||
class NzSignal
|
||||
namespace Nz
|
||||
{
|
||||
public:
|
||||
using Callback = std::function<void(Args...)>;
|
||||
class Connection;
|
||||
class ConnectionGuard;
|
||||
template<typename... Args>
|
||||
class Signal
|
||||
{
|
||||
public:
|
||||
using Callback = std::function<void(Args...)>;
|
||||
class Connection;
|
||||
class ConnectionGuard;
|
||||
|
||||
NzSignal();
|
||||
NzSignal(const NzSignal&) = delete;
|
||||
NzSignal(NzSignal&& signal);
|
||||
~NzSignal() = default;
|
||||
Signal();
|
||||
Signal(const Signal&) = delete;
|
||||
Signal(Signal&& signal);
|
||||
~Signal() = default;
|
||||
|
||||
void Clear();
|
||||
void Clear();
|
||||
|
||||
Connection Connect(const Callback& func);
|
||||
Connection Connect(Callback&& func);
|
||||
template<typename O> Connection Connect(O& object, void (O::*method)(Args...));
|
||||
template<typename O> Connection Connect(O* object, void (O::*method)(Args...));
|
||||
template<typename O> Connection Connect(const O& object, void (O::*method)(Args...) const);
|
||||
template<typename O> Connection Connect(const O* object, void (O::*method)(Args...) const);
|
||||
Connection Connect(const Callback& func);
|
||||
Connection Connect(Callback&& func);
|
||||
template<typename O> Connection Connect(O& object, void (O::*method)(Args...));
|
||||
template<typename O> Connection Connect(O* object, void (O::*method)(Args...));
|
||||
template<typename O> Connection Connect(const O& object, void (O::*method)(Args...) const);
|
||||
template<typename O> Connection Connect(const O* object, void (O::*method)(Args...) const);
|
||||
|
||||
void operator()(Args... args) const;
|
||||
void operator()(Args... args) const;
|
||||
|
||||
NzSignal& operator=(const NzSignal&) = delete;
|
||||
NzSignal& operator=(NzSignal&& signal);
|
||||
Signal& operator=(const Signal&) = delete;
|
||||
Signal& operator=(Signal&& signal);
|
||||
|
||||
private:
|
||||
struct Slot;
|
||||
private:
|
||||
struct Slot;
|
||||
|
||||
using SlotPtr = std::shared_ptr<Slot>;
|
||||
using SlotList = std::vector<SlotPtr>;
|
||||
using SlotListIndex = typename SlotList::size_type;
|
||||
using SlotPtr = std::shared_ptr<Slot>;
|
||||
using SlotList = std::vector<SlotPtr>;
|
||||
using SlotListIndex = typename SlotList::size_type;
|
||||
|
||||
struct Slot
|
||||
{
|
||||
Slot(NzSignal* me) :
|
||||
signal(me)
|
||||
struct Slot
|
||||
{
|
||||
}
|
||||
Slot(Signal* me) :
|
||||
signal(me)
|
||||
{
|
||||
}
|
||||
|
||||
Callback callback;
|
||||
NzSignal* signal;
|
||||
SlotListIndex index;
|
||||
};
|
||||
Callback callback;
|
||||
Signal* signal;
|
||||
SlotListIndex index;
|
||||
};
|
||||
|
||||
void Disconnect(const SlotPtr& slot);
|
||||
void Disconnect(const SlotPtr& slot);
|
||||
|
||||
SlotList m_slots;
|
||||
mutable SlotListIndex m_slotIterator;
|
||||
};
|
||||
SlotList m_slots;
|
||||
mutable SlotListIndex m_slotIterator;
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
class NzSignal<Args...>::Connection
|
||||
{
|
||||
using BaseClass = NzSignal<Args...>;
|
||||
friend BaseClass;
|
||||
template<typename... Args>
|
||||
class Signal<Args...>::Connection
|
||||
{
|
||||
using BaseClass = Signal<Args...>;
|
||||
friend BaseClass;
|
||||
|
||||
public:
|
||||
Connection() = default;
|
||||
Connection(const Connection& connection) = default;
|
||||
Connection(Connection&& connection) = default;
|
||||
~Connection() = default;
|
||||
public:
|
||||
Connection() = default;
|
||||
Connection(const Connection& connection) = default;
|
||||
Connection(Connection&& connection) = default;
|
||||
~Connection() = default;
|
||||
|
||||
template<typename... ConnectArgs>
|
||||
void Connect(BaseClass& signal, ConnectArgs&&... args);
|
||||
void Disconnect();
|
||||
template<typename... ConnectArgs>
|
||||
void Connect(BaseClass& signal, ConnectArgs&&... args);
|
||||
void Disconnect();
|
||||
|
||||
bool IsConnected() const;
|
||||
bool IsConnected() const;
|
||||
|
||||
Connection& operator=(const Connection& connection) = default;
|
||||
Connection& operator=(Connection&& connection) = default;
|
||||
Connection& operator=(const Connection& connection) = default;
|
||||
Connection& operator=(Connection&& connection) = default;
|
||||
|
||||
private:
|
||||
Connection(const SlotPtr& slot);
|
||||
private:
|
||||
Connection(const SlotPtr& slot);
|
||||
|
||||
std::weak_ptr<Slot> m_ptr;
|
||||
};
|
||||
std::weak_ptr<Slot> m_ptr;
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
class NzSignal<Args...>::ConnectionGuard
|
||||
{
|
||||
using BaseClass = NzSignal<Args...>;
|
||||
using Connection = typename BaseClass::Connection;
|
||||
template<typename... Args>
|
||||
class Signal<Args...>::ConnectionGuard
|
||||
{
|
||||
using BaseClass = Signal<Args...>;
|
||||
using Connection = typename BaseClass::Connection;
|
||||
|
||||
public:
|
||||
ConnectionGuard() = default;
|
||||
ConnectionGuard(const Connection& connection);
|
||||
ConnectionGuard(const ConnectionGuard& connection) = delete;
|
||||
ConnectionGuard(Connection&& connection);
|
||||
ConnectionGuard(ConnectionGuard&& connection) = default;
|
||||
~ConnectionGuard();
|
||||
public:
|
||||
ConnectionGuard() = default;
|
||||
ConnectionGuard(const Connection& connection);
|
||||
ConnectionGuard(const ConnectionGuard& connection) = delete;
|
||||
ConnectionGuard(Connection&& connection);
|
||||
ConnectionGuard(ConnectionGuard&& connection) = default;
|
||||
~ConnectionGuard();
|
||||
|
||||
template<typename... ConnectArgs>
|
||||
void Connect(BaseClass& signal, ConnectArgs&&... args);
|
||||
void Disconnect();
|
||||
template<typename... ConnectArgs>
|
||||
void Connect(BaseClass& signal, ConnectArgs&&... args);
|
||||
void Disconnect();
|
||||
|
||||
Connection& GetConnection();
|
||||
Connection& GetConnection();
|
||||
|
||||
bool IsConnected() const;
|
||||
bool IsConnected() const;
|
||||
|
||||
ConnectionGuard& operator=(const Connection& connection);
|
||||
ConnectionGuard& operator=(const ConnectionGuard& connection) = delete;
|
||||
ConnectionGuard& operator=(Connection&& connection);
|
||||
ConnectionGuard& operator=(ConnectionGuard&& connection);
|
||||
ConnectionGuard& operator=(const Connection& connection);
|
||||
ConnectionGuard& operator=(const ConnectionGuard& connection) = delete;
|
||||
ConnectionGuard& operator=(Connection&& connection);
|
||||
ConnectionGuard& operator=(ConnectionGuard&& connection);
|
||||
|
||||
private:
|
||||
Connection m_connection;
|
||||
};
|
||||
private:
|
||||
Connection m_connection;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Signal.inl>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user