commit | 4aa52e42579cbd9e2cef6c0a6c2b0d8edf73ac5d | [log] [tgz] |
---|---|---|
author | iam <igor.murashkin+github@gmail.com> | Sat Oct 27 13:12:45 2018 -0700 |
committer | Kirk Shoop <kirk.shoop@gmail.com> | Sat Oct 27 13:12:45 2018 -0700 |
tree | 2b4a574fcd4a62d8b59174646b76c53fa9c15b2d | |
parent | ed3fe6418276781e662e5113ee3cee1bee4f0998 [diff] |
Add support for compiling rxcpp with -fno-exceptions (#456) * Minor compilation/test fixes for compiling on android Change-Id: Id623455d32e9323355744a240c2813d0411d1dac * Rx: Add support for compiling code without exceptions (-fno-exceptions) std::exception_ptr usage is replaced with rxcpp::util::error_ptr which will typedef to std::exception_ptr when exceptions are enabled. When exceptions are disabled this will typedef to an internal error type that can retain the "what" error message. Additionally std::current_exception() and similar usages are replaced with rxu::current_exception which uses error_ptr instead. Lastly all try/catch/throw keywords are replaced with either RXCPP_TRY, RXCPP_CATCH, rxu::throw_exception or similar. Note that try/catch/throw keywords cause a compilation error with -fno-exceptions. Trying to access most of the std::*exception* functions will call std::terminate at runtime. Tests using exceptions must be disabled by passing --nothrow to the check2 test runner. Change-Id: I0b95ae2e323653a17c3b733d165ecf87a014c315 * update to catch2 and add RX_USE_EXCEPTIONS cmake option * fix bugs in doxygen examples * replace [[noreturn]] with RXCPP_NORETURN * removes support for VS 2013
The Reactive Extensions for C++ (RxCpp) is a library of algorithms for values-distributed-in-time. The Range-v3 library does the same for values-distributed-in-space.
Platform | Status | ----------- | :------------ | Windows | Linux & OSX |
Source | Badges |
---|---|
Github | |
Gitter.im | |
Packages | |
Documentation |
RxCpp is a header-only C++ library that only depends on the standard library. The CMake build generates documentation and unit tests. The unit tests depend on a git submodule for the Catch library.
Add Rx/v2/src
to the include paths
#include "rxcpp/rx.hpp" namespace Rx { using namespace rxcpp; using namespace rxcpp::sources; using namespace rxcpp::operators; using namespace rxcpp::util; } using namespace Rx; #include <regex> #include <random> using namespace std; using namespace std::chrono; 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(0, 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 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 // auto removespaces = [](string s){ s.erase(remove_if(s.begin(), s.end(), ::isspace), s.end()); return s; }; // create strings split on \r auto strings = bytes | concat_map([](vector<uint8_t> v){ string s(v.begin(), v.end()); regex delim(R"/(\r)/"); cregex_token_iterator cursor(&s[0], &s[0] + s.size(), delim, {-1, 0}); cregex_token_iterator end; vector<string> splits(cursor, end); return iterate(move(splits)); }) | filter([](const string& s){ return !s.empty(); }) | publish() | ref_count(); // filter to last string in each line auto closes = strings | filter( [](const string& s){ return s.back() == '\r'; }) | Rx::map([](const string&){return 0;}); // group strings by line auto linewindows = strings | window_toggle(closes | start_with(0), [=](int){return closes;}); // reduce the strings for a line into one string auto lines = linewindows | flat_map([&](observable<string> w) { return w | start_with<string>("") | sum() | Rx::map(removespaces); }); // print result lines | subscribe<string>(println(cout)); return 0; }
The ReactiveX Observable model allows you to treat streams of asynchronous events with the same sort of simple, composable operations that you use for collections of data items like arrays. It frees you from tangled webs of callbacks, and thereby makes your code more readable and less prone to bugs.
Credit ReactiveX.io
RxCpp uses a git submodule (in ext/catch
) for the excellent Catch library. The easiest way to ensure that the submodules are included in the clone is to add --recursive
in the clone command.
git clone --recursive https://github.com/ReactiveX/RxCpp.git cd RxCpp
RxCpp uses CMake to create build files for several platforms and IDE's
mkdir projects/build cd projects/build cmake -G"Xcode" ../CMake -B.
mkdir projects\build cd projects\build cmake -G "Visual Studio 15" ..\CMake\ msbuild Project.sln
mkdir projects/build cd projects/build cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -B. ../CMake make
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
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
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.
ctest
rxcpp_test_*
rxcpp_test_subscription [perf]
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.
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.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.