diff options
author | Kirk Shoop <kirk.shoop@microsoft.com> | 2015-03-24 09:51:54 -0700 |
---|---|---|
committer | Kirk Shoop <kirk.shoop@microsoft.com> | 2015-03-24 09:51:54 -0700 |
commit | bd97cedb5a11c0666c14efa9d5abb9769480a884 (patch) | |
tree | 5bb827a70abc3cb457954e2e16977fce849289a2 /Rx/v2/examples | |
parent | 0f89328f0b1ce4b1649759d56641593f6877a0a6 (diff) | |
download | RxCpp-bd97cedb5a11c0666c14efa9d5abb9769480a884.tar.gz |
add cep sample
answers #105
Diffstat (limited to 'Rx/v2/examples')
-rw-r--r-- | Rx/v2/examples/cep/CMakeLists.txt | 53 | ||||
-rw-r--r-- | Rx/v2/examples/cep/main.cpp | 43 |
2 files changed, 96 insertions, 0 deletions
diff --git a/Rx/v2/examples/cep/CMakeLists.txt b/Rx/v2/examples/cep/CMakeLists.txt new file mode 100644 index 0000000..c04bead --- /dev/null +++ b/Rx/v2/examples/cep/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 2.8) + +get_filename_component(SAMPLE_PROJECT "${CMAKE_CURRENT_SOURCE_DIR}" NAME) + +project(${SAMPLE_PROJECT}) + +FIND_PACKAGE(Threads) + +MESSAGE( STATUS "CMAKE_CXX_COMPILER_ID: " ${CMAKE_CXX_COMPILER_ID} ) +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + MESSAGE( STATUS "using clang settings" ) + add_compile_options( -Wall -Wextra -Werror ) + add_compile_options( -std=c++11 -stdlib=libc++ ) + add_compile_options( -ftemplate-depth=1024 ) # sometimes you just do what the compiler tells you +elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + MESSAGE( STATUS "using gnu settings" ) + add_compile_options( -Wall -Wextra -Werror ) + add_compile_options( -std=c++11 ) +elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + MESSAGE( STATUS "using msvc settings" ) + add_compile_options( /W4 /WX ) + add_compile_options( /wd4503 ) # truncated symbol + add_compile_options( /wd4702 ) # unreachable code + add_compile_options( /bigobj ) + add_definitions( /DUNICODE /D_UNICODE ) # it is a new millenium +endif() + + +# define some folders +get_filename_component(RXCPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PATH) +get_filename_component(RXCPP_DIR "${RXCPP_DIR}" PATH) +get_filename_component(RXCPP_DIR "${RXCPP_DIR}" PATH) +get_filename_component(RXCPP_DIR "${RXCPP_DIR}" PATH) + +MESSAGE( STATUS "RXCPP_DIR: " ${RXCPP_DIR} ) + +include_directories(SYSTEM ${RXCPP_DIR}/ext/catch/include) +include_directories(${RXCPP_DIR}/Ix/CPP/src ${RXCPP_DIR}/Rx/v2/src) + +# define the sources +set(SAMPLE_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp +) +add_executable(${SAMPLE_PROJECT} ${SAMPLE_SOURCES}) +TARGET_LINK_LIBRARIES(${SAMPLE_PROJECT} ${CMAKE_THREAD_LIBS_INIT}) + +# configure unit tests via CTest +enable_testing() +set(CTEST_CONFIGURATION_TYPE "${JOB_BUILD_CONFIGURATION}") + +add_test(NAME RunTests + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + COMMAND ${SAMPLE_PROJECT} ${TEST_ARGS})
\ No newline at end of file diff --git a/Rx/v2/examples/cep/main.cpp b/Rx/v2/examples/cep/main.cpp new file mode 100644 index 0000000..587595f --- /dev/null +++ b/Rx/v2/examples/cep/main.cpp @@ -0,0 +1,43 @@ + +#include "rxcpp/rx.hpp" +// create alias' to simplify code +// these are owned by the user so that +// conflicts can be managed by the user. +namespace rx=rxcpp; +namespace rxsub=rxcpp::subjects; +namespace rxu=rxcpp::util; + +#include <cctype> +#include <clocale> + +// At this time, RxCpp will fail to compile if the contents +// of the std namespace are merged into the global namespace +// DO NOT USE: 'using namespace std;' + +int main() +{ + auto keys = rx::observable<>::create<int>( + [](rx::subscriber<int> dest){ + for (;;) { + int key = std::cin.get(); + dest.on_next(key); + } + }). + publish(); + + auto a = keys. + filter([](int key){return std::tolower(key) == 'a';}); + + auto g = keys. + filter([](int key){return std::tolower(key) == 'g';}); + + a.merge(g). + subscribe([](int key){ + std::cout << key << std::endl; + }); + + // run the loop in create + keys.connect(); + + return 0; +} |