Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
Live Cells C++

Live Cells is a reactive programming library for C++ ported from Live Cells for Dart.

Features

Declarative

  • A declarative reactive programming library for C++
  • Define cells for your data
  • Express complex logic as functions of cells
// Define cells
// Define a function of a cell
auto sum = live_cells::computed([=] {
return a() + b();
});
auto computed(F &&compute)
Create a cell with a value that is a function of one or more argument cells.
Definition computed.hpp:45
mutable_cell< T > variable(T value)
Create a new mutable cell with an initial value.
Definition mutable_cell.hpp:276

Reactive

  • Define observers on your cells
  • Observers called automatically when cell values change
  • Observers are self-subscribing
  • React to any event or data change with minimal boilerplate
auto watcher = live_cells::watch([=] {
if (sum() > 100) {
std::cout << "Sum exceeded 100!!\\n";
}
});
a = 20;
b = 90; // Prints: Sum exceeded 100!!!
std::shared_ptr< watcher > watch(F fn)
Register a cell watch function.
Definition watcher.hpp:212

Simple, powerful and maintainable

  • You only need to learn one basic building block — the cell
  • No need to worry about adding and removing event listeners or callbacks
  • No need to implement complicated interfaces or subclasses
  • Powerful enough to express any application logic
  • Express your application logic without it buried in layers of event handling and state synchronization code
auto a = live_cells::variable(...);
auto b = live_cells::computed(...);
auto w = live_cells::watch(...);
// That's all you have to learn

Getting Started

Attention
This software is still in the beta phase and may experience rapid and drastic changes between releases.

Prerequisites

This library requires the following:

  • A compiler that supports C++20.

The following dependencies are not required to use the library, but are required for running the unit tests.

Installation

To begin using Live Cells:

  1. Download the latest release.
  2. Unpack the tar archive to a directory of your choice.
  3. Install the library by running the following commands in the directory where you unpacked the tar archive:

    mkdir build; cd build
    ../configure
    make install

    This will install Live Cells at /usr/local. You can choose an alternative prefix with:

    ../configure --prefix=/path/to/prefix

Live Cells should now be installed at /usr/local or the prefix you've given to configure.

Configuring your project

The Live Cells library consists of headers, installed in <prefix>/include/live_cells, and a static library liblive_cells.a installed in <prefix>/lib.

Note
<prefix> is /usr/local, unless specified otherwise with the --prefix argument to the configure script.

To use live cells in your C++ project, you'll need to do the following:

  1. Add <prefix>/include/live_cells to your include path.
  2. Link <prefix>/lib/liblive_cells.a into your compiled binary

Autotools

Add the following to your configure.ac:

AC_LIB_HAVE_LINKFLAGS(live_cells)

This searches for the liblive_cells.a in the default library search paths (or the paths specified by the user), adds the necessary linker options to the variable LIBLIVE_CELLS and adds directory where the header files were installed, to the project's include path.

Add the following to your Makefile.am

target_LDADD = $(LIBLIVE_CELLS)

where target is the name of your compilation target.

CMake

Add the following to your CMakeLists.txt file:

list(APPEND CMAKE_MODULE_PATH "<prefix>/share/live_cells/cmake")
find_package(live_cells REQUIRED)
Note
Substitute <prefix> with the install prefix given to the configure script.

Add ${LIVE_CELLS_LIBRARY} to your compilation target with the following:

target_link_libraries(<target> PRIVATE ${LIVE_CELLS_LIBRARY})
Note
Substitute <target> with your compilation target

Using Live Cells

Now that your project is set up, all you need to do is include the live_cells.hpp header file:

#include <live_cells/live_cells.hpp>
...

You're all set to start following the introductory tutorial.