Giter VIP home page Giter VIP logo

observable's Introduction

Observable: Generic observable objects for C++

If you want to write code in a reactive style or just implement the observer pattern, this is for you.

Quick start

The library is header-only and has no dependencies; add the observable/include directory to your include path and you're set.

Example:

#include <iostream>
#include <observable/observable.hpp>

using namespace std;
using namespace observable;

int main()
{
    auto sub = subject<void(string)> { };
    sub.subscribe([](auto const & msg) { cout << msg << endl; });

    // "Hello world!" will be printed on stdout.
    sub.notify("Hello world!");

    auto a = value<int> { 5 };
    auto b = value<int> { 5 };
    auto avg = observe(
                    (a + b) / 2.0f
               );
    auto eq_msg = observe(
                    select(a == b, "equal", "not equal")
                   );

    avg.subscribe([](auto val) { cout << val << endl; });
    eq_msg.subscribe([](auto const & msg) { cout << msg << endl; });

    // "10" and "not equal" will be printed on stdout in an
    // unspecified order.
    b = 15;

    return 0;
}

Documentation

You can access the documentation here: https://danieldinu.com/observable/.

What's with the CMake files?

The library is using CMake to build the tests, benchmarks and documentation. You won't need CMake if you don't want to work on the library as a developer.

Why not just use Boost.Signals2 or Qt?

Boost.Signals2 and Qt are pretty cool libraries and do their jobs well.

This library is not meant to replace signals and slots, it focuses more on providing easy to use observable objects and expressions that can help with patterns like MVC and reactive programming.

Choose whichever library works best for your case; you can even choose them both (for example, have your models use this library and your views use Qt).

Contributing

Bug reports, feature requests, documentation and code contributions are welcome and highly appreciated.

Legal and Licensing

The library is licensed under the Apache License version 2.0.

Please note that all contributions are considered to be provided under the terms of this license.

Supported compilers

Any relatively recent compiler with C++14 support should work.

The code has been tested with the following compilers:

  • MSVC 15 (Visual Studio 2017)
  • MSVC 14 (Visual Studio 2015)
  • GCC 5, 6, 7
  • Clang 3.6, 3.8
  • AppleClang 9.1

Build status

Visual Studio 2017 builds:

  • win32 15 build C++14 (32 bit, C++14)
  • win64 15 build C++14 (64 bit, C++14)
  • win32 15 build C++17 (32 bit, C++17)
  • win64 15 build C++17 (64 bit, C++17)

Visual Studio 2015 builds:

  • win32 14 build (32 bit, C++14)
  • win64 14 build (64 bit, C++14)

Linux (GCC, Clang) and OS X (Clang) builds:

  • travis build (64 bit)

observable's People

Contributors

ddinu avatar offa avatar droptix avatar bkuhns avatar giacomocariello avatar

Watchers

James Cloos avatar huanghuanhuangle 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.