Some documentation work

This commit is contained in:
2024-08-21 15:38:42 -04:00
parent 69e245632f
commit 5e3e20a7e5
3 changed files with 9 additions and 14 deletions

View File

@@ -14,7 +14,7 @@
// TODO: ThreadSafeEvent / AsyncEvent version of the class.
// TODO: ConsumableEvent - a version that can be "consumed" by a callback by returning true. It will be sunk and not passed to further callbacks.
///
/// See EventConnection.h
template <typename delegate, typename ... Args>
class Connection;
@@ -25,12 +25,12 @@ class Connection;
template <typename delegate, typename ... Args>
class BasicEvent {
public:
friend Connection<delegate, Args ...>;
using connection = Connection<delegate, Args ...>;
using event_ptr = std::shared_ptr<connection>;
public:
void Await(Args& ... arg);
/// Invokes the event, calling all currently bound connections, and passing in the given arguments.
virtual void Invoke(Args... args);
/// The call operator also invokes the event
void operator()(Args... args);
connection Connect(delegate callback);
void Disconnect(connection &conn);
@@ -66,6 +66,7 @@ void BasicEvent<delegate, Args...>::Disconnect(connection &conn) {
listeners.erase(std::remove(listeners.begin(), listeners.end(), 99), listeners.end());
}
/// The default event which uses a std::function as the delegate.
template <typename ... Args>
using Event = BasicEvent<std::function<void(Args...)>, Args...>;

View File

@@ -10,6 +10,7 @@
#include <functional>
#include <Event.h>
/// @see Event.h
template <typename delegate, typename ... Args>
class BasicEvent;

View File

@@ -8,27 +8,22 @@ void ProcessMessage(const std::string& message)
std::cout << "Received: " << message << std::endl;
}
// TODO: Event tests here.
int main() {
Event<int> cum;
Event<int> very_simple_event;
cum += [] (int i) { std::cout << i+5 << std::endl; };
cum.Invoke(69);
very_simple_event += [] (int i) { std::cout << i+5 << std::endl; };
very_simple_event.Invoke(69);
BasicEvent<std::function<void(std::string)>, std::string> OnMessage;
BasicEvent<std::function<void()>> VoidDelegate;
bool run = true;
auto handler = OnMessage += [&] (const std::string& message)
{
std::cout << "GOTS A MESSAGE: " << message << std::endl;
};
auto handler2 = OnMessage += ProcessMessage;
auto handler2 = OnMessage += ProcessMessage;
while (run)
{
std::string input;
@@ -38,8 +33,6 @@ int main() {
OnMessage(input);
VoidDelegate();
}
return 0;
}