Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
1290afdc68 |
40
include/Base.h
Normal file
40
include/Base.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
//template< class RT, class CallableT, class... ArgTypes >
|
||||
template<class CallableT, class... ArgTypes >
|
||||
class Callable {
|
||||
static_assert(std::is_invocable_v<CallableT(ArgTypes...)>);
|
||||
using invoke = CallableT;
|
||||
public:
|
||||
invoke;
|
||||
//CallableT invoke = CallableT();
|
||||
//ArgTypes... args
|
||||
//invoke() { /*return CallableT(args...);*/ return CallableT(RT()); }
|
||||
};
|
||||
|
||||
template< class R, class Fn, class... ArgTypes >
|
||||
class Cunt {
|
||||
static_assert(std::is_invocable_r_v<R, Fn, ArgTypes...>);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template< class RT, class... ArgTypes>
|
||||
class EventBase {
|
||||
public:
|
||||
//using delegate = CallableT;
|
||||
using delegate = std::function<RT(ArgTypes...)>;
|
||||
public:
|
||||
RT Invoke(ArgTypes... args);
|
||||
RT operator()(ArgTypes... args);
|
||||
protected:
|
||||
delegate callback;
|
||||
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
@@ -29,14 +29,14 @@ public:
|
||||
using event_ptr = std::shared_ptr<connection>;
|
||||
public:
|
||||
void Await(Args& ... arg);
|
||||
void Invoke(Args... args);
|
||||
virtual void Invoke(Args... args);
|
||||
void operator()(Args... args);
|
||||
connection Connect(delegate callback);
|
||||
void Disconnect(connection &conn);
|
||||
connection operator+=(delegate callback);
|
||||
private:
|
||||
protected:
|
||||
std::vector<event_ptr> listeners;
|
||||
uint64_t listenerCounter = 0;
|
||||
//uint64_t listenerCounter = 0;
|
||||
};
|
||||
|
||||
template<typename delegate, typename... Args>
|
||||
|
@@ -21,9 +21,11 @@ public:
|
||||
Connection(BasicEvent<delegate, Args...> *creator, delegate cb);
|
||||
bool Disconnect(); // Breaks the event connection, but does not destroy the instance
|
||||
void Invoke(Args... e);
|
||||
protected:
|
||||
delegate callback;
|
||||
private:
|
||||
BasicEvent<delegate, Args...> * owner;
|
||||
delegate callback;
|
||||
//delegate callback;
|
||||
bool active = true;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user