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
#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);
}
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
This software is available under 2 licenses -- choose whichever you prefer.
- Public Domain
- MIT
- Message Bus (GDD #3) by Stefan Schindler
- SW Message Bus by Evgeny Zavalkovsky
- Catch C++ Test Framework by Phil Nash