Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
obs/ | H | 20-Jul-2018 | - | |||
tests/ | H | 03-May-2022 | - | |||
.appveyor.yml | H A D | 20-Jul-2018 | 893 | |||
.travis.yml | H A D | 20-Jul-2018 | 1.5 KiB | |||
README.md | H A D | 20-Jul-2018 | 1.6 KiB | |||
obs.h | H A D | 20-Jul-2018 | 334 |
README.md
1Observable Library 2================== 3 4*Copyright (C) 2016-2018 David Capello* 5 6[![Build Status](https://travis-ci.org/dacap/observable.svg)](https://travis-ci.org/dacap/observable) 7[![Build status](https://ci.appveyor.com/api/projects/status/jcur6dbi1vw6hrbw?svg=true)](https://ci.appveyor.com/project/dacap/observable) 8[![MIT Licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt) 9 10Library to use the observer pattern in C++11 programs with 11observable/observer classes or signals/slots. 12 13Features 14-------- 15 16* Generate an observable notification/signal from multiple threads 17* Add/remove observers/slots from multiple threads 18* Erase/disconnect an observer/slot from the same observable notification/signal 19* Reconnect an observer in the same notification 20 21Observable 22---------- 23 24An observable `Widget`: 25 26```cpp 27#include "obs.h" 28 29class WidgetObserver { 30public: 31 virtual ~WidgetObserver() = 0; 32 virtual void onClick() { } 33}; 34 35class Widget : public obs::observable<WidgetObserver> { 36public: 37 void processClick() { 38 notify_observers(&WidgetObserver::onClick); 39 } 40}; 41``` 42 43An example 44 45```cpp 46#include "obs.h" 47 48class ObserveClick : public WidgetObserver { 49public: 50 void onClick() override { 51 // Do something... 52 } 53}; 54 55... 56ObserveClick observer; 57Widget button; 58button.add_observer(&observer); 59``` 60 61Signal 62------ 63 64```cpp 65#include "obs.h" 66 67int main() { 68 obs::signal<void (int, int)> sig; 69 sig.connect([](int x, int y){ ... }); 70 sig(1, 2); // Generate signal 71} 72``` 73 74Tested Compilers 75---------------- 76 77* Visual Studio 2015 78* Xcode 7.3.1 (`-std=c++11`) 79* GCC 4.8.4 (`-std=c++11`) 80