Awesome
PubBus
PubBus is a simple, header-only implementation of a MessageBus.
Unit tests are written with the Catch2 test framework.
Note: PubBus requires C++17, the examples and tests use some C++20 features
Example
#include <PubBus/PubBus.hpp>
#include <iostream>
struct DummyMessage : pub::Message
{
int important_value = 0;
};
int main()
{
auto bus = pub::MessageBus{};
const auto message = DummyMessage{ .important_value = 100 };
bus.subscribe<DummyMessage>(
[](const DummyMessage& message)
{
std::cout << "Important value: " << message.important_value << "\n";
}
);
bus.publish(message);
}
Test Execution
For Visual Studio I recommend installing the Test Adapter for Catch2 and set it up to use the provided catch.runsettings
.
For CMake/CTest you can run: ctest <build-dir>/test -S Release
License
This software is available under 2 licenses -- choose whichever you prefer.
- Public Domain
- MIT
Credits
- Message Bus (GDD #3) by Stefan Schindler
- SW Message Bus by Evgeny Zavalkovsky
- Catch C++ Test Framework by Phil Nash