GithubHelp home page GithubHelp logo

ik3210 / observable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dacap/observable

0.0 3.0 0.0 21 KB

Observer pattern and signals/slots for C++11 projects

License: MIT License

CMake 3.33% C 1.09% C++ 95.58%

observable's Introduction

Observable Library

Copyright (C) 2016 David Capello

Build Status MIT Licensed

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 notification

Observable

An observable Widget:

#include "obs.h"

class WidgetObserver {
public:
  virtual ~WidgetObserver() = 0;
  virtual void onClick() { }
};

class Widget : public obs::observable<WidgetObserver> {
public:
  void processClick() {
    notify_observers(&WidgetObserver::onClick);
  }
};

An example

#include "obs.h"

class ObserveClick : public WidgetObserver {
public:
  void onClick() override {
    // Do something...
  }
};

...
ObserveClick observer;
Widget button;
button.add_observer(&observer);

Signal

#include "obs.h"

int main() {
  obs::signal<void (int, int)> 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)

observable's People

Contributors

dacap avatar

Watchers

ik3210 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.