diff --git a/include/spaic-css/CSS.hpp b/include/spaic-css/CSS.hpp index f661ea1..708594f 100644 --- a/include/spaic-css/CSS.hpp +++ b/include/spaic-css/CSS.hpp @@ -5,9 +5,9 @@ namespace spaic::css { template -Stylesheet css(T... params); +Stylesheet css(T&&... params); template -Stylesheet keyframes(T... params); +Stylesheet keyframes(T&&... params); } // namespace spaic::css #include \ No newline at end of file diff --git a/include/spaic-css/CssProperty.hpp b/include/spaic-css/CssProperty.hpp index 12f6093..4a7b2d2 100644 --- a/include/spaic-css/CssProperty.hpp +++ b/include/spaic-css/CssProperty.hpp @@ -11,7 +11,8 @@ template class CssProperty { public: - AssignedCssProperty operator=(T value); + template + AssignedCssProperty operator=(U&& value); }; } // namespace spaic::css::prop diff --git a/include/spaic-css/Unit.hpp b/include/spaic-css/Unit.hpp index 0ea99c0..06c7599 100644 --- a/include/spaic-css/Unit.hpp +++ b/include/spaic-css/Unit.hpp @@ -58,7 +58,7 @@ class CssUnit long double value; public: - CssUnit(long double value) noexcept : value(value) {} + CssUnit(long double value) noexcept; std::string toCssValue(); }; @@ -99,4 +99,6 @@ defineUnitUDL(percent); } // namespace spaic::css::unit #undef defineUnitUDLRaw -#undef defineUnitUDL \ No newline at end of file +#undef defineUnitUDL + +#include \ No newline at end of file diff --git a/include/spaic-css/detail/CSS.hpp b/include/spaic-css/detail/CSS.hpp index cb4640e..bde1c6a 100644 --- a/include/spaic-css/detail/CSS.hpp +++ b/include/spaic-css/detail/CSS.hpp @@ -5,9 +5,15 @@ namespace spaic::css { template -Stylesheet css(T... params) +Stylesheet css(T&&... params) { // TODO: css(params) return Stylesheet(); } +template +Stylesheet keyframes(T&&... params) +{ + // TODO: keyframes(params) + return Stylesheet(); +} } // namespace spaic::css diff --git a/include/spaic-css/detail/CssProperty.hpp b/include/spaic-css/detail/CssProperty.hpp index 09fa61e..fd8947c 100644 --- a/include/spaic-css/detail/CssProperty.hpp +++ b/include/spaic-css/detail/CssProperty.hpp @@ -4,11 +4,10 @@ namespace spaic::css::prop { - template -AssignedCssProperty CssProperty::operator=(T value) +template +AssignedCssProperty CssProperty::operator=(U&& value) { return AssignedCssProperty(); } - } // namespace spaic::css::prop \ No newline at end of file diff --git a/include/spaic-css/detail/Unit.hpp b/include/spaic-css/detail/Unit.hpp new file mode 100644 index 0000000..5787d1d --- /dev/null +++ b/include/spaic-css/detail/Unit.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace spaic::css::unit +{ + template + CssUnit::CssUnit(long double value) noexcept : value(value) {} +} // namespace spaic::css::unit diff --git a/include/spaic-dom/Render.hpp b/include/spaic-dom/Render.hpp index a13e232..91baded 100644 --- a/include/spaic-dom/Render.hpp +++ b/include/spaic-dom/Render.hpp @@ -5,5 +5,5 @@ namespace spaic::dom { -std::string render(spaic::vnode::VNode node); +std::string render(const spaic::vnode::VNode &node); } \ No newline at end of file diff --git a/include/spaic/Component.hpp b/include/spaic/Component.hpp index 2dc3fde..72e655a 100644 --- a/include/spaic/Component.hpp +++ b/include/spaic/Component.hpp @@ -9,6 +9,7 @@ namespace spaic::vnode { class VNode; } + namespace spaic::comp { using NativeNodeName = std::optional; @@ -19,7 +20,7 @@ class ComponentParent const NativeNodeName native_node_name; const std::vector children; - ComponentParent(NativeNodeName native_node_name, std::vector children); + ComponentParent(NativeNodeName native_node_name, std::vector &&children); }; class ComponentSingle { @@ -29,7 +30,7 @@ class ComponentSingle ComponentSingle(NativeNodeName native_node_name); template - ComponentParent operator()(T... children) noexcept; + ComponentParent operator()(T&&... children) noexcept; }; template class Component @@ -39,7 +40,7 @@ class Component Component(NativeNodeName native_node_name); template - ComponentSingle operator()(T... args) noexcept; + ComponentSingle operator()(T&&... args) noexcept; }; } // namespace spaic::comp diff --git a/include/spaic/ComponentPart.hpp b/include/spaic/ComponentPart.hpp index bc5f1b2..ebfdf33 100644 --- a/include/spaic/ComponentPart.hpp +++ b/include/spaic/ComponentPart.hpp @@ -10,7 +10,7 @@ using Update = std::function; using Render = std::function; template -Component create_component(Props props, StateSet state, Update update, Render render); +Component create_component(Props &&props, StateSet &&state, const Update &update, const Render &render); } // namespace spaic::comp #include \ No newline at end of file diff --git a/include/spaic/detail/Component.hpp b/include/spaic/detail/Component.hpp index 110f47c..41b98e2 100644 --- a/include/spaic/detail/Component.hpp +++ b/include/spaic/detail/Component.hpp @@ -9,21 +9,20 @@ namespace spaic::comp { template -ComponentParent ComponentSingle::operator()(T... children) noexcept +ComponentParent ComponentSingle::operator()(T&&... children) noexcept { // TODO: ComponentSingle::operator()(children) - return ComponentParent(this->native_node_name, {children...}); + return ComponentParent(native_node_name, { std::forward(children)... }); } template -Component::Component(NativeNodeName native_node_name) : native_node_name(native_node_name) -{ -} +Component::Component(NativeNodeName native_node_name) : native_node_name(native_node_name) {} + template template -ComponentSingle Component::operator()(T... args) noexcept +ComponentSingle Component::operator()(T&&... args) noexcept { // TODO: Component::operator()(args) - return ComponentSingle(this->native_node_name); + return ComponentSingle(native_node_name); } } // namespace spaic::comp diff --git a/include/spaic/detail/ComponentPart.hpp b/include/spaic/detail/ComponentPart.hpp index 589c465..2575f9b 100644 --- a/include/spaic/detail/ComponentPart.hpp +++ b/include/spaic/detail/ComponentPart.hpp @@ -11,7 +11,7 @@ namespace spaic::comp { template -Component create_component(Props props, StateSet state, Update update, Render render) +Component create_component(Props &&props, StateSet &&state, const Update &update, const Render &render) { // TODO: create_component(props, state, update, render) return Component(std::nullopt); diff --git a/include/spaic/detail/Property.hpp b/include/spaic/detail/Property.hpp index ffea73b..75a46dd 100644 --- a/include/spaic/detail/Property.hpp +++ b/include/spaic/detail/Property.hpp @@ -58,6 +58,6 @@ Property> optional() noexcept template Property fallback(T &&fallback_value) noexcept { - return Fallback(fallback_value); + return Fallback(std::forward(fallback_value)); } } // namespace spaic::props diff --git a/src/spaic-dom/Render.cpp b/src/spaic-dom/Render.cpp index e379666..d5d330f 100644 --- a/src/spaic-dom/Render.cpp +++ b/src/spaic-dom/Render.cpp @@ -8,26 +8,25 @@ namespace spaic::dom { - template struct overloaded : Ts... { using Ts::operator()...; }; template -overloaded(Ts...)->overloaded; +overloaded(Ts...) -> overloaded; -std::string render_base(spaic::vnode::VNodeBase node) +std::string render_base(const spaic::vnode::VNodeBase &node) { std::ostringstream stream; std::visit( overloaded{ - [&](std::nullptr_t &arg) { + [&](std::nullptr_t) { // do nothing, nullptr means empty string. }, - [&](std::string &arg) { stream << arg; }, - [&](const char *&arg) { stream << arg; }, - [&](spaic::comp::ComponentParent &arg) { + [&](const std::string &arg) { stream << arg; }, + [&](const char *arg) { stream << arg; }, + [&](const spaic::comp::ComponentParent &arg) { if (arg.native_node_name) { stream << "<" << *arg.native_node_name << ">\n"; @@ -41,8 +40,8 @@ std::string render_base(spaic::vnode::VNodeBase node) stream << "\n"; } }, - [&](spaic::comp::ComponentSingle &arg) { stream << typeid(std::decay_t).name() << "(ComponentSingle)"; }, - [&](auto arg) { + [&](const spaic::comp::ComponentSingle &arg) { stream << typeid(std::decay_t).name() << "(ComponentSingle)"; }, + [&](const auto &arg) { using T = std::decay_t; if constexpr (std::is_same_v) { @@ -61,11 +60,11 @@ std::string render_base(spaic::vnode::VNodeBase node) node); return stream.str(); } -std::string render(spaic::vnode::VNode node) +std::string render(const spaic::vnode::VNode &node) { std::ostringstream stream; std::visit( - [&](auto &&arg) { + [&](const auto &arg) { // wtf is that fucking bitches using T = std::decay_t; if constexpr (std::is_same_v>) diff --git a/src/spaic/Component.cpp b/src/spaic/Component.cpp index 732cb96..2e6b332 100644 --- a/src/spaic/Component.cpp +++ b/src/spaic/Component.cpp @@ -5,5 +5,5 @@ namespace spaic::comp { ComponentSingle::ComponentSingle(NativeNodeName native_node_name) : native_node_name(native_node_name) {} -ComponentParent::ComponentParent(NativeNodeName native_node_name, std::vector children) : native_node_name(native_node_name), children(children) {} +ComponentParent::ComponentParent(NativeNodeName native_node_name, std::vector &&children) : native_node_name(native_node_name), children(std::move(children)) {} } // namespace spaic::comp \ No newline at end of file