Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dacap/observable
Observer pattern and signals/slots for C++11 projects
https://github.com/dacap/observable
cpp multiple-threads observer-pattern signal slot
Last synced: 3 months ago
JSON representation
Observer pattern and signals/slots for C++11 projects
- Host: GitHub
- URL: https://github.com/dacap/observable
- Owner: dacap
- License: mit
- Created: 2016-06-22T16:32:32.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-06-10T22:22:18.000Z (5 months ago)
- Last Synced: 2024-06-11T01:07:27.599Z (5 months ago)
- Topics: cpp, multiple-threads, observer-pattern, signal, slot
- Language: C++
- Homepage:
- Size: 50.8 KB
- Stars: 63
- Watchers: 6
- Forks: 22
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
- AwesomeCppGameDev - observable
README
Observable Library
==================*Copyright (C) 2016-2021 David Capello*
[![build](https://github.com/dacap/observable/actions/workflows/build.yml/badge.svg)](https://github.com/dacap/observable/actions/workflows/build.yml)
[![MIT Licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)Library to use the observer pattern in C++11 programs with
observable/observer classes or signals/slots.Features
--------* Generate an observable notification/signal from multiple threads
* Add/remove observers/slots from multiple threads
* Erase/disconnect an observer/slot from the same observable notification/signal
* Reconnect an observer in the same notificationObservable
----------An observable `Widget`:
```cpp
#include "obs.h"class WidgetObserver {
public:
virtual ~WidgetObserver() = 0;
virtual void onClick() { }
};class Widget : public obs::observable {
public:
void processClick() {
notify_observers(&WidgetObserver::onClick);
}
};
```An example
```cpp
#include "obs.h"class ObserveClick : public WidgetObserver {
public:
void onClick() override {
// Do something...
}
};...
ObserveClick observer;
Widget button;
button.add_observer(&observer);
```Signal
------```cpp
#include "obs.h"int main() {
obs::signal sig;
sig.connect([](int x, int y){ ... });
sig(1, 2); // Generate signal
}
```Tested Compilers
----------------* Visual Studio 2015
* Xcode 7.3.1 (`-std=c++11`)
* GCC 4.8.4 (`-std=c++11`)