1
0
Fork 0
mirror of https://github.com/eXpl0it3r/PubBus.git synced 2026-01-01 10:43:00 +00:00
A simple implementation of a MessageBus.
Find a file
2024-02-16 08:09:07 +01:00
.github/workflows Update GitHub Actions and Catch2 2024-02-15 23:37:30 +01:00
build Modernize for C++20 and clean up code 2020-10-28 14:12:14 +01:00
cmake Add CMake and GitHub Action support 2021-07-16 00:37:08 +02:00
examples Use const references 2024-02-15 23:53:38 +01:00
extlibs Use local path for locating SFML with Visual Studio 2019-10-15 00:32:32 +02:00
include/PubBus Use const references 2024-02-15 23:53:38 +01:00
test Update GitHub Actions and Catch2 2024-02-15 23:37:30 +01:00
.editorconfig Change tabs to spaces for indentation 2019-10-10 16:36:45 +02:00
.gitattributes Added virtual destructor to MessageContainerBase and override keyword in the MessageContainer class. Additionally enforced LF line endings. 2016-03-21 22:06:11 +01:00
.gitignore Extend example with more SFML messages 2019-10-15 00:32:32 +02:00
CMakeLists.txt Add CMake and GitHub Action support 2021-07-16 00:37:08 +02:00
LICENSE.md Change license to dual licence Unlicense and MIT 2019-09-12 11:32:34 +02:00
README.md Add missing reference to the readme example 2024-02-16 08:09:07 +01:00

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