From 7c98a14ed92099ba47f9dd11819b7e6a5e43e9f0 Mon Sep 17 00:00:00 2001 From: MerlinXYoung Date: Tue, 5 May 2020 09:40:19 +0800 Subject: [PATCH] build ok --- .gitignore | 2 +- CMakeLists.txt | 5 ++++- examples/CMakeLists.txt | 8 +++---- examples/src/BasicAlgorithms.cpp | 7 ++++++ examples/src/BasicEvents.cpp | 4 ++-- include/react/common/ptrcache.h | 2 +- include/react/common/slotmap.h | 2 +- include/react/detail/algorithm_nodes.h | 14 ++++++------ include/react/detail/event_nodes.h | 25 +++++++++++---------- include/react/detail/graph_impl.h | 4 ++-- include/react/detail/observer_nodes.h | 10 ++++----- include/react/detail/state_nodes.h | 13 ++++++----- include/react/event.h | 31 +++++++++++++++++--------- include/react/group.h | 2 +- include/react/observer.h | 8 +++---- include/react/state.h | 20 ++++++++++------- 16 files changed, 91 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index 91d07955..1a77098d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. - +.vscode/ # User-specific files *.suo *.user diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b6477a8..c94f0b37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,10 +7,13 @@ 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++17 -Wall -Wpedantic -Wno-#pragma-messages -Wno-unused-variable") include_directories ("${PROJECT_SOURCE_DIR}/include") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/3rd/oneTBB/include") +link_directories("${CMAKE_CURRENT_SOURCE_DIR}/3rd/oneTBB/build/linux_intel64_gcc_cc7.4.0_libc2.27_kernel4.4.0_release") + ### CppReact add_library(CppReact src/detail/graph_impl.cpp) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 417819a0..7fa87c13 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,8 +3,8 @@ 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) @@ -23,5 +23,5 @@ add_executable(Example_BasicSynchronization src/BasicSynchronization.cpp) target_link_libraries(Example_BasicSynchronization CppReact) ### Example_Sandbox -add_executable(Example_Sandbox src/Main.cpp) -target_link_libraries(Example_Sandbox CppReact) +# add_executable(Example_Sandbox src/Main.cpp) +# target_link_libraries(Example_Sandbox CppReact) diff --git a/examples/src/BasicAlgorithms.cpp b/examples/src/BasicAlgorithms.cpp index 7829049c..b3c65926 100644 --- a/examples/src/BasicAlgorithms.cpp +++ b/examples/src/BasicAlgorithms.cpp @@ -69,6 +69,9 @@ namespace example2 { StateVar name = StateVar::Create(g, string( "Bob" )); StateVar salary = StateVar::Create(g, 66666); + bool operator==(const Employee& other)const{ + return name == other.name && salary == other.salary; + } }; void Run() @@ -486,6 +489,10 @@ class Employee struct Flat; + bool operator==(const Employee& other)const{ + return name == other.name && office == other.office; + } + private: }; diff --git a/examples/src/BasicEvents.cpp b/examples/src/BasicEvents.cpp index 98fe1ef3..bc9c825a 100644 --- a/examples/src/BasicEvents.cpp +++ b/examples/src/BasicEvents.cpp @@ -8,8 +8,8 @@ #include #include -#include "react/Event.h" -#include "react/Observer.h" +#include "react/event.h" +#include "react/observer.h" /////////////////////////////////////////////////////////////////////////////////////////////////// /// Example 1 - Hello world diff --git a/include/react/common/ptrcache.h b/include/react/common/ptrcache.h index 355ae2a2..b892da7e 100644 --- a/include/react/common/ptrcache.h +++ b/include/react/common/ptrcache.h @@ -9,7 +9,7 @@ #pragma once -#include "react/detail/Defs.h" +#include "react/detail/defs.h" #include #include diff --git a/include/react/common/slotmap.h b/include/react/common/slotmap.h index 19578e59..5089df18 100644 --- a/include/react/common/slotmap.h +++ b/include/react/common/slotmap.h @@ -9,7 +9,7 @@ #pragma once -#include "react/detail/Defs.h" +#include "react/detail/defs.h" #include #include diff --git a/include/react/detail/algorithm_nodes.h b/include/react/detail/algorithm_nodes.h index d730f51c..82fa7e1e 100644 --- a/include/react/detail/algorithm_nodes.h +++ b/include/react/detail/algorithm_nodes.h @@ -120,7 +120,7 @@ class SyncedIterateNode : public StateNode ~SyncedIterateNode() { - apply([this] (const auto& ... syncs) + std::apply([this] (const auto& ... syncs) { REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(syncs).GetNodeId())); }, syncHolder_); this->DetachFromMe(GetInternals(evnt_).GetNodeId()); this->UnregisterMe(); @@ -132,7 +132,7 @@ class SyncedIterateNode : public StateNode if (GetInternals(evnt_).Events().empty()) return UpdateResult::unchanged; - S newValue = apply([this] (const auto& ... syncs) + S newValue = std::apply([this] (const auto& ... syncs) { return func_(GetInternals(evnt_).Events(), this->Value(), GetInternals(syncs).Value() ...); }, syncHolder_); @@ -176,7 +176,7 @@ class SyncedIterateByRefNode : public StateNode ~SyncedIterateByRefNode() { - apply([this] (const auto& ... syncs) { REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(syncs).GetNodeId())); }, syncHolder_); + std::apply([this] (const auto& ... syncs) { REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(syncs).GetNodeId())); }, syncHolder_); this->DetachFromMe(GetInternals(evnt_).GetNodeId()); this->UnregisterMe(); } @@ -187,7 +187,7 @@ class SyncedIterateByRefNode : public StateNode if (GetInternals(evnt_).Events().empty()) return UpdateResult::unchanged; - apply( + std::apply( [this] (const auto& ... args) { func_(GetInternals(evnt_).Events(), this->Value(), GetInternals(args).Value() ...); @@ -581,13 +581,13 @@ class FlattenObjectNode : public StateNode { public: FlattenObjectNode(const Group& group, const State& obj) : - StateNode::StateNode( in_place, group, GetInternals(obj).Value(), FlattenedInitTag{ } ), + StateNode( in_place, group, GetInternals(obj).Value(), FlattenedInitTag{ } ), obj_( obj ) { this->RegisterMe(); this->AttachToMe(GetInternals(obj).GetNodeId()); - for (NodeId nodeId : Value().memberIds_) + for (NodeId nodeId : this->Value().memberIds_) this->AttachToMe(nodeId); this->Value().initMode_ = false; @@ -595,7 +595,7 @@ class FlattenObjectNode : public StateNode ~FlattenObjectNode() { - for (NodeId nodeId : Value().memberIds_) + for (NodeId nodeId : this->Value().memberIds_) this->DetachFromMe(nodeId); this->DetachFromMe(GetInternals(obj_).GetNodeId()); diff --git a/include/react/detail/event_nodes.h b/include/react/detail/event_nodes.h index fce5b4b1..894097f2 100644 --- a/include/react/detail/event_nodes.h +++ b/include/react/detail/event_nodes.h @@ -19,7 +19,7 @@ //#include "tbb/spin_mutex.h" -#include "node_base.h" +#include "react/detail/node_base.h" #include "react/common/utility.h" /*****************************************/ REACT_BEGIN /*****************************************/ @@ -110,14 +110,14 @@ class EventMergeNode : public EventNode ~EventMergeNode() { - apply([this] (const auto& ... inputs) + std::apply([this] (const auto& ... inputs) { REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(inputs).GetNodeId())); }, inputs_); this->UnregisterMe(); } virtual UpdateResult Update(TurnId turnId) noexcept override { - apply([this] (auto& ... inputs) + std::apply([this] (auto& ... inputs) { REACT_EXPAND_PACK(MergeFromInput(inputs)); }, inputs_); if (! this->Events().empty()) @@ -147,7 +147,7 @@ class EventSlotNode : public EventNode EventSlotNode(const Group& group) : EventSlotNode::EventNode( group ) { - inputNodeId_ = GetGraphPtr()->RegisterNode(&slotInput_, NodeCategory::dyninput); + inputNodeId_ = this->GetGraphPtr()->RegisterNode(&slotInput_, NodeCategory::dyninput); this->RegisterMe(); this->AttachToMe(inputNodeId_); @@ -159,7 +159,7 @@ class EventSlotNode : public EventNode this->DetachFromMe(inputNodeId_); this->UnregisterMe(); - GetGraphPtr()->UnregisterNode(inputNodeId_); + this->GetGraphPtr()->UnregisterNode(inputNodeId_); } virtual UpdateResult Update(TurnId turnId) noexcept override @@ -280,7 +280,7 @@ class SyncedEventProcessingNode : public EventNode ~SyncedEventProcessingNode() { - apply([this] (const auto& ... syncs) + std::apply([this] (const auto& ... syncs) { REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(syncs).GetNodeId())); }, syncHolder_); this->DetachFromMe(GetInternals(dep_).GetNodeId()); this->UnregisterMe(); @@ -292,7 +292,7 @@ class SyncedEventProcessingNode : public EventNode if (GetInternals(dep_).Events().empty()) return UpdateResult::unchanged; - apply([this] (const auto& ... syncs) + std::apply([this] (const auto& ... syncs) { func_(GetInternals(dep_).Events(), std::back_inserter(this->Events()), GetInternals(syncs).Value() ...); }, @@ -329,7 +329,7 @@ class EventJoinNode : public EventNode> ~EventJoinNode() { - apply([this] (const auto& ... slots) + std::apply([this] (const auto& ... slots) { REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(slots.source).GetNodeId())); }, slots_); this->UnregisterMe(); } @@ -337,7 +337,7 @@ class EventJoinNode : public EventNode> virtual UpdateResult Update(TurnId turnId) noexcept override { // Move events into buffers. - apply([this, turnId] (Slot& ... slots) + std::apply([this, turnId] (Slot& ... slots) { REACT_EXPAND_PACK(FetchBuffer(turnId, slots)); }, slots_); while (true) @@ -345,7 +345,7 @@ class EventJoinNode : public EventNode> bool isReady = true; // All slots ready? - apply([this, &isReady] (Slot& ... slots) + std::apply([this, &isReady] (Slot& ... slots) { // Todo: combine return values instead REACT_EXPAND_PACK(CheckSlot(slots, isReady)); @@ -356,7 +356,7 @@ class EventJoinNode : public EventNode> break; // Pop values from buffers and emit tuple. - apply([this] (Slot& ... slots) + std::apply([this] (Slot& ... slots) { this->Events().emplace_back(slots.buffer.front() ...); REACT_EXPAND_PACK(slots.buffer.pop_front()); @@ -424,7 +424,7 @@ class EventLinkNode : public EventNode srcGraphPtr->DetachNode(outputNodeId_, GetInternals(dep_).GetNodeId()); srcGraphPtr->UnregisterNode(outputNodeId_); - auto& linkCache = GetGraphPtr()->GetLinkCache(); + auto& linkCache = this->GetGraphPtr()->GetLinkCache(); linkCache.Erase(this); this->UnregisterMe(); @@ -482,6 +482,7 @@ template class EventInternals { public: + using NodeType = EventNode; EventInternals() = default; EventInternals(const EventInternals&) = default; diff --git a/include/react/detail/graph_impl.h b/include/react/detail/graph_impl.h index 2ff28fff..120475ec 100644 --- a/include/react/detail/graph_impl.h +++ b/include/react/detail/graph_impl.h @@ -119,8 +119,8 @@ class ReactGraph NodeData& operator=(const NodeData&) = default; NodeData(IReactNode* nodePtrIn, NodeCategory categoryIn) : - nodePtr( nodePtrIn ), - category(categoryIn) + category(categoryIn),nodePtr( nodePtrIn ) + { } NodeCategory category = NodeCategory::normal; diff --git a/include/react/detail/observer_nodes.h b/include/react/detail/observer_nodes.h index dd051384..034c25d7 100644 --- a/include/react/detail/observer_nodes.h +++ b/include/react/detail/observer_nodes.h @@ -57,20 +57,20 @@ class StateObserverNode : public ObserverNode this->RegisterMe(NodeCategory::output); REACT_EXPAND_PACK(this->AttachToMe(GetInternals(deps).GetNodeId())); - apply([this] (const auto& ... deps) + std::apply([this] (const auto& ... deps) { this->func_(GetInternals(deps).Value() ...); }, depHolder_); } ~StateObserverNode() { - apply([this] (const auto& ... deps) + std::apply([this] (const auto& ... deps) { REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(deps).GetNodeId())); }, depHolder_); this->UnregisterMe(); } virtual UpdateResult Update(TurnId turnId) noexcept override { - apply([this] (const auto& ... deps) + std::apply([this] (const auto& ... deps) { this->func_(GetInternals(deps).Value() ...); }, depHolder_); return UpdateResult::unchanged; } @@ -137,7 +137,7 @@ class SyncedEventObserverNode : public ObserverNode ~SyncedEventObserverNode() { - apply([this] (const auto& ... syncs) + std::apply([this] (const auto& ... syncs) { REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(syncs).GetNodeId())); }, syncHolder_); this->DetachFromMe(GetInternals(subject_).GetNodeId()); this->UnregisterMe(); @@ -149,7 +149,7 @@ class SyncedEventObserverNode : public ObserverNode if (GetInternals(this->subject_).Events().empty()) return UpdateResult::unchanged; - apply([this] (const auto& ... syncs) + std::apply([this] (const auto& ... syncs) { func_(GetInternals(this->subject_).Events(), GetInternals(syncs).Value() ...); }, syncHolder_); return UpdateResult::unchanged; diff --git a/include/react/detail/state_nodes.h b/include/react/detail/state_nodes.h index 40858232..c3ffca69 100644 --- a/include/react/detail/state_nodes.h +++ b/include/react/detail/state_nodes.h @@ -16,7 +16,7 @@ #include #include -#include "node_base.h" +#include "react/detail/node_base.h" /***************************************/ REACT_IMPL_BEGIN /**************************************/ @@ -165,14 +165,14 @@ class StateFuncNode : public StateNode ~StateFuncNode() { - apply([this] (const auto& ... deps) + std::apply([this] (const auto& ... deps) { REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(deps).GetNodePtr()->GetNodeId())); }, depHolder_); this->UnregisterMe(); } virtual UpdateResult Update(TurnId turnId) noexcept override { - S newValue = apply([this] (const auto& ... deps) + S newValue = std::apply([this] (const auto& ... deps) { return this->func_(GetInternals(deps).Value() ...); }, depHolder_); if (HasChanged(this->Value(), newValue)) @@ -202,7 +202,7 @@ class StateSlotNode : public StateNode StateSlotNode::StateNode( group, GetInternals(dep).Value() ), input_( dep ) { - inputNodeId_ = GetGraphPtr()->RegisterNode(&slotInput_, NodeCategory::dyninput); + inputNodeId_ = this->GetGraphPtr()->RegisterNode(&slotInput_, NodeCategory::dyninput); this->RegisterMe(); this->AttachToMe(inputNodeId_); @@ -215,7 +215,7 @@ class StateSlotNode : public StateNode this->DetachFromMe(inputNodeId_); this->UnregisterMe(); - GetGraphPtr()->UnregisterNode(inputNodeId_); + this->GetGraphPtr()->UnregisterNode(inputNodeId_); } virtual UpdateResult Update(TurnId turnId) noexcept override @@ -284,7 +284,7 @@ class StateLinkNode : public StateNode srcGraphPtr->DetachNode(outputNodeId_, GetInternals(dep_).GetNodeId()); srcGraphPtr->UnregisterNode(outputNodeId_); - auto& linkCache = GetGraphPtr()->GetLinkCache(); + auto& linkCache = this->GetGraphPtr()->GetLinkCache(); linkCache.Erase(this); this->UnregisterMe(); @@ -340,6 +340,7 @@ template class StateInternals { public: + using NodeType = StateNode; StateInternals() = default; StateInternals(const StateInternals&) = default; diff --git a/include/react/event.h b/include/react/event.h index 21a186c1..ea12bc8e 100644 --- a/include/react/event.h +++ b/include/react/event.h @@ -21,6 +21,12 @@ #include "react/detail/event_nodes.h" #include "react/common/ptrcache.h" +/***************************************/ REACT_IMPL_BEGIN /**************************************/ + +template +static Event SameGroupOrLink(const Group& targetGroup, const Event& dep); + +/****************************************/ REACT_IMPL_END /***************************************/ /*****************************************/ REACT_BEGIN /*****************************************/ @@ -31,25 +37,26 @@ template class Event : protected REACT_IMPL::EventInternals { public: + using NodeType = typename REACT_IMPL::EventInternals::NodeType; // Construct with explicit group template static Event Create(const Group& group, F&& func, const Event& dep) - { return CreateProcessingNode(group, std::forward(func), dep); } + { return std::static_pointer_cast(CreateProcessingNode(group, std::forward(func), dep)); } // Construct with implicit group template static Event Create(F&& func, const Event& dep) - { return CreateProcessingNode(dep.GetGroup(), std::forward(func), dep); } + { return std::static_pointer_cast(CreateProcessingNode(dep.GetGroup(), std::forward(func), dep)); } // Construct with explicit group template static Event Create(const Group& group, F&& func, const Event& dep, const State& ... states) - { return CreateSyncedProcessingNode(group, std::forward(func), dep, states ...); } + { return std::static_pointer_cast(CreateSyncedProcessingNode(group, std::forward(func), dep, states ...)); } // Construct with implicit group template static Event Create(F&& func, const Event& dep, const State& ... states) - { return CreateSyncedProcessingNode(dep.GetGroup(), std::forward(func), dep, states ...); } + { return std::static_pointer_cast(CreateSyncedProcessingNode(dep.GetGroup(), std::forward(func), dep, states ...)); } Event() = default; @@ -60,10 +67,10 @@ class Event : protected REACT_IMPL::EventInternals Event& operator=(Event&&) = default; auto GetGroup() const -> const Group& - { return GetNodePtr()->GetGroup(); } + { return this->GetNodePtr()->GetGroup(); } auto GetGroup() -> Group& - { return GetNodePtr()->GetGroup(); } + { return this->GetNodePtr()->GetGroup(); } friend bool operator==(const Event& a, const Event& b) { return a.GetNodePtr() == b.GetNodePtr(); } @@ -103,7 +110,7 @@ class Event : protected REACT_IMPL::EventInternals } template - friend static RET impl::CreateWrappedNode(ARGS&& ... args); + friend /*static*/ RET impl::CreateWrappedNode(ARGS&& ... args); }; /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -113,9 +120,10 @@ template class EventSource : public Event { public: + using NodeType = REACT_IMPL::EventNode; // Construct event source static EventSource Create(const Group& group) - { return CreateSourceNode(group); } + { return std::static_pointer_cast(CreateSourceNode(group)); } EventSource() = default; @@ -219,7 +227,7 @@ class EventSlot : public Event NodeId nodeId = castedPtr->GetInputNodeId(); auto& graphPtr = GetInternals(this->GetGroup()).GetGraphPtr(); - graphPtr->PushInput(nodeId, [this, castedPtr, &input] { castedPtr->AddSlotInput(SameGroupOrLink(GetGroup(), input)); }); + graphPtr->PushInput(nodeId, [this, castedPtr, &input] { castedPtr->AddSlotInput(SameGroupOrLink(this->GetGroup(), input)); }); } void RemoveSlotInput(const Event& input) @@ -232,7 +240,7 @@ class EventSlot : public Event NodeId nodeId = castedPtr->GetInputNodeId(); auto& graphPtr = GetInternals(this->GetGroup()).GetGraphPtr(); - graphPtr->PushInput(nodeId, [this, castedPtr, &input] { castedPtr->RemoveSlotInput(SameGroupOrLink(GetGroup(), input)); }); + graphPtr->PushInput(nodeId, [this, castedPtr, &input] { castedPtr->RemoveSlotInput(SameGroupOrLink(this->GetGroup(), input)); }); } void RemoveAllSlotInputs() @@ -256,9 +264,10 @@ template class EventLink : public Event { public: + using NodeType = typename Event::NodeType; // Construct with group static EventLink Create(const Group& group, const Event& input) - { return GetOrCreateLinkNode(group, input); } + { return std::static_pointer_cast(GetOrCreateLinkNode(group, input)); } EventLink() = default; diff --git a/include/react/group.h b/include/react/group.h index d534d7e4..96de0e1c 100644 --- a/include/react/group.h +++ b/include/react/group.h @@ -14,7 +14,7 @@ #include #include -#include "react/API.h" +#include "react/api.h" #include "react/common/syncpoint.h" #include "react/detail/graph_interface.h" diff --git a/include/react/observer.h b/include/react/observer.h index a5360478..11580fe4 100644 --- a/include/react/observer.h +++ b/include/react/observer.h @@ -32,12 +32,12 @@ class Observer : protected REACT_IMPL::ObserverInternals // Construct state observer with explicit group template static Observer Create(const Group& group, F&& func, const State& subject1, const State& ... subjects) - { return CreateStateObserverNode(group, std::forward(func), subject1, subjects ...); } + { return std::static_pointer_cast(CreateStateObserverNode(group, std::forward(func), subject1, subjects ...)); } // Construct state observer with implicit group template static Observer Create(F&& func, const State& subject1, const State& ... subjects) - { return CreateStateObserverNode(subject1.GetGroup(), std::forward(func), subject1, subjects ...); } + { return std::static_pointer_cast(CreateStateObserverNode(subject1.GetGroup(), std::forward(func), subject1, subjects ...)); } // Construct event observer with explicit group template @@ -47,7 +47,7 @@ class Observer : protected REACT_IMPL::ObserverInternals // Construct event observer with implicit group template static Observer Create(F&& func, const Event& subject) - { return CreateEventObserverNode(subject.GetGroup(), std::forward(func), subject); } + { return std::static_pointer_cast(CreateEventObserverNode(subject.GetGroup(), std::forward(func), subject)); } // Constructed synced event observer with explicit group template @@ -57,7 +57,7 @@ class Observer : protected REACT_IMPL::ObserverInternals // Constructed synced event observer with implicit group template static Observer Create(F&& func, const Event& subject, const State& ... states) - { return CreateSyncedEventObserverNode(subject.GetGroup(), std::forward(func), subject, states ...); } + { return std::static_pointer_cast(CreateSyncedEventObserverNode(subject.GetGroup(), std::forward(func), subject, states ...)); } Observer(const Observer&) = default; Observer& operator=(const Observer&) = default; diff --git a/include/react/state.h b/include/react/state.h index d7942cce..fb5f7e65 100644 --- a/include/react/state.h +++ b/include/react/state.h @@ -29,20 +29,21 @@ template class State : protected REACT_IMPL::StateInternals { public: + using NodeType = typename REACT_IMPL::StateInternals::NodeType; // Construct with explicit group template static State Create(const Group& group, F&& func, const State& dep1, const State& ... deps) - { return CreateFuncNode(group, std::forward(func), dep1, deps ...); } + { return std::static_pointer_cast(CreateFuncNode(group, std::forward(func), dep1, deps ...)); } // Construct with implicit group template static State Create(F&& func, const State& dep1, const State& ... deps) - { return CreateFuncNode(dep1.GetGroup(), std::forward(func), dep1, deps ...); } + { return std::static_pointer_cast(CreateFuncNode(dep1.GetGroup(), std::forward(func), dep1, deps ...)); } // Construct with constant value template static State Create(const Group& group, T&& init) - { return CreateFuncNode(group, [value = std::move(init)] { return value; }); } + { return std::static_pointer_cast(CreateFuncNode(group, [value = std::move(init)] { return value; })); } State() = default; @@ -97,14 +98,15 @@ template class StateVar : public State { public: + using NodeType = typename State::NodeType; // Construct with group + default static StateVar Create(const Group& group) - { return CreateVarNode(group); } + { return std::static_pointer_cast(CreateVarNode(group)); } // Construct with group + value template static StateVar Create(const Group& group, T&& value) - { return CreateVarNode(group, std::forward(value)); } + { return std::static_pointer_cast(CreateVarNode(group, std::forward(value))); } StateVar() = default; @@ -188,13 +190,14 @@ template class StateSlot : public State { public: + using NodeType = typename State::NodeType; // Construct with explicit group static StateSlot Create(const Group& group, const State& input) { return CreateSlotNode(group, input); } // Construct with implicit group static StateSlot Create(const State& input) - { return CreateSlotNode(input.GetGroup(), input); } + { return std::static_pointer_cast(CreateSlotNode(input.GetGroup(), input)); } StateSlot() = default; @@ -232,7 +235,7 @@ class StateSlot : public State NodeId nodeId = castedPtr->GetInputNodeId(); auto& graphPtr = GetInternals(this->GetGroup()).GetGraphPtr(); - graphPtr->PushInput(nodeId, [this, castedPtr, &newInput] { castedPtr->SetInput(SameGroupOrLink(GetGroup(), newInput)); }); + graphPtr->PushInput(nodeId, [this, castedPtr, &newInput] { castedPtr->SetInput(SameGroupOrLink(this->GetGroup(), newInput)); }); } }; @@ -243,9 +246,10 @@ template class StateLink : public State { public: + using NodeType = typename State::NodeType; // Construct with group static StateLink Create(const Group& group, const State& input) - { return GetOrCreateLinkNode(group, input); } + { return std::static_pointer_cast(GetOrCreateLinkNode(group, input)); } StateLink() = default;