diff --git a/cabin.toml b/cabin.toml index c96a70e..1a545e8 100644 --- a/cabin.toml +++ b/cabin.toml @@ -1,7 +1,7 @@ [package] name = "flow-core" -version = "0.1.0" -authors = ["Tomas Rigaux "] +version = "1.1.1" +authors = ["Scott Henning ", "Tomas Rigaux "] edition = "20" [dependencies] diff --git a/include/flow/core/Node.hpp b/include/flow/core/Node.hpp index a0371e9..d4720a4 100644 --- a/include/flow/core/Node.hpp +++ b/include/flow/core/Node.hpp @@ -139,11 +139,11 @@ class Node virtual json SaveInputs() const { return {}; } virtual void RestoreInputs(const json&) {} - private: + protected: void AddInput(std::string_view key, const std::string& caption, std::string_view type, SharedNodeData data); + void AddOutput(std::string_view key, const std::string& caption, std::string_view type, SharedNodeData data); - protected: template void AddInput(std::string_view key, const std::string& caption, SharedNodeData data = nullptr) { @@ -162,14 +162,14 @@ class Node return AddOutput(key, caption, TypeName_v, std::move(data)); } - void EmitUpdate(const IndexableName& key); + void EmitUpdate(const IndexableName& key, const SharedNodeData& data); public: EventDispatcher<> OnCompute; - EventDispatcher OnSetInput; - EventDispatcher OnSetOutput; + EventDispatcher OnSetInput; + EventDispatcher OnSetOutput; EventDispatcher OnError; - EventDispatcher OnEmitOutput; + EventDispatcher OnEmitOutput; protected: mutable std::mutex _mutex; diff --git a/include/flow/core/TypeName.hpp b/include/flow/core/TypeName.hpp index caecb80..aa0cebc 100644 --- a/include/flow/core/TypeName.hpp +++ b/include/flow/core/TypeName.hpp @@ -22,7 +22,6 @@ template<> struct TypeName { static constexpr std::string_view value = "void"; - static constexpr bool Check(std::string_view v) { return v == value; } }; namespace detail @@ -59,7 +58,7 @@ struct TypeName * @brief The string representation of the given type. */ static constexpr std::string_view value = [] { - constexpr auto wrapped_name = detail::wrapped_type_name>(); + constexpr auto wrapped_name = detail::wrapped_type_name(); constexpr auto prefix_length = detail::wrapped_type_name_prefix_length(); constexpr auto suffix_length = detail::wrapped_type_name_suffix_length(); constexpr auto TypeName_length = wrapped_name.length() - prefix_length - suffix_length; @@ -75,17 +74,17 @@ struct TypeName template constexpr bool operator==(const TypeName&, const TypeName&) { - return false; + return std::is_same_v; } template -constexpr bool operator==(const TypeName&, const TypeName&) +constexpr bool operator==(const TypeName& type_name, const std::string_view& type_string) { - return true; + return type_name.value == type_string; } template -constexpr bool operator==(const TypeName& type_name, const std::string_view& type_string) +constexpr bool operator==(const std::string_view& type_string, const TypeName& type_name) { return type_name.value == type_string; } diff --git a/src/Node.cpp b/src/Node.cpp index 9614ef1..19ff420 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -27,6 +27,10 @@ catch (const std::exception& e) { OnError.Broadcast(e); } +catch (const std::string& e) +{ + OnError.Broadcast(std::runtime_error(e)); +} catch (...) { OnError.Broadcast(std::exception()); @@ -81,9 +85,9 @@ const SharedNodeData& Node::GetOutputData(const IndexableName& key) const { retu void Node::SetInputData(const IndexableName& key, SharedNodeData data, bool compute) { - _input_ports.at(key)->SetData(std::move(data)); + _input_ports.at(key)->SetData(data); - OnSetInput.Broadcast(key); + OnSetInput.Broadcast(key, data); if (compute) { @@ -93,20 +97,16 @@ void Node::SetInputData(const IndexableName& key, SharedNodeData data, bool comp void Node::SetOutputData(const IndexableName& key, SharedNodeData data, bool emit) { - _output_ports.at(key)->SetData(std::move(data), true); + _output_ports.at(key)->SetData(data, true); - OnSetOutput.Broadcast(key); + OnSetOutput.Broadcast(key, data); if (emit) { - EmitUpdate(key); + EmitUpdate(key, data); } } -void Node::EmitUpdate(const IndexableName& key) -{ - auto data = GetOutputData(key); - OnEmitOutput.Broadcast(ID(), key, std::move(data)); -} +void Node::EmitUpdate(const IndexableName& key, const SharedNodeData& data) { OnEmitOutput.Broadcast(ID(), key, data); } FLOW_NAMESPACE_END diff --git a/tests/type_name_test.cpp b/tests/type_name_test.cpp index 96a6c62..9019aa5 100644 --- a/tests/type_name_test.cpp +++ b/tests/type_name_test.cpp @@ -49,13 +49,23 @@ TEST(TypeNameTest, AliasTypes) EXPECT_EQ(TypeName::value, "int"); } -struct TestType +TEST(TypeNameTest, ReferenceTypes) { -}; +#ifdef FLOW_APPLE + EXPECT_EQ(TypeName::value, "int &"); + EXPECT_EQ(TypeName::value, "const int &"); +#else + EXPECT_EQ(TypeName::value, "int&"); + EXPECT_EQ(TypeName::value, "const int&"); +#endif +} + +struct TestType; namespace TestNS { struct TestType; } + TEST(TypeNameTest, CustomTypes) { EXPECT_EQ(TypeName::value, "TestType");