From fef6d1cf126e6b1011f6bf9a67de94ae1651223f Mon Sep 17 00:00:00 2001 From: Ivan Le Lann Date: Tue, 24 May 2016 22:11:12 +0200 Subject: [PATCH 1/3] cleanups --- CMakeLists.txt | 10 +- benchmarks/CMakeLists.txt | 2 + benchmarks/src/BenchmarkBase.h | 4 +- benchmarks/src/BenchmarkRandom.h | 26 +-- benchmarks/src/Main.cpp | 111 ++++++---- examples/src/BasicReactors.cpp | 8 +- include/react/common/Concurrency.h | 96 +------- include/react/common/Containers.h | 4 +- include/react/common/SourceIdSet.h | 135 ------------ include/react/common/Timing.h | 31 +-- include/react/common/TopoQueue.h | 60 ++--- include/react/common/Types.h | 5 +- include/react/detail/graph/GraphBase.h | 9 +- include/react/detail/graph/ObserverNodes.h | 6 +- include/react/detail/graph/ReactorNodes.h | 4 +- project/msvc/CppReact.sln | 149 ------------- project/msvc/CppReact.vcxproj | 206 ------------------ project/msvc/CppReact.vcxproj.filters | 171 --------------- project/msvc/CppReactBenchmark.vcxproj | 166 -------------- .../msvc/CppReactBenchmark.vcxproj.filters | 42 ---- project/msvc/CppReactExample.vcxproj | 162 -------------- project/msvc/CppReactExample.vcxproj.filters | 22 -- project/msvc/CppReactTest.vcxproj | 195 ----------------- project/msvc/CppReactTest.vcxproj.filters | 78 ------- project/msvc/Example_BasicAlgorithms.vcxproj | 150 ------------- .../Example_BasicAlgorithms.vcxproj.filters | 22 -- project/msvc/Example_BasicComposition.vcxproj | 150 ------------- .../Example_BasicComposition.vcxproj.filters | 22 -- project/msvc/Example_BasicEvents.vcxproj | 150 ------------- .../msvc/Example_BasicEvents.vcxproj.filters | 22 -- project/msvc/Example_BasicObservers.vcxproj | 150 ------------- .../Example_BasicObservers.vcxproj.filters | 22 -- project/msvc/Example_BasicReactors.vcxproj | 150 ------------- .../Example_BasicReactors.vcxproj.filters | 22 -- project/msvc/Example_BasicSignals.vcxproj | 150 ------------- .../msvc/Example_BasicSignals.vcxproj.filters | 22 -- .../msvc/Example_BasicSynchronization.vcxproj | 151 ------------- ...ample_BasicSynchronization.vcxproj.filters | 22 -- tests/CMakeLists.txt | 47 ++-- tests/src/OperationsTest.h | 10 +- tests/src/TransactionTest.cpp | 2 +- 41 files changed, 172 insertions(+), 2794 deletions(-) delete mode 100644 include/react/common/SourceIdSet.h delete mode 100644 project/msvc/CppReact.sln delete mode 100644 project/msvc/CppReact.vcxproj delete mode 100644 project/msvc/CppReact.vcxproj.filters delete mode 100644 project/msvc/CppReactBenchmark.vcxproj delete mode 100644 project/msvc/CppReactBenchmark.vcxproj.filters delete mode 100644 project/msvc/CppReactExample.vcxproj delete mode 100644 project/msvc/CppReactExample.vcxproj.filters delete mode 100644 project/msvc/CppReactTest.vcxproj delete mode 100644 project/msvc/CppReactTest.vcxproj.filters delete mode 100644 project/msvc/Example_BasicAlgorithms.vcxproj delete mode 100644 project/msvc/Example_BasicAlgorithms.vcxproj.filters delete mode 100644 project/msvc/Example_BasicComposition.vcxproj delete mode 100644 project/msvc/Example_BasicComposition.vcxproj.filters delete mode 100644 project/msvc/Example_BasicEvents.vcxproj delete mode 100644 project/msvc/Example_BasicEvents.vcxproj.filters delete mode 100644 project/msvc/Example_BasicObservers.vcxproj delete mode 100644 project/msvc/Example_BasicObservers.vcxproj.filters delete mode 100644 project/msvc/Example_BasicReactors.vcxproj delete mode 100644 project/msvc/Example_BasicReactors.vcxproj.filters delete mode 100644 project/msvc/Example_BasicSignals.vcxproj delete mode 100644 project/msvc/Example_BasicSignals.vcxproj.filters delete mode 100644 project/msvc/Example_BasicSynchronization.vcxproj delete mode 100644 project/msvc/Example_BasicSynchronization.vcxproj.filters diff --git a/CMakeLists.txt b/CMakeLists.txt index ae21be06..7929a3a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ ### Configuration cmake_minimum_required (VERSION 2.6) +enable_testing() project (CppReact) @@ -12,12 +13,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wpedantic") include_directories ("${PROJECT_SOURCE_DIR}/include") ### CppReact +file(GLOB_RECURSE CPPREACT_HEADERS include/*.h) + add_library(CppReact src/engine/PulsecountEngine.cpp src/engine/SubtreeEngine.cpp src/engine/ToposortEngine.cpp src/logging/EventLog.cpp - src/logging/EventRecords.cpp) + src/logging/EventRecords.cpp + ${CPPREACT_HEADERS}) target_link_libraries(CppReact tbb) @@ -28,13 +32,13 @@ if(build_examples) endif() ### benchmarks/ -option(build_benchmarks "Build benchmarks?" OFF) +option(build_benchmarks "Build benchmarks?" ON) if(build_benchmarks) add_subdirectory(benchmarks) endif() ### tests/ -option(build_tests "Build unit tests?" OFF) +option(build_tests "Build unit tests?" ON) if(build_tests) add_subdirectory(tests) endif() diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index b74640e9..773926a3 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -2,3 +2,5 @@ add_executable(CppReactBenchmark src/Main.cpp) target_link_libraries(CppReactBenchmark CppReact tbbmalloc_proxy) + +add_test(NAME CppReactBenchmark COMMAND CppReactBenchmark "-r" CONFIGURATIONS Benchmark) diff --git a/benchmarks/src/BenchmarkBase.h b/benchmarks/src/BenchmarkBase.h index deaaf931..48a95aa3 100644 --- a/benchmarks/src/BenchmarkBase.h +++ b/benchmarks/src/BenchmarkBase.h @@ -20,14 +20,14 @@ // Get unique random numbers from range. /////////////////////////////////////////////////////////////////////////////////////////////////// template -const std::vector GetUniqueRandomNumbers(TGen gen, T from, T to, int count) +const std::vector GetUniqueRandomNumbers(TGen gen, T from, T to, T count) { std::vector data(1 + to - from); int c = from; for (auto& p : data) p = c++; - for (int i=0; i dist(i,(to - from)); auto r = dist(gen); diff --git a/benchmarks/src/BenchmarkRandom.h b/benchmarks/src/BenchmarkRandom.h index 63cbd996..3ba59484 100644 --- a/benchmarks/src/BenchmarkRandom.h +++ b/benchmarks/src/BenchmarkRandom.h @@ -53,14 +53,14 @@ class RandomGraphGenerator Func3T Function3; Func4T Function4; - int Width = 1; - int Height = 1; + unsigned int Width = 1; + unsigned int Height = 1; - int SelectSlowCount = 0; - int SelectEdgeCount = 0; + unsigned int SelectSlowCount = 0; + unsigned int SelectEdgeCount = 0; - int EdgeSeed; - int SlowSeed; + unsigned int EdgeSeed; + unsigned int SlowSeed; void Generate() { @@ -76,7 +76,7 @@ class RandomGraphGenerator Func3T f3Fast = [this] (TValue a1, TValue a2, TValue a3) { FastDelayFunc(); return Function3(a1,a2,a3); }; Func4T f4Fast = [this] (TValue a1, TValue a2, TValue a3, TValue a4) { FastDelayFunc(); return Function4(a1,a2,a3,a4); }; - int nodeCount = Width * Height; + auto nodeCount = Width * Height; std::mt19937 edgeGen(EdgeSeed); const auto edgeNodes = GetUniqueRandomNumbers(edgeGen, Width, nodeCount - 1, SelectEdgeCount); @@ -90,17 +90,17 @@ class RandomGraphGenerator auto edgeNodeIt = edgeNodes.begin(); auto slowNodeIt = slowNodes.begin(); - auto cur = 0; + unsigned cur = 0; HandleVect nodes(nodeCount); - for (int w=0; w nodeDist(0, Width*h - 1); - for (int w=0; w return d; } -}; \ No newline at end of file +}; diff --git a/benchmarks/src/Main.cpp b/benchmarks/src/Main.cpp index eb47f33f..4c62ae8c 100644 --- a/benchmarks/src/Main.cpp +++ b/benchmarks/src/Main.cpp @@ -81,14 +81,14 @@ void runBenchmarkRandom(std::ostream& out) void runBenchmarkFanout(std::ostream& out) { - //RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(10, 10000, 0), - // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain); + RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(10, 10000, 0), + ToposortSTDomain, ToposortDomain, PulsecountDomain); - //RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(100, 10000, 0), - // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain); + RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(100, 10000, 0), + ToposortSTDomain, ToposortDomain, PulsecountDomain); - //RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(1000, 10000, 0), - // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain); + RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(1000, 10000, 0), + ToposortSTDomain, ToposortDomain, PulsecountDomain); RUN_BENCHMARK(out, 3, Benchmark_Fanout, BenchmarkParams_Fanout(10, 10, 10), ToposortSTDomain, ToposortDomain, PulsecountDomain); @@ -100,41 +100,41 @@ void runBenchmarkFanout(std::ostream& out) ToposortSTDomain, ToposortDomain, PulsecountDomain); } -void runBenchmarkSequence(std::ostream& out) -{ - //RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(10, 10000, 0), - // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain); +//void runBenchmarkSequence(std::ostream& out) +//{ +// //RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(10, 10000, 0), +// // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain); - //RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(100, 10000, 0), - // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain); +// //RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(100, 10000, 0), +// // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain); - //RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(1000, 10000, 0), - // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain); +// //RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(1000, 10000, 0), +// // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain); - RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(10, 10, 10), - ToposortSTDomain, ToposortDomain, PulsecountDomain); +// RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(10, 10, 10), +// ToposortSTDomain, ToposortDomain, PulsecountDomain); - RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(100, 10, 10), - ToposortSTDomain, ToposortDomain, PulsecountDomain); +// RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(100, 10, 10), +// ToposortSTDomain, ToposortDomain, PulsecountDomain); - RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(1000, 10, 10), - ToposortSTDomain, ToposortDomain, PulsecountDomain); -} +// RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(1000, 10, 10), +// ToposortSTDomain, ToposortDomain, PulsecountDomain); +//} -void runBenchmarkLifeSim(std::ostream& out) -{ - //RUN_BENCHMARK(std::cout, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(150, 1000), - // ELMDomain); +//void runBenchmarkLifeSim(std::ostream& out) +//{ +// //RUN_BENCHMARK(std::cout, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(150, 10, 1000), +// // ToposortDomain); - //RUN_BENCHMARK(std::cout, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(250, 30, 10000), - // SourceSetDomain, PulsecountDomain); +// //RUN_BENCHMARK(std::cout, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(250, 30, 10000), +// // SourceSetDomain, PulsecountDomain); - RUN_BENCHMARK(out, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(100, 15, 10000), - ToposortSTDomain, ToposortDomain, PulsecountDomain); +// //RUN_BENCHMARK(out, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(100, 15, 10000), +// //ToposortSTDomain, ToposortDomain, PulsecountDomain); - //RUN_BENCHMARK(out, 3, Benchmark_LifeSim, BenchmarkParams_LifeSim(100, 50, 100), - // PulsecountDomain, PulsecountDomain); -} +// //RUN_BENCHMARK(out, 3, Benchmark_LifeSim, BenchmarkParams_LifeSim(100, 50, 100), +// // PulsecountDomain, PulsecountDomain); +//} void runBenchmarks() { @@ -144,21 +144,21 @@ void runBenchmarks() logfile.open(path.c_str()); // === GRID - //runBenchmarkGrid(logfile); - - //runBenchmarkFlooding(logfile); + runBenchmarkGrid(logfile); // === RANDOM - //runBenchmarkRandom(logfile); + if (0) + runBenchmarkRandom(logfile); // === FANOUT - //runBenchmarkFanout(logfile); + if (0) + runBenchmarkFanout(logfile); // === SEQUENCE //runBenchmarkSequence(logfile); // === LIFESIM - runBenchmarkLifeSim(logfile); + //runBenchmarkLifeSim(logfile); logfile.close(); } @@ -233,9 +233,34 @@ void profileBenchmark() } // ~anonymous namespace -int main() +#include + +int main(int argc, char * argv[]) { - //runBenchmarks(); - //debugBenchmarks(); - profileBenchmark(); -} \ No newline at end of file + auto begin = argv; + auto end = argv + argc; + +// auto getCmdOption = [&](const std::string & option) -> char* +// { +// char ** itr = std::find(begin, end, option); +// if (itr != end && ++itr != end) +// { +// return *itr; +// } +// return 0; +// }; + + auto cmdOptionExists = [&](const std::string& option) -> bool + { + return std::find(begin, end, option) != end; + }; + + std::cout << "-d to debug, -p to profile. run by default" << std::endl; + + if (cmdOptionExists("-d")) + debugBenchmarks(); + else if (cmdOptionExists("-p")) + profileBenchmark(); + else + runBenchmarks(); +} diff --git a/examples/src/BasicReactors.cpp b/examples/src/BasicReactors.cpp index 1e30cc1c..56fd09a5 100644 --- a/examples/src/BasicReactors.cpp +++ b/examples/src/BasicReactors.cpp @@ -35,7 +35,7 @@ namespace example1 ReactorT loop { - [&] (ReactorT::Context ctx) + [] (ReactorT::Context ctx) { PathT points; @@ -101,13 +101,13 @@ namespace example2 ReactorT loop { - [&] (ReactorT::Context ctx) + [] (ReactorT::Context ctx) { PathT points; points.emplace_back(ctx.Await(mouseDown)); - auto count = ctx.Get(counter); + ctx.Get(counter); ctx.RepeatUntil(mouseUp, [&] { points.emplace_back(ctx.Await(mouseMove)); @@ -158,4 +158,4 @@ int main() example2::Run(); return 0; -} \ No newline at end of file +} diff --git a/include/react/common/Concurrency.h b/include/react/common/Concurrency.h index e27fd9ba..9065f9c0 100644 --- a/include/react/common/Concurrency.h +++ b/include/react/common/Concurrency.h @@ -76,19 +76,6 @@ class WaitingStateBase : public IWaitingState }// ~mutex_ } - inline bool IsWaiting() - {// mutex_ - std::lock_guard scopedLock(mutex_); - return isWaiting_; - }// ~mutex_ - - template - auto Run(F&& func) -> decltype(func(false)) - {// mutex_ - std::lock_guard scopedLock(mutex_); - return func(isWaiting_); - }// ~mutex_ - template bool RunIfWaiting(F&& func) {// mutex_ @@ -101,18 +88,6 @@ class WaitingStateBase : public IWaitingState return true; }// ~mutex_ - template - bool RunIfNotWaiting(F&& func) - {// mutex_ - std::lock_guard scopedLock(mutex_); - - if (isWaiting_) - return false; - - func(); - return true; - }// ~mutex_ - private: std::atomic waitCount_{ 0 }; std::condition_variable condition_; @@ -221,75 +196,6 @@ class SharedWaitingStateCollection : public IWaitingState std::vector others_; }; -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// BlockingCondition -/////////////////////////////////////////////////////////////////////////////////////////////////// -class BlockingCondition -{ -public: - inline void Block() - {// mutex_ - std::lock_guard scopedLock(mutex_); - blocked_ = true; - }// ~mutex_ - - inline void Unblock() - {// mutex_ - std::lock_guard scopedLock(mutex_); - blocked_ = false; - condition_.notify_all(); - }// ~mutex_ - - inline void WaitForUnblock() - { - std::unique_lock lock(mutex_); - condition_.wait(lock, [this] { return !blocked_; }); - } - - inline bool IsBlocked() - {// mutex_ - std::lock_guard scopedLock(mutex_); - return blocked_; - }// ~mutex_ - - template - auto Run(F&& func) -> decltype(func(false)) - {// mutex_ - std::lock_guard scopedLock(mutex_); - return func(blocked_); - }// ~mutex_ - - template - bool RunIfBlocked(F&& func) - {// mutex_ - std::lock_guard scopedLock(mutex_); - - if (!blocked_) - return false; - - func(); - return true; - }// ~mutex_ - - template - bool RunIfUnblocked(F&& func) - {// mutex_ - std::lock_guard scopedLock(mutex_); - - if (blocked_) - return false; - - func(); - return true; - }// ~mutex_ - -private: - std::mutex mutex_; - std::condition_variable condition_; - - bool blocked_ = false; -}; - /////////////////////////////////////////////////////////////////////////////////////////////////// /// ConditionalCriticalSection /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -321,4 +227,4 @@ class ConditionalCriticalSection /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_COMMON_CONCURRENCY_H_INCLUDED \ No newline at end of file +#endif // REACT_COMMON_CONCURRENCY_H_INCLUDED diff --git a/include/react/common/Containers.h b/include/react/common/Containers.h index 9b77de06..1064b1b0 100644 --- a/include/react/common/Containers.h +++ b/include/react/common/Containers.h @@ -117,7 +117,7 @@ class NodeBuffer front_( nodes_.begin() ), back_( nodes_.begin() ) { - for (auto i=0; i -#include - -#include "tbb/queuing_mutex.h" - -/***************************************/ REACT_IMPL_BEGIN /**************************************/ - -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// SourceIdSet -/////////////////////////////////////////////////////////////////////////////////////////////////// -template -class SourceIdSet -{ -private: - using MutexT = tbb::queuing_mutex; - using DataT = std::vector; - -public: - void Insert(const T& e) - { - MutexT::scoped_lock lock(mutex_); - - data_.push_back(e); - - isSorted_ = false; - } - - void Insert(SourceIdSet& other) - { - MutexT::scoped_lock myLock(mutex_); - MutexT::scoped_lock otherLock(other.mutex_); - - sort(); - other.sort(); - - auto l = data_.begin(); - auto r = data_.end(); - auto offset = std::distance(l,r); - - // For each element in other, check if it's already contained in this - // if not, add it - for (const auto& e : other.data_) - { - l = std::lower_bound(l, r, e); - - // Already in the set? - if (l < r && *l == e) - continue; - - auto d = std::distance(data_.begin(), l); - - data_.push_back(e); - - // push_back invalidates iterators - l = data_.begin() + d; - r = data_.begin() + offset; - } - - std::inplace_merge(data_.begin(), data_.begin() + offset, data_.end()); - } - - void Erase(const T& e) - { - MutexT::scoped_lock lock(mutex_); - - data_.erase(std::find(data_.begin(), data_.end(), e)); - } - - void Clear() - { - MutexT::scoped_lock lock(mutex_); - - data_.clear(); - isSorted_ = true; - } - - bool IntersectsWith(SourceIdSet& other) - { - MutexT::scoped_lock myLock(mutex_); - MutexT::scoped_lock otherLock(other.mutex_); - - sort(); - other.sort(); - - auto l1 = data_.begin(); - const auto r1 = data_.end(); - - auto l2 = other.data_.begin(); - const auto r2 = other.data_.end(); - - // Is intersection of turn sourceIds and node sourceIds non-empty? - while (l1 != r1 && l2 != r2) - { - if (*l1 < *l2) - l1++; - else if (*l2 < *l1) - l2++; - // Equals => Intersect - else - return true; - } - return false; - } - -private: - MutexT mutex_; - DataT data_; - bool isSorted_ = false; - - void sort() - { - if (isSorted_) - return; - - std::sort(data_.begin(), data_.end()); - isSorted_ = true; - } -}; - -/****************************************/ REACT_IMPL_END /***************************************/ - -#endif // REACT_COMMON_SOURCEIDSET_H_INCLUDED \ No newline at end of file diff --git a/include/react/common/Timing.h b/include/react/common/Timing.h index 3775661d..9440ceaa 100644 --- a/include/react/common/Timing.h +++ b/include/react/common/Timing.h @@ -52,29 +52,15 @@ inline const LARGE_INTEGER& GetPerformanceFrequency() /////////////////////////////////////////////////////////////////////////////////////////////////// template < - long long threshold, + std::chrono::microseconds::rep threshold, bool is_enabled > -class ConditionalTimer -{ -public: - class ScopedTimer - { - public: - // Note: - // Count is passed by ref so it can be set later if it's not known at time of creation - ScopedTimer(const ConditionalTimer&, const size_t& count); - }; - - void Reset(); - void ForceThresholdExceeded(bool isExceeded); - bool IsThresholdExceeded() const; -}; +class ConditionalTimer; // Disabled template < - long long threshold + std::chrono::microseconds::rep threshold > class ConditionalTimer { @@ -83,18 +69,18 @@ class ConditionalTimer class ScopedTimer { public: - ScopedTimer(const ConditionalTimer&, const size_t& count) {} + ScopedTimer(const ConditionalTimer&, const size_t&) {} }; void Reset() {} - void ForceThresholdExceeded(bool isExceeded) {} + void ForceThresholdExceeded(bool) {} bool IsThresholdExceeded() const { return false; } }; // Enabled template < - long long threshold + std::chrono::microseconds::rep threshold > class ConditionalTimer { @@ -103,6 +89,7 @@ class ConditionalTimer using TimestampT = LARGE_INTEGER; #else using ClockT = std::chrono::high_resolution_clock; + using RepT = ClockT::duration::rep; using TimestampT = std::chrono::time_point; #endif @@ -158,7 +145,7 @@ class ConditionalTimer ConditionalTimer& parent_; TimestampT startTime_; - const size_t& count_; + const std::chrono::microseconds::rep& count_; }; static TimestampT now() @@ -198,4 +185,4 @@ class ConditionalTimer /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_COMMON_TIMING_H_INCLUDED \ No newline at end of file +#endif // REACT_COMMON_TIMING_H_INCLUDED diff --git a/include/react/common/TopoQueue.h b/include/react/common/TopoQueue.h index 8084d419..bc05c0dd 100644 --- a/include/react/common/TopoQueue.h +++ b/include/react/common/TopoQueue.h @@ -12,8 +12,6 @@ #include "react/detail/Defs.h" #include -#include -#include #include #include @@ -51,30 +49,30 @@ class TopoQueue bool FetchNext() { - // Throw away previous values - nextData_.clear(); - // Find min level of nodes in queue data - minLevel_ = (std::numeric_limits::max)(); - for (const auto& e : queueData_) - if (minLevel_ > e.Level) - minLevel_ = e.Level; + auto min = std::min_element( + queueData_.begin(), + queueData_.end(), + [](const Entry& a, const Entry& b){ return a.Level < b.Level;}); // Swap entries with min level to the end auto p = std::partition( queueData_.begin(), queueData_.end(), - LevelCompFunctor{ minLevel_ }); + [&min](const Entry& e) { return e.Level != min->Level;}); + + // Throw away any previous values + nextData_.clear(); // Reserve once to avoid multiple re-allocations nextData_.reserve(std::distance(p, queueData_.end())); // Move min level values to next data for (auto it = p; it != queueData_.end(); ++it) - nextData_.push_back(std::move(it->Value)); + nextData_.emplace_back(std::move(it->Value)); // Truncate moved entries - queueData_.resize(std::distance(queueData_.begin(), p)); + queueData_.erase(p, queueData_.end()); return !nextData_.empty(); } @@ -93,21 +91,10 @@ class TopoQueue int Level; }; - struct LevelCompFunctor - { - LevelCompFunctor(int level) : Level( level ) {} - - bool operator()(const Entry& e) const { return e.Level != Level; } - - const int Level; - }; - NextDataT nextData_; QueueDataT queueData_; TLevelFunc levelFunc_; - - int minLevel_ = (std::numeric_limits::max)(); }; /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -226,10 +213,10 @@ class ConcurrentTopoQueue uint totalWeight = 0; // Determine current min level - minLevel_ = (std::numeric_limits::max)(); - for (const auto& buf : collectBuffer_) - if (minLevel_ > buf.MinLevel) - minLevel_ = buf.MinLevel; + auto min = std::min_element( + collectBuffer_.begin(), + collectBuffer_.end(), + [](const ThreadLocalBuffer& a, const ThreadLocalBuffer& b){ return a.MinLevel < b.MinLevel;}); // For each thread local buffer... for (auto& buf : collectBuffer_) @@ -240,17 +227,17 @@ class ConcurrentTopoQueue auto p = std::partition( v.begin(), v.end(), - LevelCompFunctor{ minLevel_ }); + [&min](const Entry& e) { return e.Level != min->MinLevel;}); // Reserve once to avoid multiple re-allocations - nextData_.reserve(std::distance(p, v.end())); + nextData_.reserve(nextData_.size() + std::distance(p, v.end())); // Move min level values to global next data for (auto it = p; it != v.end(); ++it) nextData_.emplace_back(std::move(it->Value), it->Weight); // Truncate remaining - v.resize(std::distance(v.begin(), p)); + v.erase(p, v.end()); // Calc new min level and weight for this buffer buf.MinLevel = (std::numeric_limits::max)(); @@ -296,15 +283,6 @@ class ConcurrentTopoQueue uint Weight; }; - struct LevelCompFunctor - { - LevelCompFunctor(int level) : Level{ level } {} - - bool operator()(const Entry& e) const { return e.Level != Level; } - - const int Level; - }; - struct ThreadLocalBuffer { QueueDataT Data; @@ -312,8 +290,6 @@ class ConcurrentTopoQueue uint Weight = 0; }; - int minLevel_ = (std::numeric_limits::max)(); - NextDataT nextData_; NextRangeT nextRange_; @@ -325,4 +301,4 @@ class ConcurrentTopoQueue /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_COMMON_TOPOQUEUE_H_INCLUDED \ No newline at end of file +#endif // REACT_COMMON_TOPOQUEUE_H_INCLUDED diff --git a/include/react/common/Types.h b/include/react/common/Types.h index 5d747eee..728d683a 100644 --- a/include/react/common/Types.h +++ b/include/react/common/Types.h @@ -11,7 +11,6 @@ #include "react/detail/Defs.h" -#include #include /***************************************/ REACT_IMPL_BEGIN /**************************************/ @@ -24,8 +23,6 @@ ObjectId GetObjectId(const O& obj) return (ObjectId)&obj; } -using UpdateDurationT = std::chrono::duration; - /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_COMMON_TYPES_H_INCLUDED \ No newline at end of file +#endif // REACT_COMMON_TYPES_H_INCLUDED diff --git a/include/react/detail/graph/GraphBase.h b/include/react/detail/graph/GraphBase.h index b7d79d27..31e8c481 100644 --- a/include/react/detail/graph/GraphBase.h +++ b/include/react/detail/graph/GraphBase.h @@ -38,7 +38,7 @@ enum class WeightHint template < typename D, - long long threshold + unsigned long long threshold > class UpdateTimingPolicy : private ConditionalTimer @@ -264,8 +264,11 @@ class EventRange const_iterator begin() const { return data_.begin(); } const_iterator end() const { return data_.end(); } + size_type size() const { return data_.size(); } + bool empty() const { return data_.empty(); } + size_type Size() const { return data_.size(); } - bool IsEmpty() const { return data_.empty(); } + bool Empty() const { return data_.empty(); } explicit EventRange(const std::vector& data) : data_( data ) @@ -280,4 +283,4 @@ using EventEmitter = std::back_insert_iterator>; /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_DETAIL_GRAPH_GRAPHBASE_H_INCLUDED \ No newline at end of file +#endif // REACT_DETAIL_GRAPH_GRAPHBASE_H_INCLUDED diff --git a/include/react/detail/graph/ObserverNodes.h b/include/react/detail/graph/ObserverNodes.h index 351a54e5..616c3721 100644 --- a/include/react/detail/graph/ObserverNodes.h +++ b/include/react/detail/graph/ObserverNodes.h @@ -240,7 +240,7 @@ class EventObserverNode : TFunc func_; - virtual void detachObserver() + virtual void detachObserver() override { if (auto p = subject_.lock()) { @@ -340,7 +340,7 @@ class SyncedObserverNode : TFunc func_; DepHolderT deps_; - virtual void detachObserver() + virtual void detachObserver() override { if (auto p = subject_.lock()) { @@ -358,4 +358,4 @@ class SyncedObserverNode : /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_DETAIL_GRAPH_OBSERVERNODES_H_INCLUDED \ No newline at end of file +#endif // REACT_DETAIL_GRAPH_OBSERVERNODES_H_INCLUDED diff --git a/include/react/detail/graph/ReactorNodes.h b/include/react/detail/graph/ReactorNodes.h index b693a5f0..ddb2c5f4 100644 --- a/include/react/detail/graph/ReactorNodes.h +++ b/include/react/detail/graph/ReactorNodes.h @@ -245,7 +245,7 @@ class ReactorNode : std::function func_; PullT mainLoop_; - TurnT* turnPtr_; + TurnT* turnPtr_ = nullptr; PushT* curOutPtr_ = nullptr; @@ -256,4 +256,4 @@ class ReactorNode : /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_DETAIL_GRAPH_REACTORNODES_H_INCLUDED \ No newline at end of file +#endif // REACT_DETAIL_GRAPH_REACTORNODES_H_INCLUDED diff --git a/project/msvc/CppReact.sln b/project/msvc/CppReact.sln deleted file mode 100644 index b414852d..00000000 --- a/project/msvc/CppReact.sln +++ /dev/null @@ -1,149 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30501.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppReact", "CppReact.vcxproj", "{5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppReactBenchmark", "CppReactBenchmark.vcxproj", "{F9115FB9-61DD-4B3C-BCE8-7D26372B05F7}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppReactTest", "CppReactTest.vcxproj", "{52A9EC67-C6A7-453B-AD65-F027CA07AF44}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3_Examples", "3_Examples", "{518ACABC-E4A7-4E2D-9A04-FFA669A30DBF}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1_Core", "1_Core", "{91AFD614-F7E6-48CE-9808-642EAF476B66}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4_Benchmarks", "4_Benchmarks", "{D6F88FF5-E55C-4E65-ABBB-B4298AB84D40}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2_Tests", "2_Tests", "{3F97AA87-0A03-4428-94C1-C9B4007C2C80}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppReactExample", "CppReactExample.vcxproj", "{CC0CD982-AE7D-4797-A122-58E6BBE70DDB}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example_BasicAlgorithms", "Example_BasicAlgorithms.vcxproj", "{617019A2-97BE-4A60-8EC4-3547D8C54533}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example_BasicComposition", "Example_BasicComposition.vcxproj", "{D7B70D3B-F14D-4A85-B164-EAB88C358E85}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example_BasicEvents", "Example_BasicEvents.vcxproj", "{BD777649-97F1-4810-BF21-CB27F7672BF4}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example_BasicObservers", "Example_BasicObservers.vcxproj", "{CC66BFA0-D609-46E0-9FD1-F9CC902410B1}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example_BasicReactors", "Example_BasicReactors.vcxproj", "{D976F4D4-B472-4709-BFB5-B1BEEA1F7E96}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example_BasicSignals", "Example_BasicSignals.vcxproj", "{230C9137-CCD0-47E2-8F1F-2E1DD19984A1}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example_BasicSynchronization", "Example_BasicSynchronization.vcxproj", "{269329F8-A9E1-41AC-9C37-3A82A082A62C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1}.Debug|Win32.ActiveCfg = Debug|Win32 - {5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1}.Debug|Win32.Build.0 = Debug|Win32 - {5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1}.Debug|x64.ActiveCfg = Debug|x64 - {5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1}.Debug|x64.Build.0 = Debug|x64 - {5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1}.Release|Win32.ActiveCfg = Release|Win32 - {5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1}.Release|Win32.Build.0 = Release|Win32 - {5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1}.Release|x64.ActiveCfg = Release|x64 - {5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1}.Release|x64.Build.0 = Release|x64 - {F9115FB9-61DD-4B3C-BCE8-7D26372B05F7}.Debug|Win32.ActiveCfg = Debug|Win32 - {F9115FB9-61DD-4B3C-BCE8-7D26372B05F7}.Debug|Win32.Build.0 = Debug|Win32 - {F9115FB9-61DD-4B3C-BCE8-7D26372B05F7}.Debug|x64.ActiveCfg = Debug|x64 - {F9115FB9-61DD-4B3C-BCE8-7D26372B05F7}.Debug|x64.Build.0 = Debug|x64 - {F9115FB9-61DD-4B3C-BCE8-7D26372B05F7}.Release|Win32.ActiveCfg = Release|Win32 - {F9115FB9-61DD-4B3C-BCE8-7D26372B05F7}.Release|Win32.Build.0 = Release|Win32 - {F9115FB9-61DD-4B3C-BCE8-7D26372B05F7}.Release|x64.ActiveCfg = Release|x64 - {F9115FB9-61DD-4B3C-BCE8-7D26372B05F7}.Release|x64.Build.0 = Release|x64 - {52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Debug|Win32.ActiveCfg = Debug|Win32 - {52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Debug|Win32.Build.0 = Debug|Win32 - {52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Debug|x64.ActiveCfg = Debug|x64 - {52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Debug|x64.Build.0 = Debug|x64 - {52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Release|Win32.ActiveCfg = Release|Win32 - {52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Release|Win32.Build.0 = Release|Win32 - {52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Release|x64.ActiveCfg = Release|x64 - {52A9EC67-C6A7-453B-AD65-F027CA07AF44}.Release|x64.Build.0 = Release|x64 - {CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Debug|Win32.ActiveCfg = Debug|Win32 - {CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Debug|Win32.Build.0 = Debug|Win32 - {CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Debug|x64.ActiveCfg = Debug|x64 - {CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Debug|x64.Build.0 = Debug|x64 - {CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Release|Win32.ActiveCfg = Release|Win32 - {CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Release|Win32.Build.0 = Release|Win32 - {CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Release|x64.ActiveCfg = Release|x64 - {CC0CD982-AE7D-4797-A122-58E6BBE70DDB}.Release|x64.Build.0 = Release|x64 - {617019A2-97BE-4A60-8EC4-3547D8C54533}.Debug|Win32.ActiveCfg = Debug|Win32 - {617019A2-97BE-4A60-8EC4-3547D8C54533}.Debug|Win32.Build.0 = Debug|Win32 - {617019A2-97BE-4A60-8EC4-3547D8C54533}.Debug|x64.ActiveCfg = Debug|x64 - {617019A2-97BE-4A60-8EC4-3547D8C54533}.Debug|x64.Build.0 = Debug|x64 - {617019A2-97BE-4A60-8EC4-3547D8C54533}.Release|Win32.ActiveCfg = Release|Win32 - {617019A2-97BE-4A60-8EC4-3547D8C54533}.Release|Win32.Build.0 = Release|Win32 - {617019A2-97BE-4A60-8EC4-3547D8C54533}.Release|x64.ActiveCfg = Release|x64 - {617019A2-97BE-4A60-8EC4-3547D8C54533}.Release|x64.Build.0 = Release|x64 - {D7B70D3B-F14D-4A85-B164-EAB88C358E85}.Debug|Win32.ActiveCfg = Debug|Win32 - {D7B70D3B-F14D-4A85-B164-EAB88C358E85}.Debug|Win32.Build.0 = Debug|Win32 - {D7B70D3B-F14D-4A85-B164-EAB88C358E85}.Debug|x64.ActiveCfg = Debug|x64 - {D7B70D3B-F14D-4A85-B164-EAB88C358E85}.Debug|x64.Build.0 = Debug|x64 - {D7B70D3B-F14D-4A85-B164-EAB88C358E85}.Release|Win32.ActiveCfg = Release|Win32 - {D7B70D3B-F14D-4A85-B164-EAB88C358E85}.Release|Win32.Build.0 = Release|Win32 - {D7B70D3B-F14D-4A85-B164-EAB88C358E85}.Release|x64.ActiveCfg = Release|x64 - {D7B70D3B-F14D-4A85-B164-EAB88C358E85}.Release|x64.Build.0 = Release|x64 - {BD777649-97F1-4810-BF21-CB27F7672BF4}.Debug|Win32.ActiveCfg = Debug|Win32 - {BD777649-97F1-4810-BF21-CB27F7672BF4}.Debug|Win32.Build.0 = Debug|Win32 - {BD777649-97F1-4810-BF21-CB27F7672BF4}.Debug|x64.ActiveCfg = Debug|x64 - {BD777649-97F1-4810-BF21-CB27F7672BF4}.Debug|x64.Build.0 = Debug|x64 - {BD777649-97F1-4810-BF21-CB27F7672BF4}.Release|Win32.ActiveCfg = Release|Win32 - {BD777649-97F1-4810-BF21-CB27F7672BF4}.Release|Win32.Build.0 = Release|Win32 - {BD777649-97F1-4810-BF21-CB27F7672BF4}.Release|x64.ActiveCfg = Release|x64 - {BD777649-97F1-4810-BF21-CB27F7672BF4}.Release|x64.Build.0 = Release|x64 - {CC66BFA0-D609-46E0-9FD1-F9CC902410B1}.Debug|Win32.ActiveCfg = Debug|Win32 - {CC66BFA0-D609-46E0-9FD1-F9CC902410B1}.Debug|Win32.Build.0 = Debug|Win32 - {CC66BFA0-D609-46E0-9FD1-F9CC902410B1}.Debug|x64.ActiveCfg = Debug|x64 - {CC66BFA0-D609-46E0-9FD1-F9CC902410B1}.Debug|x64.Build.0 = Debug|x64 - {CC66BFA0-D609-46E0-9FD1-F9CC902410B1}.Release|Win32.ActiveCfg = Release|Win32 - {CC66BFA0-D609-46E0-9FD1-F9CC902410B1}.Release|Win32.Build.0 = Release|Win32 - {CC66BFA0-D609-46E0-9FD1-F9CC902410B1}.Release|x64.ActiveCfg = Release|x64 - {CC66BFA0-D609-46E0-9FD1-F9CC902410B1}.Release|x64.Build.0 = Release|x64 - {D976F4D4-B472-4709-BFB5-B1BEEA1F7E96}.Debug|Win32.ActiveCfg = Debug|Win32 - {D976F4D4-B472-4709-BFB5-B1BEEA1F7E96}.Debug|Win32.Build.0 = Debug|Win32 - {D976F4D4-B472-4709-BFB5-B1BEEA1F7E96}.Debug|x64.ActiveCfg = Debug|x64 - {D976F4D4-B472-4709-BFB5-B1BEEA1F7E96}.Debug|x64.Build.0 = Debug|x64 - {D976F4D4-B472-4709-BFB5-B1BEEA1F7E96}.Release|Win32.ActiveCfg = Release|Win32 - {D976F4D4-B472-4709-BFB5-B1BEEA1F7E96}.Release|Win32.Build.0 = Release|Win32 - {D976F4D4-B472-4709-BFB5-B1BEEA1F7E96}.Release|x64.ActiveCfg = Release|x64 - {D976F4D4-B472-4709-BFB5-B1BEEA1F7E96}.Release|x64.Build.0 = Release|x64 - {230C9137-CCD0-47E2-8F1F-2E1DD19984A1}.Debug|Win32.ActiveCfg = Debug|Win32 - {230C9137-CCD0-47E2-8F1F-2E1DD19984A1}.Debug|Win32.Build.0 = Debug|Win32 - {230C9137-CCD0-47E2-8F1F-2E1DD19984A1}.Debug|x64.ActiveCfg = Debug|x64 - {230C9137-CCD0-47E2-8F1F-2E1DD19984A1}.Debug|x64.Build.0 = Debug|x64 - {230C9137-CCD0-47E2-8F1F-2E1DD19984A1}.Release|Win32.ActiveCfg = Release|Win32 - {230C9137-CCD0-47E2-8F1F-2E1DD19984A1}.Release|Win32.Build.0 = Release|Win32 - {230C9137-CCD0-47E2-8F1F-2E1DD19984A1}.Release|x64.ActiveCfg = Release|x64 - {230C9137-CCD0-47E2-8F1F-2E1DD19984A1}.Release|x64.Build.0 = Release|x64 - {269329F8-A9E1-41AC-9C37-3A82A082A62C}.Debug|Win32.ActiveCfg = Debug|Win32 - {269329F8-A9E1-41AC-9C37-3A82A082A62C}.Debug|Win32.Build.0 = Debug|Win32 - {269329F8-A9E1-41AC-9C37-3A82A082A62C}.Debug|x64.ActiveCfg = Debug|x64 - {269329F8-A9E1-41AC-9C37-3A82A082A62C}.Debug|x64.Build.0 = Debug|x64 - {269329F8-A9E1-41AC-9C37-3A82A082A62C}.Release|Win32.ActiveCfg = Release|Win32 - {269329F8-A9E1-41AC-9C37-3A82A082A62C}.Release|Win32.Build.0 = Release|Win32 - {269329F8-A9E1-41AC-9C37-3A82A082A62C}.Release|x64.ActiveCfg = Release|x64 - {269329F8-A9E1-41AC-9C37-3A82A082A62C}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1} = {91AFD614-F7E6-48CE-9808-642EAF476B66} - {F9115FB9-61DD-4B3C-BCE8-7D26372B05F7} = {D6F88FF5-E55C-4E65-ABBB-B4298AB84D40} - {52A9EC67-C6A7-453B-AD65-F027CA07AF44} = {3F97AA87-0A03-4428-94C1-C9B4007C2C80} - {CC0CD982-AE7D-4797-A122-58E6BBE70DDB} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF} - {617019A2-97BE-4A60-8EC4-3547D8C54533} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF} - {D7B70D3B-F14D-4A85-B164-EAB88C358E85} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF} - {BD777649-97F1-4810-BF21-CB27F7672BF4} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF} - {CC66BFA0-D609-46E0-9FD1-F9CC902410B1} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF} - {D976F4D4-B472-4709-BFB5-B1BEEA1F7E96} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF} - {230C9137-CCD0-47E2-8F1F-2E1DD19984A1} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF} - {269329F8-A9E1-41AC-9C37-3A82A082A62C} = {518ACABC-E4A7-4E2D-9A04-FFA669A30DBF} - EndGlobalSection -EndGlobal diff --git a/project/msvc/CppReact.vcxproj b/project/msvc/CppReact.vcxproj deleted file mode 100644 index 16ae1f97..00000000 --- a/project/msvc/CppReact.vcxproj +++ /dev/null @@ -1,206 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {5E56AAB9-4E33-4B9E-A315-E85CEDB75CF1} - CppReact - - - - StaticLibrary - true - v120 - MultiByte - - - StaticLibrary - true - v120 - MultiByte - - - StaticLibrary - false - v120 - true - MultiByte - - - StaticLibrary - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - true - %(PreprocessorDefinitions) - - - true - - - $(OutDir)$(TargetName)$(TargetExt) - - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - true - %(PreprocessorDefinitions) - - - true - - - $(OutDir)$(TargetName)$(TargetExt) - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - true - %(PreprocessorDefinitions) - - - true - true - true - - - $(OutDir)$(TargetName)$(TargetExt) - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - true - %(PreprocessorDefinitions) - - - true - true - true - - - $(OutDir)$(TargetName)$(TargetExt) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/project/msvc/CppReact.vcxproj.filters b/project/msvc/CppReact.vcxproj.filters deleted file mode 100644 index 7de3201b..00000000 --- a/project/msvc/CppReact.vcxproj.filters +++ /dev/null @@ -1,171 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {82fd9b9e-0b63-40f7-b245-b5eb0271b0d2} - - - {c7adc39d-d19e-4fe2-b945-332515717bc8} - - - {6883dd62-b27e-4b11-9cc8-cbac096f4723} - - - {11a75126-8bfd-4693-be4b-4e06ab73450c} - - - {f58215db-3a12-432a-a4c1-e24a90df70a9} - - - {3f444875-ab1a-4bbd-99eb-7018c930098a} - - - {22da08e3-fb85-4fed-9fbc-8944ef866ccc} - - - - - Header Files\common - - - Header Files\common - - - Header Files\common - - - Header Files\common - - - Header Files\common - - - Header Files - - - Header Files\common - - - Header Files - - - Header Files\engine - - - Header Files\detail - - - Header Files\detail - - - Header Files\detail - - - Header Files\detail - - - Header Files\detail - - - Header Files\detail\graph - - - Header Files\detail\graph - - - Header Files\detail\graph - - - Header Files\logging - - - Header Files\logging - - - Header Files\logging - - - Header Files - - - Header Files\detail - - - Header Files\detail - - - Header Files\detail\graph - - - Header Files\detail\graph - - - Header Files\detail - - - Header Files - - - Header Files\detail - - - Header Files - - - Header Files\detail\graph - - - Header Files\engine - - - Header Files - - - Header Files - - - Header Files\common - - - Header Files\engine - - - Header Files\detail\graph - - - Header Files\common - - - Header Files\detail - - - - - Source Files\logging - - - Source Files\logging - - - Source Files\engine - - - Source Files\engine - - - Source Files\engine - - - \ No newline at end of file diff --git a/project/msvc/CppReactBenchmark.vcxproj b/project/msvc/CppReactBenchmark.vcxproj deleted file mode 100644 index 7613239a..00000000 --- a/project/msvc/CppReactBenchmark.vcxproj +++ /dev/null @@ -1,166 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {F9115FB9-61DD-4B3C-BCE8-7D26372B05F7} - CppReactBenchmark - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - - Level3 - Disabled - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - _CRT_SECURE_NO_WARNINGS;_VARIADIC_MAX=10;%(PreprocessorDefinitions) - - - true - Console - - - - - Level3 - Disabled - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - _CRT_SECURE_NO_WARNINGS;_VARIADIC_MAX=10;%(PreprocessorDefinitions) - - - true - Console - - - - - Level3 - MaxSpeed - true - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - _CRT_SECURE_NO_WARNINGS;_VARIADIC_MAX=10;%(PreprocessorDefinitions) - - - true - true - true - Console - false - - - - - Level3 - MaxSpeed - true - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - _CRT_SECURE_NO_WARNINGS;_VARIADIC_MAX=10;%(PreprocessorDefinitions) - - - true - true - true - Console - false - - - - - {5e56aab9-4e33-4b9e-a315-e85cedb75cf1} - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/project/msvc/CppReactBenchmark.vcxproj.filters b/project/msvc/CppReactBenchmark.vcxproj.filters deleted file mode 100644 index cc27f988..00000000 --- a/project/msvc/CppReactBenchmark.vcxproj.filters +++ /dev/null @@ -1,42 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - \ No newline at end of file diff --git a/project/msvc/CppReactExample.vcxproj b/project/msvc/CppReactExample.vcxproj deleted file mode 100644 index 323c777f..00000000 --- a/project/msvc/CppReactExample.vcxproj +++ /dev/null @@ -1,162 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {CC0CD982-AE7D-4797-A122-58E6BBE70DDB} - CppReactSandbox - CppReactExample - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - true - _VARIADIC_MAX=10;%(PreprocessorDefinitions) - - - true - Console - - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - true - _VARIADIC_MAX=10;%(PreprocessorDefinitions) - - - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - true - _VARIADIC_MAX=10;%(PreprocessorDefinitions) - - - true - true - true - Console - false - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - true - _VARIADIC_MAX=10;%(PreprocessorDefinitions) - - - true - true - true - Console - false - - - - - {5e56aab9-4e33-4b9e-a315-e85cedb75cf1} - - - - - - - - - \ No newline at end of file diff --git a/project/msvc/CppReactExample.vcxproj.filters b/project/msvc/CppReactExample.vcxproj.filters deleted file mode 100644 index 4c1c8f03..00000000 --- a/project/msvc/CppReactExample.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/project/msvc/CppReactTest.vcxproj b/project/msvc/CppReactTest.vcxproj deleted file mode 100644 index 7b1cb65f..00000000 --- a/project/msvc/CppReactTest.vcxproj +++ /dev/null @@ -1,195 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {52A9EC67-C6A7-453B-AD65-F027CA07AF44} - CppReactTest - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;$(GTestDir)\include;%(AdditionalIncludeDirectories) - _VARIADIC_MAX=10;%(PreprocessorDefinitions) - true - 4503;%(DisableSpecificWarnings) - - - true - $(GTestDir)\msvc\gtest-md\Debug;%(AdditionalLibraryDirectories) - gtestd.lib;gtest_main-mdd.lib;%(AdditionalDependencies) - Console - - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;$(GTestDir)\include;%(AdditionalIncludeDirectories) - _VARIADIC_MAX=10;%(PreprocessorDefinitions) - true - 4503;%(DisableSpecificWarnings) - /bigobj %(AdditionalOptions) - - - true - $(GTestDir)\msvc\gtest-md\Debug;%(AdditionalLibraryDirectories) - gtestd.lib;gtest_main-mdd.lib;%(AdditionalDependencies) - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;$(GTestDir)\include;%(AdditionalIncludeDirectories) - _VARIADIC_MAX=10;%(PreprocessorDefinitions) - true - 4503;%(DisableSpecificWarnings) - - - true - true - true - $(GTestDir)\msvc\gtest-md\Release;%(AdditionalLibraryDirectories) - gtest.lib;gtest_main-md.lib;%(AdditionalDependencies) - Console - false - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;$(GTestDir)\include;%(AdditionalIncludeDirectories) - _VARIADIC_MAX=10;%(PreprocessorDefinitions) - true - 4503;%(DisableSpecificWarnings) - /bigobj %(AdditionalOptions) - - - true - true - true - $(GTestDir)\msvc\gtest-md\Release;%(AdditionalLibraryDirectories) - gtest.lib;gtest_main-md.lib;%(AdditionalDependencies) - Console - false - - - - - {5e56aab9-4e33-4b9e-a315-e85cedb75cf1} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/project/msvc/CppReactTest.vcxproj.filters b/project/msvc/CppReactTest.vcxproj.filters deleted file mode 100644 index ae74e006..00000000 --- a/project/msvc/CppReactTest.vcxproj.filters +++ /dev/null @@ -1,78 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicAlgorithms.vcxproj b/project/msvc/Example_BasicAlgorithms.vcxproj deleted file mode 100644 index eeffca5a..00000000 --- a/project/msvc/Example_BasicAlgorithms.vcxproj +++ /dev/null @@ -1,150 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {617019A2-97BE-4A60-8EC4-3547D8C54533} - Example_BasicAlgorithms - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - - - - - {5e56aab9-4e33-4b9e-a315-e85cedb75cf1} - - - - - - - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicAlgorithms.vcxproj.filters b/project/msvc/Example_BasicAlgorithms.vcxproj.filters deleted file mode 100644 index b71fc9ed..00000000 --- a/project/msvc/Example_BasicAlgorithms.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicComposition.vcxproj b/project/msvc/Example_BasicComposition.vcxproj deleted file mode 100644 index 01d26c88..00000000 --- a/project/msvc/Example_BasicComposition.vcxproj +++ /dev/null @@ -1,150 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {D7B70D3B-F14D-4A85-B164-EAB88C358E85} - Example_BasicComposition - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - - - - - {5e56aab9-4e33-4b9e-a315-e85cedb75cf1} - - - - - - - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicComposition.vcxproj.filters b/project/msvc/Example_BasicComposition.vcxproj.filters deleted file mode 100644 index c7a5255c..00000000 --- a/project/msvc/Example_BasicComposition.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicEvents.vcxproj b/project/msvc/Example_BasicEvents.vcxproj deleted file mode 100644 index d5d13295..00000000 --- a/project/msvc/Example_BasicEvents.vcxproj +++ /dev/null @@ -1,150 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {BD777649-97F1-4810-BF21-CB27F7672BF4} - Example_BasicEvents - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - - - - - {5e56aab9-4e33-4b9e-a315-e85cedb75cf1} - - - - - - - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicEvents.vcxproj.filters b/project/msvc/Example_BasicEvents.vcxproj.filters deleted file mode 100644 index 54888eca..00000000 --- a/project/msvc/Example_BasicEvents.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicObservers.vcxproj b/project/msvc/Example_BasicObservers.vcxproj deleted file mode 100644 index 9fa37b8c..00000000 --- a/project/msvc/Example_BasicObservers.vcxproj +++ /dev/null @@ -1,150 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {CC66BFA0-D609-46E0-9FD1-F9CC902410B1} - Example_BasicObservers - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - - - - - - - - {5e56aab9-4e33-4b9e-a315-e85cedb75cf1} - - - - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicObservers.vcxproj.filters b/project/msvc/Example_BasicObservers.vcxproj.filters deleted file mode 100644 index a809b186..00000000 --- a/project/msvc/Example_BasicObservers.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicReactors.vcxproj b/project/msvc/Example_BasicReactors.vcxproj deleted file mode 100644 index 07701d98..00000000 --- a/project/msvc/Example_BasicReactors.vcxproj +++ /dev/null @@ -1,150 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {D976F4D4-B472-4709-BFB5-B1BEEA1F7E96} - Example_BasicReactors - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - - - - - - - - {5e56aab9-4e33-4b9e-a315-e85cedb75cf1} - - - - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicReactors.vcxproj.filters b/project/msvc/Example_BasicReactors.vcxproj.filters deleted file mode 100644 index 7398067f..00000000 --- a/project/msvc/Example_BasicReactors.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicSignals.vcxproj b/project/msvc/Example_BasicSignals.vcxproj deleted file mode 100644 index e090dd8a..00000000 --- a/project/msvc/Example_BasicSignals.vcxproj +++ /dev/null @@ -1,150 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {230C9137-CCD0-47E2-8F1F-2E1DD19984A1} - Example_BasicSignals - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - - - - - {5e56aab9-4e33-4b9e-a315-e85cedb75cf1} - - - - - - - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicSignals.vcxproj.filters b/project/msvc/Example_BasicSignals.vcxproj.filters deleted file mode 100644 index eafb525a..00000000 --- a/project/msvc/Example_BasicSignals.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicSynchronization.vcxproj b/project/msvc/Example_BasicSynchronization.vcxproj deleted file mode 100644 index 2b2edec4..00000000 --- a/project/msvc/Example_BasicSynchronization.vcxproj +++ /dev/null @@ -1,151 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {269329F8-A9E1-41AC-9C37-3A82A082A62C} - Example_BasicSynchronization - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - $(SolutionDir)..\..\build\$(Configuration)\ - $(OutDir)$(ProjectName)\ - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - Disabled - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - Console - - - - - Level3 - MaxSpeed - true - true - true - $(SolutionDir)..\..\include;%(AdditionalIncludeDirectories) - - - true - true - true - Console - - - - - - - - {5e56aab9-4e33-4b9e-a315-e85cedb75cf1} - - - - - - \ No newline at end of file diff --git a/project/msvc/Example_BasicSynchronization.vcxproj.filters b/project/msvc/Example_BasicSynchronization.vcxproj.filters deleted file mode 100644 index f19c5061..00000000 --- a/project/msvc/Example_BasicSynchronization.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1946c5e0..1733e9a8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,23 +1,28 @@ -### Configuration -if(DEFINED ENV{GTEST_DIR}) - message("Using gtest found in $ENV{GTEST_DIR}.") -else() - message("GTEST_DIR is not defined. You must tell CMake where to find the gtest source.") - return() -endif() -add_subdirectory($ENV{GTEST_DIR} ${CMAKE_CURRENT_BINARY_DIR}/gtest) +find_package(GTest REQUIRED) +find_package(Threads REQUIRED) -### CppReactTest -add_executable(CppReactTest - src/EventStreamTest.cpp - src/EventStreamTestQ.cpp - src/MoveTest.cpp - src/ObserverTest.cpp - src/ObserverTestQ.cpp - src/OperationsTest.cpp - src/OperationsTestQ.cpp - src/SignalTest.cpp - src/SignalTestQ.cpp - src/TransactionTest.cpp) +function(cppreact_test) + set(options SKIPPED BOOST BENCHMARK) + set(oneValueArgs NAME) + set(multiValueArgs SOURCES) + cmake_parse_arguments(cppreact_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) -target_link_libraries(CppReactTest CppReact gtest gtest_main) + add_executable (${cppreact_test_NAME} ${cppreact_test_SOURCES}) + target_link_libraries(${cppreact_test_NAME} CppReact ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) + + # GTEST_ADD_TESTS does not seem to be able to find our tests ... + # pure guess : because of INSTANTIATE_TYPED_TEST_CASE_P usage ? + #GTEST_ADD_TESTS(${cppreact_test_NAME} "" AUTO) + add_test(NAME ${cppreact_test_NAME} COMMAND ${cppreact_test_NAME}) +endfunction(cppreact_test) + +cppreact_test(NAME EventStreamTest SOURCES src/EventStreamTest.cpp) +cppreact_test(NAME EventStreamTestQ SOURCES src/EventStreamTestQ.cpp) +cppreact_test(NAME MoveTest SOURCES src/MoveTest.cpp) +cppreact_test(NAME ObserverTest SOURCES src/ObserverTest.cpp) +cppreact_test(NAME ObserverTestQ SOURCES src/ObserverTestQ.cpp) +cppreact_test(NAME OperationsTest SOURCES src/OperationsTest.cpp) +cppreact_test(NAME OperationsTestQ SOURCES src/OperationsTestQ.cpp) +cppreact_test(NAME SignalTest SOURCES src/SignalTest.cpp) +cppreact_test(NAME SignalTestQ SOURCES src/SignalTestQ.cpp) +cppreact_test(NAME TransactionTest SOURCES src/TransactionTest.cpp) diff --git a/tests/src/OperationsTest.h b/tests/src/OperationsTest.h index 5ef9cc3d..a5f7c83d 100644 --- a/tests/src/OperationsTest.h +++ b/tests/src/OperationsTest.h @@ -30,6 +30,11 @@ struct Incrementer { T operator()(Token, T v) const { return v+1; } }; template struct Decrementer { T operator()(Token, T v) const { return v-1; } }; +template +void repeat(I i, F f) { + while (i--) f(); +} + /////////////////////////////////////////////////////////////////////////////////////////////////// /// EventStreamTest fixture /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -710,11 +715,10 @@ TYPED_TEST_P(OperationsTest, SyncedIterate4) vector{}, With(op1,op2), [] (EventRange range, vector& v, int op1, int op2) -> void { - for (const auto& e : range) - { + repeat(range.size(),[&]{ v.push_back(op1); v.push_back(op2); - } + }); }); auto out2 = Iterate( diff --git a/tests/src/TransactionTest.cpp b/tests/src/TransactionTest.cpp index 61a51e11..efc476f5 100644 --- a/tests/src/TransactionTest.cpp +++ b/tests/src/TransactionTest.cpp @@ -26,4 +26,4 @@ INSTANTIATE_TYPED_TEST_CASE_P(ParToposort, TransactionTest, P2); INSTANTIATE_TYPED_TEST_CASE_P(Pulsecount, TransactionTest, P3); INSTANTIATE_TYPED_TEST_CASE_P(Subtree, TransactionTest, P4); -} // ~namespace \ No newline at end of file +} // ~namespace From 9e6cc41430344d90be138775c6437903811dcef9 Mon Sep 17 00:00:00 2001 From: Ivan Le Lann Date: Mon, 30 May 2016 02:13:04 +0200 Subject: [PATCH 2/3] currently unusable draft --- CMakeLists.txt | 2 +- examples/CMakeLists.txt | 22 +- include/react/Algorithm.h | 33 +- include/react/Domain.h | 43 +- include/react/Event.h | 39 +- include/react/Forward.h | 55 + include/react/Observer.h | 33 +- include/react/Signal.h | 1175 ++++++---------------- include/react/TypeTraits.h | 40 +- include/react/common/Util.h | 62 +- include/react/detail/DomainBase.h | 3 +- include/react/detail/graph/SignalNodes.h | 7 +- tests/CMakeLists.txt | 14 +- tests/src/SignalTest.h | 150 ++- 14 files changed, 602 insertions(+), 1076 deletions(-) create mode 100644 include/react/Forward.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7929a3a9..15bf3d5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wpedantic") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wpedantic") include_directories ("${PROJECT_SOURCE_DIR}/include") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 940479ae..3ae11c1c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,10 +1,10 @@ ### Example_BasicAlgorithms -add_executable(Example_BasicAlgorithms src/BasicAlgorithms.cpp) -target_link_libraries(Example_BasicAlgorithms CppReact) +#add_executable(Example_BasicAlgorithms src/BasicAlgorithms.cpp) +#target_link_libraries(Example_BasicAlgorithms CppReact) ### Example_BasicComposition -add_executable(Example_BasicComposition src/BasicComposition.cpp) -target_link_libraries(Example_BasicComposition CppReact) +#add_executable(Example_BasicComposition src/BasicComposition.cpp) +#target_link_libraries(Example_BasicComposition CppReact) ### Example_BasicEvents add_executable(Example_BasicEvents src/BasicEvents.cpp) @@ -15,16 +15,16 @@ add_executable(Example_BasicObservers src/BasicObservers.cpp) target_link_libraries(Example_BasicObservers CppReact) ### Example_BasicReactors -find_package(Boost 1.55 COMPONENTS coroutine context system) +find_package(Boost COMPONENTS coroutine context system) if(Boost_FOUND) - include_directories(${Boost_INCLUDE_DIRS}) - add_executable(Example_BasicReactors src/BasicReactors.cpp) - target_link_libraries(Example_BasicReactors CppReact ${Boost_LIBRARIES}) + include_directories(${Boost_INCLUDE_DIRS}) + add_executable(Example_BasicReactors src/BasicReactors.cpp) + target_link_libraries(Example_BasicReactors CppReact ${Boost_LIBRARIES}) else() - message("boost::coroutine not found. Skipping build of Example_BasicReactors.") + message("boost::coroutine not found. Skipping build of Example_BasicReactors.") + #add_executable(Example_BasicReactors src/BasicReactors.cpp) + #target_link_libraries(Example_BasicReactors CppReact) endif() -#add_exyecutable(Example_BasicReactors src/BasicReactors.cpp) -#target_link_libraries(Example_BasicReactors CppReact) ### Example_BasicSignals add_executable(Example_BasicSignals src/BasicSignals.cpp) diff --git a/include/react/Algorithm.h b/include/react/Algorithm.h index 7caed812..a1d20b18 100644 --- a/include/react/Algorithm.h +++ b/include/react/Algorithm.h @@ -19,26 +19,6 @@ /*****************************************/ REACT_BEGIN /*****************************************/ -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// Forward declarations -/////////////////////////////////////////////////////////////////////////////////////////////////// -template -class Signal; - -template -class VarSignal; - -template -class Events; - -template -class EventSource; - -enum class Token; - -template -class SignalPack; - /////////////////////////////////////////////////////////////////////////////////////////////////// /// Hold - Hold the most recent event in a signal /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -63,11 +43,12 @@ auto Hold(const Events& events, V&& init) /////////////////////////////////////////////////////////////////////////////////////////////////// template < - typename D, - typename S + typename SignalT, + typename D = typename SignalT::DomainT, + typename S = typename SignalT::ValueT > -auto Monitor(const Signal& target) - -> Events +auto Monitor(const SignalT& target) + -> Events { using REACT_IMPL::MonitorNode; @@ -140,7 +121,7 @@ template typename S = typename std::decay::type > auto Iterate(const Events& events, V&& init, - const SignalPack& depPack, FIn&& func) + const SignalPack& depPack, FIn&& func) -> Signal { using REACT_IMPL::SyncedIterateNode; @@ -281,4 +262,4 @@ auto ChangedTo(const Signal& target, V&& value) /******************************************/ REACT_END /******************************************/ -#endif // REACT_ALGORITHM_H_INCLUDED \ No newline at end of file +#endif // REACT_ALGORITHM_H_INCLUDED diff --git a/include/react/Domain.h b/include/react/Domain.h index e27c2514..ee638aaa 100644 --- a/include/react/Domain.h +++ b/include/react/Domain.h @@ -19,6 +19,8 @@ #include "react/detail/graph/ContinuationNodes.h" +#include "react/Forward.h" + #ifdef REACT_ENABLE_LOGGING #include "react/logging/EventLog.h" #include "react/logging/EventRecords.h" @@ -26,41 +28,6 @@ /*****************************************/ REACT_BEGIN /*****************************************/ -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// Forward declarations -/////////////////////////////////////////////////////////////////////////////////////////////////// -template -class Signal; - -template -class VarSignal; - -template -class TempSignal; - -template -class Events; - -template -class EventSource; - -template -class TempEvents; - -enum class Token; - -template -class Observer; - -template -class ScopedObserver; - -template -class Reactor; - -template -class SignalPack; - /////////////////////////////////////////////////////////////////////////////////////////////////// /// Common types & constants /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -285,7 +252,7 @@ template typename ... TDepValues > auto MakeContinuation(TransactionFlagsT flags, const Events& trigger, - const SignalPack& depPack, FIn&& func) + const SignalPack& depPack, FIn&& func) -> Continuation { static_assert(DOut::is_concurrent, @@ -349,7 +316,7 @@ template typename ... TDepValues > auto MakeContinuation(const Events& trigger, - const SignalPack& depPack, FIn&& func) + const SignalPack& depPack, FIn&& func) -> Continuation { return MakeContinuation(0, trigger, depPack, std::forward(func)); @@ -461,4 +428,4 @@ void AsyncTransaction(TransactionFlagsT flags, TransactionStatus& status, F&& fu \ using ReactorT = Reactor; -#endif // REACT_DOMAIN_H_INCLUDED \ No newline at end of file +#endif // REACT_DOMAIN_H_INCLUDED diff --git a/include/react/Event.h b/include/react/Event.h index 2c286809..6c94fb9c 100644 --- a/include/react/Event.h +++ b/include/react/Event.h @@ -15,6 +15,7 @@ #include #include +#include "react/Forward.h" #include "react/Observer.h" #include "react/TypeTraits.h" #include "react/common/Util.h" @@ -22,26 +23,6 @@ /*****************************************/ REACT_BEGIN /*****************************************/ -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// Forward declarations -/////////////////////////////////////////////////////////////////////////////////////////////////// -template -class Events; - -template -class EventSource; - -template -class TempEvents; - -enum class Token; - -template -class Signal; - -template -class SignalPack; - using REACT_IMPL::WeightHint; /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -228,7 +209,7 @@ template typename FIn, typename ... TDepValues > -auto Filter(const Events& source, const SignalPack& depPack, FIn&& func) +auto Filter(const Events& source, const SignalPack& depPack, FIn&& func) -> Events { using REACT_IMPL::SyncedEventFilterNode; @@ -313,7 +294,7 @@ template typename ... TDepValues, typename TOut = typename std::result_of::type > -auto Transform(const Events& source, const SignalPack& depPack, FIn&& func) +auto Transform(const Events& source, const SignalPack& depPack, FIn&& func) -> Events { using REACT_IMPL::SyncedEventTransformNode; @@ -379,7 +360,7 @@ template typename FIn, typename ... TDepValues > -auto Process(const Events& source, const SignalPack& depPack, FIn&& func) +auto Process(const Events& source, const SignalPack& depPack, FIn&& func) -> Events { using REACT_IMPL::SyncedEventProcessingNode; @@ -834,14 +815,4 @@ class TempEvents : public Events /******************************************/ REACT_END /******************************************/ -/***************************************/ REACT_IMPL_BEGIN /**************************************/ - -template -bool Equals(const Events& lhs, const Events& rhs) -{ - return lhs.Equals(rhs); -} - -/****************************************/ REACT_IMPL_END /***************************************/ - -#endif // REACT_EVENT_H_INCLUDED \ No newline at end of file +#endif // REACT_EVENT_H_INCLUDED diff --git a/include/react/Forward.h b/include/react/Forward.h new file mode 100644 index 00000000..98ee0742 --- /dev/null +++ b/include/react/Forward.h @@ -0,0 +1,55 @@ + +// Copyright Sebastian Jeckel 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef REACT_FORWARD_H_INCLUDED +#define REACT_FORWARD_H_INCLUDED + +#pragma once + +#include "react/detail/Defs.h" + +/*****************************************/ REACT_BEGIN /*****************************************/ + +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// Forward declarations +/////////////////////////////////////////////////////////////////////////////////////////////////// + +template +class Signal; + +template +class VarSignal; + +template +class OpSignal; + +template +using ValueT = typename std::decay_t::value_type; + +template +struct SignalPack; + +template +class Events; + +template +class EventSource; + +template +class TempEvents; + +template +class Observer; + +template +class ScopedObserver; + +template +class Continuation; + +/******************************************/ REACT_END /******************************************/ + +#endif // REACT_FORWARD_H_INCLUDED diff --git a/include/react/Observer.h b/include/react/Observer.h index 45fd78a1..b955ac15 100644 --- a/include/react/Observer.h +++ b/include/react/Observer.h @@ -18,21 +18,10 @@ #include "react/detail/IReactiveNode.h" #include "react/detail/ObserverBase.h" #include "react/detail/graph/ObserverNodes.h" +#include "react/Forward.h" /*****************************************/ REACT_BEGIN /*****************************************/ -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// Forward declarations -/////////////////////////////////////////////////////////////////////////////////////////////////// -template -class Signal; - -template -class SignalPack; - -template -class Events; - using REACT_IMPL::ObserverAction; using REACT_IMPL::WeightHint; @@ -264,7 +253,7 @@ template typename ... TDepValues > auto Observe(const Events& subject, - const SignalPack& depPack, FIn&& func) + const SignalPack& depPack, FIn&& func) -> Observer { using REACT_IMPL::IObserver; @@ -279,19 +268,19 @@ auto Observe(const Events& subject, using WrapperT = typename std::conditional< - IsCallableWith, TDepValues ...>::value, + IsCallableWith, ValueT ...>::value, F, typename std::conditional< - IsCallableWith::value, - AddObserverRangeWrapper, + IsCallableWith ...>::value, + AddObserverRangeWrapper ...>, typename std::conditional< - IsCallableWith, TDepValues ...>::value, + IsCallableWith, ValueT ...>::value, AddDefaultReturnValueWrapper, typename std::conditional< - IsCallableWith::value, + IsCallableWith ...>::value, AddObserverRangeWrapper, - TDepValues...>, + ValueT...>, void >::type >::type @@ -302,7 +291,7 @@ auto Observe(const Events& subject, ! std::is_same::value, "Observe: Passed function does not match any of the supported signatures."); - using NodeT = SyncedObserverNode; + using NodeT = SyncedObserverNode ...>; struct NodeBuilder_ { @@ -311,7 +300,7 @@ auto Observe(const Events& subject, MyFunc( std::forward(func) ) {} - auto operator()(const Signal& ... deps) + auto operator()(const TDepValues& ... deps) -> ObserverNode* { return new NodeT( @@ -337,4 +326,4 @@ auto Observe(const Events& subject, /******************************************/ REACT_END /******************************************/ -#endif // REACT_OBSERVER_H_INCLUDED \ No newline at end of file +#endif // REACT_OBSERVER_H_INCLUDED diff --git a/include/react/Signal.h b/include/react/Signal.h index 7f211392..d165dd0e 100644 --- a/include/react/Signal.h +++ b/include/react/Signal.h @@ -10,944 +10,431 @@ #pragma once #if _MSC_VER && !__INTEL_COMPILER - #pragma warning(disable : 4503) +#pragma warning(disable : 4503) #endif #include "react/detail/Defs.h" +#include #include #include #include #include +#include "react/Forward.h" #include "react/Observer.h" #include "react/TypeTraits.h" #include "react/detail/SignalBase.h" -/*****************************************/ REACT_BEGIN /*****************************************/ +namespace react { -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// Forward declarations -/////////////////////////////////////////////////////////////////////////////////////////////////// -template -class Signal; +namespace impl { -template -class VarSignal; +template struct DomainTrait; + +template +using domain_t = typename DomainTrait...>::type; + +template +using value_t = typename std::decay_t::value_type; + +template +using if_not_signal_t = std::enable_if_t>::value>; + +template +using if_signal_t = std::enable_if_t>::value>; -template -class TempSignal; +template +using if_not_event_t = std::enable_if_t>::value>; + +template +using if_event_t = std::enable_if_t>::value>; + +template struct DomainTrait { + using type = typename TSignal::DomainT; +}; + +template +struct DomainTrait { + static_assert(std::is_same::type, + typename DomainTrait::type>::value, + "domain mismatch"); + + using type = typename TSignal::DomainT; +}; + +template struct DomainTrait> { + using type = typename DomainTrait::type; +}; + +template +using functor_t = FunctionOp; + +template +using signal_node_t = SignalOpNode...>>; + +template +auto make_node(F &&f, Args &&... args) { + return std::make_shared>( + std::forward(f), std::forward(args)...); +} + +template +auto make_op_signal(F &&f, TSignals &&... args) { + using D = domain_t; + using S = std::result_of_t...)>; + + return Signal{make_node( + std::forward(f), GetNodePtr(std::forward(args))...)}; +} + +using namespace std::placeholders; +} /////////////////////////////////////////////////////////////////////////////////////////////////// /// SignalPack - Wraps several nodes in a tuple. Create with comma operator. /////////////////////////////////////////////////////////////////////////////////////////////////// -template -< - typename D, - typename ... TValues -> -class SignalPack -{ -public: - SignalPack(const Signal& ... deps) : - Data( std::tie(deps ...) ) - {} - - template - SignalPack(const SignalPack& curArgs, const Signal& newArg) : - Data( std::tuple_cat(curArgs.Data, std::tie(newArg)) ) - {} - - std::tuple& ...> Data; + +template struct SignalPack { + SignalPack(const TSignals &... deps) : Data{deps...} {} + + template + SignalPack(const SignalPack &curArgs, const TSignal &newArg) + : Data{std::tuple_cat(curArgs.Data, std::tie(newArg))} {} + + std::tuple Data; }; /////////////////////////////////////////////////////////////////////////////////////////////////// /// With - Utility function to create a SignalPack /////////////////////////////////////////////////////////////////////////////////////////////////// -template -< - typename D, - typename ... TValues -> -auto With(const Signal& ... deps) - -> SignalPack -{ - return SignalPack(deps ...); + +template +auto With(const TSignals &... some_signals) -> SignalPack { + return SignalPack{some_signals...}; } /////////////////////////////////////////////////////////////////////////////////////////////////// /// MakeVar /////////////////////////////////////////////////////////////////////////////////////////////////// -template -< - typename D, - typename V, - typename S = typename std::decay::type, - class = typename std::enable_if< - ! IsSignal::value>::type, - class = typename std::enable_if< - ! IsEvent::value>::type -> -auto MakeVar(V&& value) - -> VarSignal -{ - return VarSignal( - std::make_shared>( - std::forward(value))); -} -template -< - typename D, - typename S -> -auto MakeVar(std::reference_wrapper value) - -> VarSignal -{ - return VarSignal( - std::make_shared>>(value)); +template ::type, + class = impl::if_not_signal_t, class = impl::if_not_event_t> +auto MakeVar(V &&value) -> VarSignal { + return VarSignal( + std::make_shared>(std::forward(value))); } /////////////////////////////////////////////////////////////////////////////////////////////////// /// MakeVar (higher order reactives) /////////////////////////////////////////////////////////////////////////////////////////////////// -template -< - typename D, - typename V, - typename S = typename std::decay::type, - typename TInner = typename S::ValueT, - class = typename std::enable_if< - IsSignal::value>::type -> -auto MakeVar(V&& value) - -> VarSignal> -{ - return VarSignal>( - std::make_shared>>( - std::forward(value))); +template ::type, + typename TInner = typename S::value_type, + class = typename std::enable_if::value>::type> +auto MakeVar(V &&value) -> VarSignal> { + return VarSignal>( + std::make_shared>>( + std::forward(value))); } -template -< - typename D, - typename V, - typename S = typename std::decay::type, - typename TInner = typename S::ValueT, - class = typename std::enable_if< - IsEvent::value>::type -> -auto MakeVar(V&& value) - -> VarSignal> -{ - return VarSignal>( - std::make_shared>>( - std::forward(value))); +template ::type, + typename TInner = typename S::value_type, + class = typename std::enable_if::value>::type> +auto MakeVar(V &&value) -> VarSignal> { + return VarSignal>( + std::make_shared>>( + std::forward(value))); } /////////////////////////////////////////////////////////////////////////////////////////////////// /// MakeSignal /////////////////////////////////////////////////////////////////////////////////////////////////// + // Single arg -template -< - typename D, - typename TValue, - typename FIn, - typename F = typename std::decay::type, - typename S = typename std::result_of::type, - typename TOp = REACT_IMPL::FunctionOp> -> -auto MakeSignal(const Signal& arg, FIn&& func) - -> TempSignal -{ - return TempSignal( - std::make_shared>( - std::forward(func), GetNodePtr(arg))); +template , + typename S = std::result_of_t> +auto MakeSignal(const Signal &arg, FIn &&func) { + return Signal( + impl::make_node(std::forward(func), GetNodePtr(arg))); +} + +// Multiple args +template +auto MakeNode(F &&f, const Tuple &tuple, std::index_sequence) { + return impl::make_node(std::forward(f), + GetNodePtr(std::get(tuple))...); } // Multiple args -template -< - typename D, - typename ... TValues, - typename FIn, - typename F = typename std::decay::type, - typename S = typename std::result_of::type, - typename TOp = REACT_IMPL::FunctionOp ...> -> -auto MakeSignal(const SignalPack& argPack, FIn&& func) - -> TempSignal -{ - using REACT_IMPL::SignalOpNode; - - struct NodeBuilder_ - { - NodeBuilder_(FIn&& func) : - MyFunc( std::forward(func) ) - {} - - auto operator()(const Signal& ... args) - -> TempSignal - { - return TempSignal( - std::make_shared>( - std::forward(MyFunc), GetNodePtr(args) ...)); - } - - FIn MyFunc; - }; - - return REACT_IMPL::apply( - NodeBuilder_( std::forward(func) ), - argPack.Data); +template , + typename F = std::decay_t, + typename S = std::result_of_t...)>> +auto MakeSignal(const SignalPack &argPack, FIn &&func) { + return Signal{ + MakeNode(std::forward(func), argPack.Data, + impl::indices_t>())}; } /////////////////////////////////////////////////////////////////////////////////////////////////// -/// Unary operators +/// Utils /////////////////////////////////////////////////////////////////////////////////////////////////// -#define REACT_DECLARE_OP(op,name) \ -template \ -struct name ## OpFunctor \ -{ \ - T operator()(const T& v) const { return op v; } \ -}; \ - \ -template \ -< \ - typename TSignal, \ - typename D = typename TSignal::DomainT, \ - typename TVal = typename TSignal::ValueT, \ - class = typename std::enable_if< \ - IsSignal::value>::type, \ - typename F = name ## OpFunctor, \ - typename S = typename std::result_of::type, \ - typename TOp = REACT_IMPL::FunctionOp> \ -> \ -auto operator op(const TSignal& arg) \ - -> TempSignal \ -{ \ - return TempSignal( \ - std::make_shared>( \ - F(), GetNodePtr(arg))); \ -} \ - \ -template \ -< \ - typename D, \ - typename TVal, \ - typename TOpIn, \ - typename F = name ## OpFunctor, \ - typename S = typename std::result_of::type, \ - typename TOp = REACT_IMPL::FunctionOp \ -> \ -auto operator op(TempSignal&& arg) \ - -> TempSignal \ -{ \ - return TempSignal( \ - std::make_shared>( \ - F(), arg.StealOp())); \ -} -REACT_DECLARE_OP(+, UnaryPlus) -REACT_DECLARE_OP(-, UnaryMinus) -REACT_DECLARE_OP(!, LogicalNegation) -REACT_DECLARE_OP(~, BitwiseComplement) -REACT_DECLARE_OP(++, Increment) -REACT_DECLARE_OP(--, Decrement) +template struct ValueTypeTrait { using type = S; }; -#undef REACT_DECLARE_OP +template struct ValueTypeTrait { + using type = std::reference_wrapper; +}; /////////////////////////////////////////////////////////////////////////////////////////////////// -/// Binary operators +/// Signal /////////////////////////////////////////////////////////////////////////////////////////////////// -#define REACT_DECLARE_OP(op,name) \ -template \ -struct name ## OpFunctor \ -{ \ - auto operator()(const L& lhs, const R& rhs) const \ - -> decltype(std::declval() op std::declval()) \ - { \ - return lhs op rhs; \ - } \ -}; \ - \ -template \ -struct name ## OpRFunctor \ -{ \ - name ## OpRFunctor(name ## OpRFunctor&& other) : \ - LeftVal( std::move(other.LeftVal) ) \ - {} \ - \ - template \ - name ## OpRFunctor(T&& val) : \ - LeftVal( std::forward(val) ) \ - {} \ - \ - name ## OpRFunctor(const name ## OpRFunctor& other) = delete; \ - \ - auto operator()(const R& rhs) const \ - -> decltype(std::declval() op std::declval()) \ - { \ - return LeftVal op rhs; \ - } \ - \ - L LeftVal; \ -}; \ - \ -template \ -struct name ## OpLFunctor \ -{ \ - name ## OpLFunctor(name ## OpLFunctor&& other) : \ - RightVal( std::move(other.RightVal) ) \ - {} \ - \ - template \ - name ## OpLFunctor(T&& val) : \ - RightVal( std::forward(val) ) \ - {} \ - \ - name ## OpLFunctor(const name ## OpLFunctor& other) = delete; \ - \ - auto operator()(const L& lhs) const \ - -> decltype(std::declval() op std::declval()) \ - { \ - return lhs op RightVal; \ - } \ - \ - R RightVal; \ -}; \ - \ -template \ -< \ - typename TLeftSignal, \ - typename TRightSignal, \ - typename D = typename TLeftSignal::DomainT, \ - typename TLeftVal = typename TLeftSignal::ValueT, \ - typename TRightVal = typename TRightSignal::ValueT, \ - class = typename std::enable_if< \ - IsSignal::value>::type, \ - class = typename std::enable_if< \ - IsSignal::value>::type, \ - typename F = name ## OpFunctor, \ - typename S = typename std::result_of::type, \ - typename TOp = REACT_IMPL::FunctionOp, \ - REACT_IMPL::SignalNodePtrT> \ -> \ -auto operator op(const TLeftSignal& lhs, const TRightSignal& rhs) \ - -> TempSignal \ -{ \ - return TempSignal( \ - std::make_shared>( \ - F(), GetNodePtr(lhs), GetNodePtr(rhs))); \ -} \ - \ -template \ -< \ - typename TLeftSignal, \ - typename TRightValIn, \ - typename D = typename TLeftSignal::DomainT, \ - typename TLeftVal = typename TLeftSignal::ValueT, \ - typename TRightVal = typename std::decay::type, \ - class = typename std::enable_if< \ - IsSignal::value>::type, \ - class = typename std::enable_if< \ - ! IsSignal::value>::type, \ - typename F = name ## OpLFunctor, \ - typename S = typename std::result_of::type, \ - typename TOp = REACT_IMPL::FunctionOp> \ -> \ -auto operator op(const TLeftSignal& lhs, TRightValIn&& rhs) \ - -> TempSignal \ -{ \ - return TempSignal( \ - std::make_shared>( \ - F( std::forward(rhs) ), GetNodePtr(lhs))); \ -} \ - \ -template \ -< \ - typename TLeftValIn, \ - typename TRightSignal, \ - typename D = typename TRightSignal::DomainT, \ - typename TLeftVal = typename std::decay::type, \ - typename TRightVal = typename TRightSignal::ValueT, \ - class = typename std::enable_if< \ - ! IsSignal::value>::type, \ - class = typename std::enable_if< \ - IsSignal::value>::type, \ - typename F = name ## OpRFunctor, \ - typename S = typename std::result_of::type, \ - typename TOp = REACT_IMPL::FunctionOp> \ -> \ -auto operator op(TLeftValIn&& lhs, const TRightSignal& rhs) \ - -> TempSignal \ -{ \ - return TempSignal( \ - std::make_shared>( \ - F( std::forward(lhs) ), GetNodePtr(rhs))); \ -} \ -template \ -< \ - typename D, \ - typename TLeftVal, \ - typename TLeftOp, \ - typename TRightVal, \ - typename TRightOp, \ - typename F = name ## OpFunctor, \ - typename S = typename std::result_of::type, \ - typename TOp = REACT_IMPL::FunctionOp \ -> \ -auto operator op(TempSignal&& lhs, \ - TempSignal&& rhs) \ - -> TempSignal \ -{ \ - return TempSignal( \ - std::make_shared>( \ - F(), lhs.StealOp(), rhs.StealOp())); \ -} \ - \ -template \ -< \ - typename D, \ - typename TLeftVal, \ - typename TLeftOp, \ - typename TRightSignal, \ - typename TRightVal = typename TRightSignal::ValueT, \ - class = typename std::enable_if< \ - IsSignal::value>::type, \ - typename F = name ## OpFunctor, \ - typename S = typename std::result_of::type, \ - typename TOp = REACT_IMPL::FunctionOp> \ -> \ -auto operator op(TempSignal&& lhs, \ - const TRightSignal& rhs) \ - -> TempSignal \ -{ \ - return TempSignal( \ - std::make_shared>( \ - F(), lhs.StealOp(), GetNodePtr(rhs))); \ -} \ - \ -template \ -< \ - typename TLeftSignal, \ - typename D, \ - typename TRightVal, \ - typename TRightOp, \ - typename TLeftVal = typename TLeftSignal::ValueT, \ - class = typename std::enable_if< \ - IsSignal::value>::type, \ - typename F = name ## OpFunctor, \ - typename S = typename std::result_of::type, \ - typename TOp = REACT_IMPL::FunctionOp, \ - TRightOp> \ -> \ -auto operator op(const TLeftSignal& lhs, TempSignal&& rhs) \ - -> TempSignal \ -{ \ - return TempSignal( \ - std::make_shared>( \ - F(), GetNodePtr(lhs), rhs.StealOp())); \ -} \ - \ -template \ -< \ - typename D, \ - typename TLeftVal, \ - typename TLeftOp, \ - typename TRightValIn, \ - typename TRightVal = typename std::decay::type, \ - class = typename std::enable_if< \ - ! IsSignal::value>::type, \ - typename F = name ## OpLFunctor, \ - typename S = typename std::result_of::type, \ - typename TOp = REACT_IMPL::FunctionOp \ -> \ -auto operator op(TempSignal&& lhs, TRightValIn&& rhs) \ - -> TempSignal \ -{ \ - return TempSignal( \ - std::make_shared>( \ - F( std::forward(rhs) ), lhs.StealOp())); \ -} \ - \ -template \ -< \ - typename TLeftValIn, \ - typename D, \ - typename TRightVal, \ - typename TRightOp, \ - typename TLeftVal = typename std::decay::type, \ - class = typename std::enable_if< \ - ! IsSignal::value>::type, \ - typename F = name ## OpRFunctor, \ - typename S = typename std::result_of::type, \ - typename TOp = REACT_IMPL::FunctionOp \ -> \ -auto operator op(TLeftValIn&& lhs, TempSignal&& rhs) \ - -> TempSignal \ -{ \ - return TempSignal( \ - std::make_shared>( \ - F( std::forward(lhs) ), rhs.StealOp())); \ -} - -REACT_DECLARE_OP(+, Addition) -REACT_DECLARE_OP(-, Subtraction) -REACT_DECLARE_OP(*, Multiplication) -REACT_DECLARE_OP(/, Division) -REACT_DECLARE_OP(%, Modulo) - -REACT_DECLARE_OP(==, Equal) -REACT_DECLARE_OP(!=, NotEqual) -REACT_DECLARE_OP(<, Less) -REACT_DECLARE_OP(<=, LessEqual) -REACT_DECLARE_OP(>, Greater) -REACT_DECLARE_OP(>=, GreaterEqual) - -REACT_DECLARE_OP(&&, LogicalAnd) -REACT_DECLARE_OP(||, LogicalOr) - -REACT_DECLARE_OP(&, BitwiseAnd) -REACT_DECLARE_OP(|, BitwiseOr) -REACT_DECLARE_OP(^, BitwiseXor) -//REACT_DECLARE_OP(<<, BitwiseLeftShift); // MSVC: Internal compiler error -//REACT_DECLARE_OP(>>, BitwiseRightShift); - -#undef REACT_DECLARE_OP -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// Comma operator overload to create signal pack from 2 signals. -/////////////////////////////////////////////////////////////////////////////////////////////////// -template -< - typename D, - typename TLeftVal, - typename TRightVal -> -auto operator,(const Signal& a, const Signal& b) - -> SignalPack -{ - return SignalPack(a, b); +template struct Signal { + using value_type = typename ValueTypeTrait::type; + using ValueT = value_type; + using NodeT = REACT_IMPL::SignalNode; + using NodePtrT = std::shared_ptr; + using DomainT = D; + + Signal() : ptr_{} {} + explicit Signal(NodePtrT p) : ptr_{p} {} + + // Signal(const Signal &) = delete; + // Signal& operator =(const Signal &) = delete; + + // Signal(Signal &&) = default; + // Signal& operator =(Signal &&) = default; + + const value_type &Value() const { return ptr_->ValueRef(); } + const value_type &operator()() const { return Value(); } + + template bool Equals(const Signal &other) const { + return ptr_ == other.ptr_; + } + + const NodePtrT &node_ptr() const { return ptr_; } + + bool Equals(const Signal &other) const { return ptr_ == other.ptr_; } + +protected: + using input_manager_type = REACT_IMPL::InputManager; + + static input_manager_type &input_manager() { + return REACT_IMPL::DomainSpecificInputManager::Instance(); + } + +private: + NodePtrT ptr_; +}; + +template +bool Equals(const Signal &lhs, const Signal &rhs) { + return lhs.Equals(rhs); } /////////////////////////////////////////////////////////////////////////////////////////////////// -/// Comma operator overload to append node to existing signal pack. +/// Operators /////////////////////////////////////////////////////////////////////////////////////////////////// -template -< - typename D, - typename ... TCurValues, - typename TAppendValue -> -auto operator,(const SignalPack& cur, const Signal& append) - -> SignalPack -{ - return SignalPack(cur, append); + +template +auto operator+(const Signal &l, const Signal &r) { + return impl::make_op_signal(std::plus<>(), l, r); } -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// operator->* overload to connect signals to a function and return the resulting signal. -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Single arg -template -< - typename D, - typename F, - template class TSignal, - typename TValue, - class = typename std::enable_if< - IsSignal>::value>::type -> -auto operator->*(const TSignal& arg, F&& func) - -> Signal::type> -{ - return REACT::MakeSignal(arg, std::forward(func)); +template > +auto operator+(const Signal &l, RV &&r) { + return impl::make_op_signal( + std::bind(std::plus<>(), impl::_1, std::forward(r)), l); } -// Multiple args -template -< - typename D, - typename F, - typename ... TValues -> -auto operator->*(const SignalPack& argPack, F&& func) - -> Signal::type> -{ - return REACT::MakeSignal(argPack, std::forward(func)); +template > +auto operator+(LV &&l, const Signal &&r) { + return impl::make_op_signal( + std::bind(std::plus<>(), std::forward(l), impl::_1), r); +} + +template +auto operator-(const Signal &l, const Signal &r) { + return impl::make_op_signal(std::minus<>(), l, r); +} + +template > +auto operator-(const Signal &l, RV &&r) { + return impl::make_op_signal( + std::bind(std::minus<>(), impl::_1, std::forward(r)), l); +} + +template > +auto operator-(LV &&l, const Signal &&r) { + return impl::make_op_signal( + std::bind(std::minus<>(), std::forward(l), impl::_1), r); +} + +template +auto operator*(const Signal &l, const Signal &r) { + return impl::make_op_signal(std::multiplies<>(), l, r); +} + +template > +auto operator*(const Signal &l, RV &&r) { + return impl::make_op_signal( + std::bind(std::multiplies<>(), impl::_1, std::forward(r)), l); +} + +template > +auto operator*(LV &&l, const Signal &&r) { + return impl::make_op_signal( + std::bind(std::multiplies<>(), std::forward(l), impl::_1), r); +} + +template +auto operator/(const Signal &l, const Signal &r) { + return impl::make_op_signal(std::divides<>(), l, r); +} + +template > +auto operator/(const Signal &l, RV &&r) { + return impl::make_op_signal( + std::bind(std::divides<>(), impl::_1, std::forward(r)), l); +} + +template > +auto operator/(LV &&l, const Signal &&r) { + return impl::make_op_signal( + std::bind(std::divides<>(), std::forward(l), impl::_1), r); +} + +template +Signal operator-(const Signal &in) { + return in * S{-1}; +} + +template +const auto &GetNodePtr(const Signal &s) { + return s.node_ptr(); } /////////////////////////////////////////////////////////////////////////////////////////////////// /// Flatten /////////////////////////////////////////////////////////////////////////////////////////////////// -template -< - typename D, - typename TInnerValue -> -auto Flatten(const Signal>& outer) - -> Signal -{ - return Signal( - std::make_shared, TInnerValue>>( - GetNodePtr(outer), GetNodePtr(outer.Value()))); +template +auto Flatten(const Signal &outer) -> Signal { + return Signal( + std::make_shared< + REACT_IMPL::FlattenNode, TInnerValue>>( + GetNodePtr(outer), GetNodePtr(outer.Value()))); } /////////////////////////////////////////////////////////////////////////////////////////////////// -/// Signal +/// VarSignal /////////////////////////////////////////////////////////////////////////////////////////////////// -template -< - typename D, - typename S -> -class Signal : public REACT_IMPL::SignalBase -{ -private: - using NodeT = REACT_IMPL::SignalNode; - using NodePtrT = std::shared_ptr; - -public: - using ValueT = S; - - // Default ctor - Signal() = default; - - // Copy ctor - Signal(const Signal&) = default; - - // Move ctor - Signal(Signal&& other) : - Signal::SignalBase( std::move(other) ) - {} - - // Node ctor - explicit Signal(NodePtrT&& nodePtr) : - Signal::SignalBase( std::move(nodePtr) ) - {} - - // Copy assignment - Signal& operator=(const Signal&) = default; - - // Move assignment - Signal& operator=(Signal&& other) - { - Signal::SignalBase::operator=( std::move(other) ); - return *this; - } - - const S& Value() const { return Signal::SignalBase::getValue(); } - const S& operator()() const { return Signal::SignalBase::getValue(); } - - bool Equals(const Signal& other) const - { - return Signal::SignalBase::Equals(other); - } - - bool IsValid() const - { - return Signal::SignalBase::IsValid(); - } - - void SetWeightHint(WeightHint weight) - { - Signal::SignalBase::SetWeightHint(weight); - } - - S Flatten() const - { - static_assert(IsSignal::value || IsEvent::value, - "Flatten requires a Signal or Events value type."); - return REACT::Flatten(*this); - } -}; -// Specialize for references -template -< - typename D, - typename S -> -class Signal : public REACT_IMPL::SignalBase> -{ -private: - using NodeT = REACT_IMPL::SignalNode>; - using NodePtrT = std::shared_ptr; - -public: - using ValueT = S; - - // Default ctor - Signal() = default; - - // Copy ctor - Signal(const Signal&) = default; - - // Move ctor - Signal(Signal&& other) : - Signal::SignalBase( std::move(other) ) - {} - - // Node ctor - explicit Signal(NodePtrT&& nodePtr) : - Signal::SignalBase( std::move(nodePtr) ) - {} - - // Copy assignment - Signal& operator=(const Signal&) = default; - - // Move assignment - Signal& operator=(Signal&& other) - { - Signal::SignalBase::operator=( std::move(other) ); - return *this; - } - - const S& Value() const { return Signal::SignalBase::getValue(); } - const S& operator()() const { return Signal::SignalBase::getValue(); } - - bool Equals(const Signal& other) const - { - return Signal::SignalBase::Equals(other); - } - - bool IsValid() const - { - return Signal::SignalBase::IsValid(); - } - - void SetWeightHint(WeightHint weight) - { - Signal::SignalBase::SetWeightHint(weight); - } -}; +template struct VarSignal : Signal { + using NodeT = REACT_IMPL::VarNode; + using NodePtrT = std::shared_ptr; + using typename Signal::value_type; -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// VarSignal -/////////////////////////////////////////////////////////////////////////////////////////////////// -template -< - typename D, - typename S -> -class VarSignal : public Signal -{ -private: - using NodeT = REACT_IMPL::VarNode; - using NodePtrT = std::shared_ptr; - -public: - // Default ctor - VarSignal() = default; - - // Copy ctor - VarSignal(const VarSignal&) = default; - - // Move ctor - VarSignal(VarSignal&& other) : - VarSignal::Signal( std::move(other) ) - {} - - // Node ctor - explicit VarSignal(NodePtrT&& nodePtr) : - VarSignal::Signal( std::move(nodePtr) ) - {} - - // Copy assignment - VarSignal& operator=(const VarSignal&) = default; - - // Move assignment - VarSignal& operator=(VarSignal&& other) - { - VarSignal::SignalBase::operator=( std::move(other) ); - return *this; - } - - void Set(const S& newValue) const - { - VarSignal::SignalBase::setValue(newValue); - } - - void Set(S&& newValue) const - { - VarSignal::SignalBase::setValue(std::move(newValue)); - } - - const VarSignal& operator<<=(const S& newValue) const - { - VarSignal::SignalBase::setValue(newValue); - return *this; - } - - const VarSignal& operator<<=(S&& newValue) const - { - VarSignal::SignalBase::setValue(std::move(newValue)); - return *this; - } - - template - void Modify(const F& func) const - { - VarSignal::SignalBase::modifyValue(func); - } -}; + explicit VarSignal(NodePtrT nodePtr) : Signal{nodePtr} {} + + void Set(const value_type &newValue) const { + Signal::input_manager().AddInput(var_node(), newValue); + } + + void Set(value_type &&newValue) const { + Signal::input_manager().AddInput(var_node(), std::move(newValue)); + } + + const VarSignal &operator<<=(const value_type &newValue) const { + Set(newValue); + return *this; + } + + const VarSignal &operator<<=(value_type &&newValue) const { + Set(std::move(newValue)); + return *this; + } + + template void Modify(const F &func) const { + Signal::input_manager().ModifyInput(var_node(), func); + } -// Specialize for references -template -< - typename D, - typename S -> -class VarSignal : public Signal> -{ private: - using NodeT = REACT_IMPL::VarNode>; - using NodePtrT = std::shared_ptr; - -public: - using ValueT = S; - - // Default ctor - VarSignal() = default; - - // Copy ctor - VarSignal(const VarSignal&) = default; - - // Move ctor - VarSignal(VarSignal&& other) : - VarSignal::Signal( std::move(other) ) - {} - - // Node ctor - explicit VarSignal(NodePtrT&& nodePtr) : - VarSignal::Signal( std::move(nodePtr) ) - {} - - // Copy assignment - VarSignal& operator=(const VarSignal&) = default; - - // Move assignment - VarSignal& operator=(VarSignal&& other) - { - VarSignal::Signal::operator=( std::move(other) ); - return *this; - } - - void Set(std::reference_wrapper newValue) const - { - VarSignal::SignalBase::setValue(newValue); - } - - const VarSignal& operator<<=(std::reference_wrapper newValue) const - { - VarSignal::SignalBase::setValue(newValue); - return *this; - } + NodeT &var_node() const { + return *std::static_pointer_cast(this->node_ptr()); + } }; /////////////////////////////////////////////////////////////////////////////////////////////////// -/// TempSignal +/// Comma operator overload to create signal pack from 2 signals. /////////////////////////////////////////////////////////////////////////////////////////////////// -template -< - typename D, - typename S, - typename TOp -> -class TempSignal : public Signal -{ -private: - using NodeT = REACT_IMPL::SignalOpNode; - using NodePtrT = std::shared_ptr; - -public: - // Default ctor - TempSignal() = default; - - // Copy ctor - TempSignal(const TempSignal&) = default; - - // Move ctor - TempSignal(TempSignal&& other) : - TempSignal::Signal( std::move(other) ) - {} - - // Node ctor - explicit TempSignal(NodePtrT&& ptr) : - TempSignal::Signal( std::move(ptr) ) - {} - - // Copy assignment - TempSignal& operator=(const TempSignal&) = default; - - // Move assignemnt - TempSignal& operator=(TempSignal&& other) - { - TempSignal::Signal::operator=( std::move(other) ); - return *this; - } - - TOp StealOp() - { - return std::move(reinterpret_cast(this->ptr_.get())->StealOp()); - } -}; +template +auto operator,(const Signal &a, const Signal &b) { + return SignalPack, Signal>{a, b}; +} -/******************************************/ REACT_END /******************************************/ +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// Comma operator overload to append node to existing signal pack. +/////////////////////////////////////////////////////////////////////////////////////////////////// +template +auto operator,(const SignalPack &cur, + const Signal &append) { + return SignalPack>{cur, append}; +} -/***************************************/ REACT_IMPL_BEGIN /**************************************/ +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// operator->* overload to connect signals to a function and return the +/// resulting signal. +/////////////////////////////////////////////////////////////////////////////////////////////////// -template -bool Equals(const Signal& lhs, const Signal& rhs) -{ - return lhs.Equals(rhs); +// Single arg +template +auto operator->*(const Signal &arg, F &&func) { + return MakeSignal(arg, std::forward(func)); } -/****************************************/ REACT_IMPL_END /***************************************/ +// Multiple args +template +auto operator->*(const SignalPack &argPack, F &&func) { + return MakeSignal(argPack, std::forward(func)); +} +} /////////////////////////////////////////////////////////////////////////////////////////////////// /// Flatten macros /////////////////////////////////////////////////////////////////////////////////////////////////// -// Note: Using static_cast rather than -> return type, because when using lambda for inline +// Note: Using static_cast rather than -> return type, because when using lambda +// for inline // class initialization, decltype did not recognize the parameter r // Note2: MSVC doesn't like typename in the lambda #if _MSC_VER && !__INTEL_COMPILER - #define REACT_MSVC_NO_TYPENAME +#define REACT_MSVC_NO_TYPENAME #else - #define REACT_MSVC_NO_TYPENAME typename +#define REACT_MSVC_NO_TYPENAME typename #endif -#define REACTIVE_REF(obj, name) \ - Flatten( \ - MakeSignal( \ - obj, \ - [] (const REACT_MSVC_NO_TYPENAME \ - REACT_IMPL::Identity::Type::ValueT& r) \ - { \ - using T = decltype(r.name); \ - using S = REACT_MSVC_NO_TYPENAME REACT::DecayInput::Type; \ - return static_cast(r.name); \ - })) - -#define REACTIVE_PTR(obj, name) \ - Flatten( \ - MakeSignal( \ - obj, \ - [] (REACT_MSVC_NO_TYPENAME \ - REACT_IMPL::Identity::Type::ValueT r) \ - { \ - assert(r != nullptr); \ - using T = decltype(r->name); \ - using S = REACT_MSVC_NO_TYPENAME REACT::DecayInput::Type; \ - return static_cast(r->name); \ - })) - -#endif // REACT_SIGNAL_H_INCLUDED \ No newline at end of file +#define REACTIVE_REF(obj, name) \ + Flatten(MakeSignal( \ + obj, [](const REACT_MSVC_NO_TYPENAME REACT_IMPL::Identity::Type::ValueT &r) { return r.name; })) + +#define REACTIVE_PTR(obj, name) \ + Flatten(MakeSignal( \ + obj, [](REACT_MSVC_NO_TYPENAME \ + REACT_IMPL::Identity::Type::ValueT r) { \ + assert(r != nullptr); \ + using T = decltype(r->name); \ + using S = REACT_MSVC_NO_TYPENAME REACT::DecayInput::Type; \ + return static_cast(r->name); \ + })) + +#endif // REACT_SIGNAL_H_INCLUDED diff --git a/include/react/TypeTraits.h b/include/react/TypeTraits.h index c6b6b7dd..6f46fd14 100644 --- a/include/react/TypeTraits.h +++ b/include/react/TypeTraits.h @@ -11,37 +11,9 @@ #include "react/detail/Defs.h" -/*****************************************/ REACT_BEGIN /*****************************************/ - -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// Forward declarations -/////////////////////////////////////////////////////////////////////////////////////////////////// -template -class Signal; - -template -class VarSignal; - -template -class TempSignal; - -template -class Events; +#include "react/Forward.h" -template -class EventSource; - -template -class TempEvents; - -template -class Observer; - -template -class ScopedObserver; - -template -class Continuation; +/*****************************************/ REACT_BEGIN /*****************************************/ /////////////////////////////////////////////////////////////////////////////////////////////////// /// IsSignal @@ -56,7 +28,7 @@ template struct IsSignal> { static const bool value = true; }; template -struct IsSignal> { static const bool value = true; }; +struct IsSignal> { static const bool value = true; }; /////////////////////////////////////////////////////////////////////////////////////////////////// /// IsEvent @@ -107,7 +79,7 @@ template struct IsObservable> { static const bool value = true; }; template -struct IsObservable> { static const bool value = true; }; +struct IsObservable> { static const bool value = true; }; template struct IsObservable> { static const bool value = true; }; @@ -131,7 +103,7 @@ template struct IsReactive> { static const bool value = true; }; template -struct IsReactive> { static const bool value = true; }; +struct IsReactive> { static const bool value = true; }; template struct IsReactive> { static const bool value = true; }; @@ -165,4 +137,4 @@ struct DecayInput> { using Type = Events; }; /******************************************/ REACT_END /******************************************/ -#endif // REACT_TYPETRAITS_H_INCLUDED \ No newline at end of file +#endif // REACT_TYPETRAITS_H_INCLUDED diff --git a/include/react/common/Util.h b/include/react/common/Util.h index 39741ed7..b50b852f 100644 --- a/include/react/common/Util.h +++ b/include/react/common/Util.h @@ -22,62 +22,18 @@ /// http://stackoverflow.com/questions/687490/how-do-i-expand-a-tuple-into-variadic-template-functions-arguments /////////////////////////////////////////////////////////////////////////////////////////////////// -template -struct Apply { - template - static inline auto apply(F && f, T && t, A &&... a) - -> decltype(Apply::apply(std::forward(f), std::forward(t), std::get(std::forward(t)), std::forward(a)...)) - { - return Apply::apply(std::forward(f), std::forward(t), std::get(std::forward(t)), std::forward(a)...); - } -}; - -template<> -struct Apply<0> -{ - template - static inline auto apply(F && f, T &&, A &&... a) - -> decltype(std::forward(f)(std::forward(a)...)) - { - return std::forward(f)(std::forward(a)...); - } -}; - -template -inline auto apply(F && f, T && t) - -> decltype(Apply::type>::value>::apply(std::forward(f), std::forward(t))) -{ - return Apply::type>::value> - ::apply(std::forward(f), std::forward(t)); +template +auto apply_impl(F&& f, Tuple&& t, std::index_sequence) { + return std::forward(f)(std::get(std::forward(t))...); } -template -struct ApplyMemberFn { - template - static inline auto apply(O obj, F f, T && t, A &&... a) - -> decltype(ApplyMemberFn::apply(obj, f, std::forward(t), std::get(std::forward(t)), std::forward(a)...)) - { - return ApplyMemberFn::apply(obj, f, std::forward(t), std::get(std::forward(t)), std::forward(a)...); - } -}; +template +using indices_t = std::make_index_sequence>::value>; -template<> -struct ApplyMemberFn<0> -{ - template - static inline auto apply(O obj, F f, T &&, A &&... a) - -> decltype((obj->*f)(std::forward(a)...)) - { - return (obj->*f)(std::forward(a)...); - } -}; -template -inline auto applyMemberFn(O obj, F f, T&& t) - -> decltype(ApplyMemberFn::type>::value>::apply(obj, f, std::forward(t))) -{ - return ApplyMemberFn::type>::value> - ::apply(obj, f, std::forward(t)); +template +auto apply(F&& f, Tuple&& t) { + return apply_impl(std::forward(f), std::forward(t), indices_t()); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -228,4 +184,4 @@ class IsCallableWith // Use comma operator to replace potential void return value with 0 #define REACT_EXPAND_PACK(...) REACT_IMPL::pass((__VA_ARGS__ , 0) ...) -#endif // REACT_COMMON_UTIL_H_INCLUDED \ No newline at end of file +#endif // REACT_COMMON_UTIL_H_INCLUDED diff --git a/include/react/detail/DomainBase.h b/include/react/detail/DomainBase.h index 67c7e8ae..a21f6dc1 100644 --- a/include/react/detail/DomainBase.h +++ b/include/react/detail/DomainBase.h @@ -28,6 +28,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// /// Forward declarations /////////////////////////////////////////////////////////////////////////////////////////////////// + template class Signal; @@ -262,4 +263,4 @@ class DomainInitializer /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_DETAIL_DOMAINBASE_H_INCLUDED \ No newline at end of file +#endif // REACT_DETAIL_DOMAINBASE_H_INCLUDED diff --git a/include/react/detail/graph/SignalNodes.h b/include/react/detail/graph/SignalNodes.h index eb438a0c..a71cfca9 100644 --- a/include/react/detail/graph/SignalNodes.h +++ b/include/react/detail/graph/SignalNodes.h @@ -35,12 +35,12 @@ template class SignalNode : public ObservableNode { public: + // TODO why ? SignalNode() = default; template explicit SignalNode(T&& value) : - SignalNode::ObservableNode( ), - value_( std::forward(value) ) + value_{std::forward(value)} {} const S& ValueRef() const @@ -73,6 +73,7 @@ class VarNode : template VarNode(T&& value) : VarNode::SignalNode( std::forward(value) ), + // TODO assign newValue_ with value ? value is moved-from just above newValue_( value ) { Engine::OnNodeCreate(*this); @@ -383,4 +384,4 @@ class FlattenNode : public SignalNode /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_DETAIL_GRAPH_SIGNALNODES_H_INCLUDED \ No newline at end of file +#endif // REACT_DETAIL_GRAPH_SIGNALNODES_H_INCLUDED diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1733e9a8..68a19d05 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,13 +16,13 @@ function(cppreact_test) add_test(NAME ${cppreact_test_NAME} COMMAND ${cppreact_test_NAME}) endfunction(cppreact_test) -cppreact_test(NAME EventStreamTest SOURCES src/EventStreamTest.cpp) -cppreact_test(NAME EventStreamTestQ SOURCES src/EventStreamTestQ.cpp) +#cppreact_test(NAME EventStreamTest SOURCES src/EventStreamTest.cpp) +#cppreact_test(NAME EventStreamTestQ SOURCES src/EventStreamTestQ.cpp) cppreact_test(NAME MoveTest SOURCES src/MoveTest.cpp) -cppreact_test(NAME ObserverTest SOURCES src/ObserverTest.cpp) -cppreact_test(NAME ObserverTestQ SOURCES src/ObserverTestQ.cpp) -cppreact_test(NAME OperationsTest SOURCES src/OperationsTest.cpp) -cppreact_test(NAME OperationsTestQ SOURCES src/OperationsTestQ.cpp) +#cppreact_test(NAME ObserverTest SOURCES src/ObserverTest.cpp) +#cppreact_test(NAME ObserverTestQ SOURCES src/ObserverTestQ.cpp) +#cppreact_test(NAME OperationsTest SOURCES src/OperationsTest.cpp) +#cppreact_test(NAME OperationsTestQ SOURCES src/OperationsTestQ.cpp) cppreact_test(NAME SignalTest SOURCES src/SignalTest.cpp) cppreact_test(NAME SignalTestQ SOURCES src/SignalTestQ.cpp) -cppreact_test(NAME TransactionTest SOURCES src/TransactionTest.cpp) +#cppreact_test(NAME TransactionTest SOURCES src/TransactionTest.cpp) diff --git a/tests/src/SignalTest.h b/tests/src/SignalTest.h index 8d7a34e2..149c329e 100644 --- a/tests/src/SignalTest.h +++ b/tests/src/SignalTest.h @@ -62,6 +62,77 @@ TYPED_TEST_P(SignalTest, MakeVars) ASSERT_EQ(v4(),40); } +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// Signals0 tests +/////////////////////////////////////////////////////////////////////////////////////////////////// +TYPED_TEST_P(SignalTest, Signals00) +{ + using D = typename Signals00::MyDomain; + + auto v1 = MakeVar(1); + auto v2 = MakeVar(2); + + auto s1 = MakeSignal(With(v1,v2), [] (int a, int b) { + return a + b; + }); + + ASSERT_EQ(s1(),3); +} + +TYPED_TEST_P(SignalTest, Signals01) +{ + using D = typename Signals01::MyDomain; + + auto v1 = MakeVar(1); + auto v2 = MakeVar(2); + + auto s1 = MakeSignal(With(v1,v2), [] (int a, int b) { + return a + b; + }); + + auto v3 = MakeVar(3); + + auto s2 = MakeSignal(With(s1,v3), [] (int a, int b) { + return a + b; + }); + + ASSERT_EQ(s2(),6); +} + +TYPED_TEST_P(SignalTest, Signals02) +{ + using D = typename Signals02::MyDomain; + + auto v1 = MakeVar(1); + auto v2 = MakeVar(2); + + auto s1 = MakeSignal(With(v1,v2), [] (int a, int b) { + return a + b; + }); + + auto v3 = MakeVar(3); + + ASSERT_EQ((s1 + v3)(),6); +} + +TYPED_TEST_P(SignalTest, Signals03) +{ + using D = typename Signals03::MyDomain; + + auto v1 = MakeVar(1); + auto v2 = MakeVar(2); + + auto s1 = MakeSignal(With(v1,v2), [] (int a, int b) { + return a + b; + }); + + auto v3 = MakeVar(3); + + auto s2 = s1 + v3; + + ASSERT_EQ(s2(),6); +} + /////////////////////////////////////////////////////////////////////////////////////////////////// /// Signals1 test /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -274,6 +345,79 @@ TYPED_TEST_P(SignalTest, Signals4) ASSERT_EQ(b2(),12); } +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// Plus tests +/////////////////////////////////////////////////////////////////////////////////////////////////// +TYPED_TEST_P(SignalTest, Plus100) +{ + using D = typename Plus100::MyDomain; + + auto a = MakeVar(1); + + auto b = a + 100; + ASSERT_EQ(b(),101); + + a <<= 10; + ASSERT_EQ(b(),110); +} + +TYPED_TEST_P(SignalTest, UnaryMinus) +{ + using D = typename UnaryMinus::MyDomain; + + auto a = MakeVar(1); + + auto b = -a; + ASSERT_EQ(b(),-1); + + a <<= 10; + ASSERT_EQ(b(),-10); +} + +TYPED_TEST_P(SignalTest, UnaryMinusThenPlus100) +{ + using D = typename UnaryMinusThenPlus100::MyDomain; + + auto a = MakeVar(1); + + auto b = -a; + ASSERT_EQ(b(),-1); + + auto c = b + 100; + ASSERT_EQ(b(),-1); + ASSERT_EQ(c(),99); + + a <<= 10; + ASSERT_EQ(b(),-10); + ASSERT_EQ(c(),90); +} + +TYPED_TEST_P(SignalTest, Plus10Plus100) +{ + using D = typename Plus10Plus100::MyDomain; + + auto a = MakeVar(1); + + auto b = a + 10 + 100; + ASSERT_EQ(111, b()); + + a <<= 10; + ASSERT_EQ(120, b()); +} + +TYPED_TEST_P(SignalTest, UnaryMinusPlus100) +{ + using D = typename UnaryMinusPlus100::MyDomain; + + auto a = MakeVar(1); + + auto b = -a + 100; + ASSERT_EQ(b(),99); + + a <<= 10; + ASSERT_EQ(b(),90); +} + /////////////////////////////////////////////////////////////////////////////////////////////////// /// FunctionBind1 test /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -459,7 +603,7 @@ TYPED_TEST_P(SignalTest, Flatten3) auto result = flattened + a0; - ASSERT_EQ(result(), 10 + 30); + ASSERT_EQ(10 + 30, result()); ASSERT_EQ(observeCount, 0); DoTransaction([&] { @@ -536,7 +680,7 @@ TYPED_TEST_P(SignalTest, Member1) auto outer = MakeVar(10); auto inner = MakeVar(outer); - auto flattened = inner.Flatten(); + auto flattened = Flatten(inner); Observe(flattened, [] (int v) { ASSERT_EQ(v, 30); @@ -653,7 +797,9 @@ REGISTER_TYPED_TEST_CASE_P ( SignalTest, MakeVars, + Signals00, Signals01, Signals02, Signals03, Signals1, Signals2, Signals3, Signals4, + Plus100, UnaryMinusThenPlus100, Plus10Plus100, UnaryMinus,UnaryMinusPlus100, FunctionBind1, FunctionBind2, Flatten1, Flatten2, Flatten3, Flatten4, Member1, From e4324a14259a29c0103583b729c1ee26fe0805b4 Mon Sep 17 00:00:00 2001 From: Ivan Le Lann Date: Wed, 1 Jun 2016 22:38:02 +0200 Subject: [PATCH 3/3] more test OK, zero copy, no default constructible --- include/react/Signal.h | 33 ++++++------ include/react/detail/graph/AlgorithmNodes.h | 2 +- .../react/detail/graph/ContinuationNodes.h | 2 +- include/react/detail/graph/GraphBase.h | 2 +- include/react/detail/graph/SignalNodes.h | 50 +++++++++++-------- tests/CMakeLists.txt | 2 +- tests/src/MoveTest.h | 33 +++--------- 7 files changed, 57 insertions(+), 67 deletions(-) diff --git a/include/react/Signal.h b/include/react/Signal.h index d165dd0e..578fc0ac 100644 --- a/include/react/Signal.h +++ b/include/react/Signal.h @@ -70,13 +70,14 @@ template struct DomainTrait> { template using functor_t = FunctionOp; -template -using signal_node_t = SignalOpNode...>>; +template +using signal_op_node_t = SignalOpNode; template -auto make_node(F &&f, Args &&... args) { - return std::make_shared>( - std::forward(f), std::forward(args)...); +auto make_op_node(F &&f, Args &&... args) { + using TOp = functor_t...>; + return std::make_shared>( + TOp{std::forward(f), std::forward(args)...}); } template @@ -84,7 +85,7 @@ auto make_op_signal(F &&f, TSignals &&... args) { using D = domain_t; using S = std::result_of_t...)>; - return Signal{make_node( + return Signal{make_op_node( std::forward(f), GetNodePtr(std::forward(args))...)}; } @@ -155,14 +156,14 @@ template , typename S = std::result_of_t> auto MakeSignal(const Signal &arg, FIn &&func) { return Signal( - impl::make_node(std::forward(func), GetNodePtr(arg))); + impl::make_op_node(std::forward(func), GetNodePtr(arg))); } // Multiple args template auto MakeNode(F &&f, const Tuple &tuple, std::index_sequence) { - return impl::make_node(std::forward(f), - GetNodePtr(std::get(tuple))...); + return impl::make_op_node(std::forward(f), + GetNodePtr(std::get(tuple))...); } // Multiple args @@ -177,7 +178,7 @@ auto MakeSignal(const SignalPack &argPack, FIn &&func) { } /////////////////////////////////////////////////////////////////////////////////////////////////// -/// Utils +/// ValueTypeTrait /////////////////////////////////////////////////////////////////////////////////////////////////// template struct ValueTypeTrait { using type = S; }; @@ -198,7 +199,7 @@ template struct Signal { using DomainT = D; Signal() : ptr_{} {} - explicit Signal(NodePtrT p) : ptr_{p} {} + explicit Signal(NodePtrT p) : ptr_{std::move(p)} {} // Signal(const Signal &) = delete; // Signal& operator =(const Signal &) = delete; @@ -251,7 +252,7 @@ auto operator+(const Signal &l, RV &&r) { template > -auto operator+(LV &&l, const Signal &&r) { +auto operator+(LV &&l, const Signal &r) { return impl::make_op_signal( std::bind(std::plus<>(), std::forward(l), impl::_1), r); } @@ -270,7 +271,7 @@ auto operator-(const Signal &l, RV &&r) { template > -auto operator-(LV &&l, const Signal &&r) { +auto operator-(LV &&l, const Signal &r) { return impl::make_op_signal( std::bind(std::minus<>(), std::forward(l), impl::_1), r); } @@ -289,7 +290,7 @@ auto operator*(const Signal &l, RV &&r) { template > -auto operator*(LV &&l, const Signal &&r) { +auto operator*(LV &&l, const Signal &r) { return impl::make_op_signal( std::bind(std::multiplies<>(), std::forward(l), impl::_1), r); } @@ -308,14 +309,14 @@ auto operator/(const Signal &l, RV &&r) { template > -auto operator/(LV &&l, const Signal &&r) { +auto operator/(LV &&l, const Signal &r) { return impl::make_op_signal( std::bind(std::divides<>(), std::forward(l), impl::_1), r); } template Signal operator-(const Signal &in) { - return in * S{-1}; + return S{-1} * in; } template diff --git a/include/react/detail/graph/AlgorithmNodes.h b/include/react/detail/graph/AlgorithmNodes.h index 454fdfbb..fbddf824 100644 --- a/include/react/detail/graph/AlgorithmNodes.h +++ b/include/react/detail/graph/AlgorithmNodes.h @@ -657,4 +657,4 @@ class PulseNode : public EventStreamNode /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_DETAIL_GRAPH_ALGORITHMNODES_H_INCLUDED \ No newline at end of file +#endif // REACT_DETAIL_GRAPH_ALGORITHMNODES_H_INCLUDED diff --git a/include/react/detail/graph/ContinuationNodes.h b/include/react/detail/graph/ContinuationNodes.h index c841d23f..f5a55331 100644 --- a/include/react/detail/graph/ContinuationNodes.h +++ b/include/react/detail/graph/ContinuationNodes.h @@ -348,4 +348,4 @@ class SyncedContinuationNode : public ContinuationNode /****************************************/ REACT_IMPL_END /***************************************/ -#endif // REACT_DETAIL_GRAPH_CONTINUATIONNODES_H_INCLUDED \ No newline at end of file +#endif // REACT_DETAIL_GRAPH_CONTINUATIONNODES_H_INCLUDED diff --git a/include/react/detail/graph/GraphBase.h b/include/react/detail/graph/GraphBase.h index 31e8c481..bd0e8a81 100644 --- a/include/react/detail/graph/GraphBase.h +++ b/include/react/detail/graph/GraphBase.h @@ -199,7 +199,7 @@ template class ReactiveOpBase { public: - using DepHolderT = std::tuple; + using DepHolderT = std::tuple...>; template ReactiveOpBase(DontMove, TDepsIn&& ... deps) : diff --git a/include/react/detail/graph/SignalNodes.h b/include/react/detail/graph/SignalNodes.h index a71cfca9..5accd3c7 100644 --- a/include/react/detail/graph/SignalNodes.h +++ b/include/react/detail/graph/SignalNodes.h @@ -13,6 +13,7 @@ #include #include +#include #include "GraphBase.h" @@ -35,8 +36,6 @@ template class SignalNode : public ObservableNode { public: - // TODO why ? - SignalNode() = default; template explicit SignalNode(T&& value) : @@ -72,9 +71,7 @@ class VarNode : public: template VarNode(T&& value) : - VarNode::SignalNode( std::forward(value) ), - // TODO assign newValue_ with value ? value is moved-from just above - newValue_( value ) + VarNode::SignalNode( std::forward(value) ) { Engine::OnNodeCreate(*this); } @@ -96,7 +93,7 @@ class VarNode : template void AddInput(V&& newValue) { - newValue_ = std::forward(newValue); + pushNewValue(std::forward(newValue)); isInputAdded_ = true; @@ -121,7 +118,7 @@ class VarNode : // in ApplyInput else { - func(newValue_); + func(getNewValue()); } } @@ -134,9 +131,9 @@ class VarNode : { isInputAdded_ = false; - if (! Equals(this->value_, newValue_)) + if (! Equals(this->value_, getNewValue())) { - this->value_ = std::move(newValue_); + popNewValue(); Engine::OnInputChange(*this, turn); return true; } @@ -160,7 +157,26 @@ class VarNode : } private: - S newValue_; + + S & getNewValue() + { + return *reinterpret_cast(newValueData); + } + + template + void pushNewValue(V && v) + { + new (newValueData) S{std::forward(v)}; + } + + void popNewValue() + { + this->value_ = std::move(*reinterpret_cast(newValueData)); + } + + // so that we don't require S to be default constructible + std::aligned_storage_t newValueData[1]; + bool isInputAdded_ = false; bool isInputModified_ = false; }; @@ -183,11 +199,6 @@ class FunctionOp : public ReactiveOpBase func_( std::forward(func) ) {} - FunctionOp(FunctionOp&& other) : - FunctionOp::ReactiveOpBase( std::move(other) ), - func_( std::move(other.func_) ) - {} - S Evaluate() { return apply(EvalFunctor( func_ ), this->deps_); @@ -239,13 +250,10 @@ class SignalOpNode : using Engine = typename SignalOpNode::Engine; public: - template - SignalOpNode(TArgs&& ... args) : - SignalOpNode::SignalNode( ), - op_( std::forward(args) ... ) + explicit SignalOpNode(TOp op) : + SignalOpNode::SignalNode{op.Evaluate()}, + op_{std::move(op)} { - this->value_ = op_.Evaluate(); - Engine::OnNodeCreate(*this); op_.template Attach(*this); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 68a19d05..a598d76e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,7 +19,7 @@ endfunction(cppreact_test) #cppreact_test(NAME EventStreamTest SOURCES src/EventStreamTest.cpp) #cppreact_test(NAME EventStreamTestQ SOURCES src/EventStreamTestQ.cpp) cppreact_test(NAME MoveTest SOURCES src/MoveTest.cpp) -#cppreact_test(NAME ObserverTest SOURCES src/ObserverTest.cpp) +cppreact_test(NAME ObserverTest SOURCES src/ObserverTest.cpp) #cppreact_test(NAME ObserverTestQ SOURCES src/ObserverTestQ.cpp) #cppreact_test(NAME OperationsTest SOURCES src/OperationsTest.cpp) #cppreact_test(NAME OperationsTestQ SOURCES src/OperationsTestQ.cpp) diff --git a/tests/src/MoveTest.h b/tests/src/MoveTest.h index 46e1d39d..960df6ab 100644 --- a/tests/src/MoveTest.h +++ b/tests/src/MoveTest.h @@ -30,7 +30,6 @@ class MoveTest : public testing::Test struct Stats { - int copyCount = 0; int moveCount = 0; }; @@ -39,19 +38,13 @@ class MoveTest : public testing::Test int v = 0; Stats* stats = nullptr; - CopyCounter() = default; - CopyCounter(int x, Stats* s) : v( x ), stats( s ) {} - CopyCounter(const CopyCounter& other) : - v( other.v ), - stats( other.stats ) - { - stats->copyCount++; - } + CopyCounter(const CopyCounter& other) = delete; + CopyCounter& operator=(const CopyCounter& other) = delete; CopyCounter(CopyCounter&& other) : v( other.v ), @@ -60,14 +53,6 @@ class MoveTest : public testing::Test stats->moveCount++; } - CopyCounter& operator=(const CopyCounter& other) - { - v = other.v; - stats = other.stats; - stats->copyCount++; - return *this; - } - CopyCounter& operator=(CopyCounter&& other) { v = other.v; @@ -107,21 +92,17 @@ TYPED_TEST_P(MoveTest, Copy1) auto d = MakeVar(CopyCounter{1000,&stats1}); // 4x move to value_ - // 4x copy to newValue_ (can't be unitialized for references) - ASSERT_EQ(stats1.copyCount, 4); - ASSERT_EQ(stats1.moveCount, 4); + ASSERT_EQ(4, stats1.moveCount); auto x = a + b + c + d; - ASSERT_EQ(stats1.copyCount, 4); - ASSERT_EQ(stats1.moveCount, 7); - ASSERT_EQ(x().v, 1111); + ASSERT_EQ(7, stats1.moveCount); + ASSERT_EQ(1111, x().v); a <<= CopyCounter{2,&stats1}; - ASSERT_EQ(stats1.copyCount, 4); - ASSERT_EQ(stats1.moveCount, 10); - ASSERT_EQ(x().v, 1112); + ASSERT_EQ(10, stats1.moveCount); + ASSERT_EQ(1112, x().v); } ///////////////////////////////////////////////////////////////////////////////////////////////////