The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in C++.
#Example
Add Rx/v2/src
to the include paths
#include "rxcpp/rx.hpp"
using namespace rxcpp;
using namespace rxcpp::sources;
using namespace rxcpp::operators;
using namespace rxcpp::util;
#include <regex>
#include <random>
using namespace std;
int main()
{
random_device rd; // non-deterministic generator
mt19937 gen(rd());
uniform_int_distribution<> dist(4, 18);
// for testing purposes, produce byte stream that from lines of text
auto bytes = range(1, 10) |
flat_map([&](int i){
auto body = from((uint8_t)('A' + i)) |
repeat(dist(gen)) |
as_dynamic();
auto delim = from((uint8_t)'\r');
return from(body, delim) | concat();
}) |
window(17) |
flat_map([](observable<uint8_t> w){
return w |
reduce(
vector<uint8_t>(),
[](vector<uint8_t>& v, uint8_t b){
v.push_back(b);
return move(v);
}) |
as_dynamic();
}) |
tap([](vector<uint8_t>& v){
// print input packet of bytes
copy(v.begin(), v.end(), ostream_iterator<long>(cout, " "));
cout << endl;
});
//
// recover lines of text from byte stream
//
// create strings split on \r
auto strings = bytes |
concat_map([](vector<uint8_t> v){
string s(v.begin(), v.end());
regex delim(R"/(\r)/");
sregex_token_iterator cursor(s.begin(), s.end(), delim, {-1, 0});
sregex_token_iterator end;
vector<string> splits(cursor, end);
return iterate(move(splits));
}) |
filter([](string& s){
return !s.empty();
});
// group strings by line
int group = 0;
auto linewindows = strings |
group_by(
[=](string& s) mutable {
return s.back() == '\r' ? group++ : group;
});
// reduce the strings for a line into one string
auto lines = linewindows |
flat_map([](grouped_observable<int, string> w){
return w | sum();
});
// print result
lines |
subscribe<string>(println(cout));
return 0;
}
- Rx.NET: The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators.
- RxJS: The Reactive Extensions for JavaScript (RxJS) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in JavaScript which can target both the browser and Node.js.
- RxCpp: The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C++.
#Building RxCpp
- RxCpp is regularly tested on OSX and Windows.
- RxCpp is regularly built with Clang, Gcc and VC
- RxCpp depends on the latest compiler releases.
RxCpp uses CMake to create build files for several platforms and IDE's
###ide builds
####XCode
mkdir projects/build
cd projects/build
cmake -G"Xcode" ../CMake -B.
####Visual Studio 13
mkdir projects\build
cd projects\build
cmake -G"Visual Studio 12" ..\CMake -B.
- Note: open in VC2013 and upgrade to the 2013 toolset
###makefile builds
####OSX
mkdir projects/build
cd projects/build
cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -B. ../CMake
make
####Linux --- Clang
mkdir projects/build
cd projects/build
cmake -G"Unix Makefiles" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -B. ../CMake
make
####Linux --- GCC
mkdir projects/build
cd projects/build
cmake -G"Unix Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -B. ../CMake
make
####Windows
mkdir projects\build
cd projects\build
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -B. ..\CMake
nmake
The build only produces test and example binaries.
#Running tests
- You can use the CMake test runner
ctest
- You can run the test binaries directly
rxcppv2_test_*
- Tests can be selected by name or tag Example of by-tag
rxcppv2_test_subscription [perf]
#Documentation
RxCpp uses Doxygen to generate project documentation.
When Doxygen+Graphviz is installed, CMake creates a special build task named doc
. It creates actual documentation and puts it to projects/doxygen/html/
folder, which can be published to the gh-pages
branch. Each merged pull request will build the docs and publish them.
#Contributing Code
Before submitting a feature or substantial code contribution please discuss it with the team and ensure it follows the product roadmap. Note that all code submissions will be rigorously reviewed and tested by the Rx Team, and only those that meet an extremely high bar for both quality and design/roadmap appropriateness will be merged into the source.
You will be promted to submit a Contributor License Agreement form after submitting your pull request. This needs to only be done once for any Microsoft OSS project. Fill in the Contributor License Agreement (CLA).