Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andsmedeiros/fuss

Efficient in-process pub/sub pattern for C++
https://github.com/andsmedeiros/fuss

Last synced: 2 months ago
JSON representation

Efficient in-process pub/sub pattern for C++

Awesome Lists containing this project

README

        

# FUSS

FUSS is a simple and efficient pub/sub pattern implementation aimed for C++17 programs with an intuitive interface.
It consists of a single header file and has no external dependencies.

## Features

- Simple, efficient, small and elegant. Just read the code!
- Leverages modern C++ to provide an intuitive and pleasant API.
- Avoids unnecessary dynamic memory as much as possible.
- No virtual functions.
- No RTTI.

## Example

```C++
#include

// Define what messages are available to be published.
struct greeting : fuss::message<> {};

// Note that messages can have parameters.
struct echo : fuss::message {};

// Create a publisher object
struct noisy : fuss::shouter {
void greet() {
// Publishes the `greeting` message.
// `shout()` is protected, so we create a member function to call it
shout();
}

void repeat(const std::string &s) {
// Publishes the `echo` message with a string as parameter
shout(s);
}
};

// Instantiate the publisher
noisy n;

// Subscribe to the messages
auto greeting_listener = n.listen([]() {
std::cout << "Hello world!" << std::endl;
});

n.listen([](std::string s) {
std::cout << s << std::endl;
});

n.greet(); // prints 'Hello world!'
n.repeat("What a fuss!"); // prints 'What a fuss!'

// Unsubscribe from a message
n.unlisten(greeting_listener);

n.greet(); // doesn't print anything

```

## Copyright

Copyright André Medeiros 2022
Contact: [email protected]