docs: add documentation for event lib
This commit is contained in:
@@ -92,12 +92,44 @@ int main() {
|
||||
```
|
||||
|
||||
<a name="module-assertion"></a>
|
||||
### 2. Assertion
|
||||
### 2. Assert
|
||||
(Documentation pending implementation)
|
||||
|
||||
<a name="module-events"></a>
|
||||
### 3. Events
|
||||
(Documentation pending implementation)
|
||||
The Events module provides a thread and type safe signal/slot mechanism. It allows you to define custom events with any number of parameters and subscribe to them using callbacks.
|
||||
#### Basic Usage
|
||||
```cpp
|
||||
#include <seallib/event.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace seallib;
|
||||
|
||||
// Define an event that takes an int and a string
|
||||
Event<int, std::string> OnUserLogin;
|
||||
|
||||
void onLogin(int id, std::string name) {
|
||||
std::cout << "User " << name << " (ID: " << id << ") logged in!" << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// 1. Subscribe to the event
|
||||
auto connection = OnUserLogin.addListener(onLogin);
|
||||
|
||||
// 2. Add a lambda listener
|
||||
OnUserLogin.addListener([](int id, auto name) {
|
||||
std::clog << "[Log] Login detected for ID: " << id << std::endl;
|
||||
});
|
||||
|
||||
// 3. Trigger the event
|
||||
OnUserLogin.run(42, "SomeUser");
|
||||
|
||||
// 4. Remove a listener when no longer needed
|
||||
OnUserLogin.removeListener(connection);
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
<a name="module-vfs"></a>
|
||||
### 4. VFS
|
||||
|
||||
Reference in New Issue
Block a user