Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

nick2781/observable

Repository files navigation

Observable: Generic observable objects for C++

Did you ever needed to implement the observer pattern and didn't have an easy way to do it? This is for those times.

Quick start

The library is header-only; just copy the include/observable directory into your include path and you're set.

Observable properties (member values):

#include <observable/value.hpp>
using namespace observable;
class WidgetModel
{
public:
 property<std::string, WidgetModel> text;
 void set_text(std::string const & value) { text = value; }
};
WidgetModel widget_model;
auto sub = widget_model.text.subscribe([&](std::string const & new_value) {
 /* Update the widget. */
 });
widget_model.text.subscribe([&]() { /* React to updates */ }).release();
widget_model.set_text("Hello!"); // Calls the lambdas above.

Observable values:

#include <observable/value.hpp>
using namespace observable;
value<std::string> text;
auto sub = text.subscribe([&](std::string const & new_value) {
 /* React to the text change. */
 });
text = "foo"; // Will call the lambda above.

Simple subject:

#include <observable/subject.hpp>
observable::subject<void(double)> subject;
auto subscription = subject.subscribe([](double value) {
 /* Use value */
 });
subject.notify(5.1); // Calls the lambda from above.

Documentation

Documentation Status

The project is documented using Sphinx and the documentation is hosted on Read the Docs <https://readthedocs.org/>.

You can access the documentation here: http://observable.readthedocs.io/en/latest/.

What's with the CMake files?

The library is using CMake to build and run the tests and benchmarks. You won't need CMake if you don't want to run the tests.

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 properties, values and eventually collections for patterns like MVC and reactive programming in general.

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).

What's happening next

  • Observable collections (wrappers around the standard collections).
  • Operations (+, -, /, *, etc.) for observable values (value<int> a; value<int> b; value<int> c = a + b;, where c updates when a or b change).
  • More complex code examples.

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.

Supported compilers

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

The code has been tested with the following compilers:

  • MSVC 14 (Visual Studio 2015)
  • GCC 5.4, 6.2
  • Clang 3.6, 3.7, 3.8, 3.9

Build status

Visual Studio 2015 builds:

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

About

Generic observable objects for C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

  • C++ 88.5%
  • CMake 11.5%

AltStyle によって変換されたページ (->オリジナル) /