Skip to content

Commit

Permalink
Merge pull request #1 from kmc7468/master
Browse files Browse the repository at this point in the history
rvalue reference, universal reference를 사용할 수 있는 곳에 적용
  • Loading branch information
RanolP authored Mar 17, 2020
2 parents 0df41d6 + 6f632a3 commit f206105
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 35 deletions.
4 changes: 2 additions & 2 deletions include/spaic-css/CSS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace spaic::css
{
template <typename... T>
Stylesheet css(T... params);
Stylesheet css(T&&... params);
template <typename... T>
Stylesheet keyframes(T... params);
Stylesheet keyframes(T&&... params);
} // namespace spaic::css

#include <spaic-css/detail/CSS.hpp>
3 changes: 2 additions & 1 deletion include/spaic-css/CssProperty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ template <typename T>
class CssProperty
{
public:
AssignedCssProperty<T> operator=(T value);
template <typename U>
AssignedCssProperty<T> operator=(U&& value);
};
} // namespace spaic::css::prop

Expand Down
6 changes: 4 additions & 2 deletions include/spaic-css/Unit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down Expand Up @@ -99,4 +99,6 @@ defineUnitUDL(percent);
} // namespace spaic::css::unit

#undef defineUnitUDLRaw
#undef defineUnitUDL
#undef defineUnitUDL

#include <spaic-css/detail/Unit.hpp>
8 changes: 7 additions & 1 deletion include/spaic-css/detail/CSS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
namespace spaic::css
{
template <typename... T>
Stylesheet css(T... params)
Stylesheet css(T&&... params)
{
// TODO: css(params)
return Stylesheet();
}
template<typename ...T>
Stylesheet keyframes(T&&... params)
{
// TODO: keyframes(params)
return Stylesheet();
}
} // namespace spaic::css
5 changes: 2 additions & 3 deletions include/spaic-css/detail/CssProperty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

namespace spaic::css::prop
{

template <typename T>
AssignedCssProperty<T> CssProperty<T>::operator=(T value)
template <typename U>
AssignedCssProperty<T> CssProperty<T>::operator=(U&& value)
{
return AssignedCssProperty<T>();
}

} // namespace spaic::css::prop
9 changes: 9 additions & 0 deletions include/spaic-css/detail/Unit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <spaic-css/Unit.hpp>

namespace spaic::css::unit
{
template <CssUnitType T>
CssUnit<T>::CssUnit(long double value) noexcept : value(value) {}
} // namespace spaic::css::unit
2 changes: 1 addition & 1 deletion include/spaic-dom/Render.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

namespace spaic::dom
{
std::string render(spaic::vnode::VNode node);
std::string render(const spaic::vnode::VNode &node);
}
7 changes: 4 additions & 3 deletions include/spaic/Component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace spaic::vnode
{
class VNode;
}

namespace spaic::comp
{
using NativeNodeName = std::optional<const char *>;
Expand All @@ -19,7 +20,7 @@ class ComponentParent
const NativeNodeName native_node_name;
const std::vector<spaic::vnode::VNode> children;

ComponentParent(NativeNodeName native_node_name, std::vector<spaic::vnode::VNode> children);
ComponentParent(NativeNodeName native_node_name, std::vector<spaic::vnode::VNode> &&children);
};
class ComponentSingle
{
Expand All @@ -29,7 +30,7 @@ class ComponentSingle
ComponentSingle(NativeNodeName native_node_name);

template <typename... T>
ComponentParent operator()(T... children) noexcept;
ComponentParent operator()(T&&... children) noexcept;
};
template <typename Props>
class Component
Expand All @@ -39,7 +40,7 @@ class Component

Component(NativeNodeName native_node_name);
template <typename... T>
ComponentSingle operator()(T... args) noexcept;
ComponentSingle operator()(T&&... args) noexcept;
};
} // namespace spaic::comp

Expand Down
2 changes: 1 addition & 1 deletion include/spaic/ComponentPart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Update = std::function<ShouldRender()>;
using Render = std::function<spaic::vnode::VNode()>;

template <typename Props, typename StateSet>
Component<Props> create_component(Props props, StateSet state, Update update, Render render);
Component<Props> create_component(Props &&props, StateSet &&state, const Update &update, const Render &render);
} // namespace spaic::comp

#include <spaic/detail/ComponentPart.hpp>
13 changes: 6 additions & 7 deletions include/spaic/detail/Component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@
namespace spaic::comp
{
template <typename... T>
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<T>(children)... });
}

template <typename Props>
Component<Props>::Component(NativeNodeName native_node_name) : native_node_name(native_node_name)
{
}
Component<Props>::Component(NativeNodeName native_node_name) : native_node_name(native_node_name) {}

template <typename Props>
template <typename... T>
ComponentSingle Component<Props>::operator()(T... args) noexcept
ComponentSingle Component<Props>::operator()(T&&... args) noexcept
{
// TODO: Component::operator()(args)
return ComponentSingle(this->native_node_name);
return ComponentSingle(native_node_name);
}
} // namespace spaic::comp
2 changes: 1 addition & 1 deletion include/spaic/detail/ComponentPart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace spaic::comp
{
template <typename Props, typename StateSet>
Component<Props> create_component(Props props, StateSet state, Update update, Render render)
Component<Props> create_component(Props &&props, StateSet &&state, const Update &update, const Render &render)
{
// TODO: create_component(props, state, update, render)
return Component<Props>(std::nullopt);
Expand Down
2 changes: 1 addition & 1 deletion include/spaic/detail/Property.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ Property<T, std::optional<T>> optional() noexcept
template <typename T>
Property<T, T> fallback(T &&fallback_value) noexcept
{
return Fallback<T>(fallback_value);
return Fallback<T>(std::forward<T>(fallback_value));
}
} // namespace spaic::props
21 changes: 10 additions & 11 deletions src/spaic-dom/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@

namespace spaic::dom
{

template <class... Ts>
struct overloaded : Ts...
{
using Ts::operator()...;
};
template <class... Ts>
overloaded(Ts...)->overloaded<Ts...>;
overloaded(Ts...) -> overloaded<Ts...>;

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";
Expand All @@ -41,8 +40,8 @@ std::string render_base(spaic::vnode::VNodeBase node)
stream << "</" << *arg.native_node_name << ">\n";
}
},
[&](spaic::comp::ComponentSingle &arg) { stream << typeid(std::decay_t<decltype(arg)>).name() << "(ComponentSingle)"; },
[&](auto arg) {
[&](const spaic::comp::ComponentSingle &arg) { stream << typeid(std::decay_t<decltype(arg)>).name() << "(ComponentSingle)"; },
[&](const auto &arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, bool>)
{
Expand All @@ -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<decltype(arg)>;
if constexpr (std::is_same_v<T, std::vector<spaic::vnode::VNode>>)
Expand Down
2 changes: 1 addition & 1 deletion src/spaic/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<spaic::vnode::VNode> children) : native_node_name(native_node_name), children(children) {}
ComponentParent::ComponentParent(NativeNodeName native_node_name, std::vector<spaic::vnode::VNode> &&children) : native_node_name(native_node_name), children(std::move(children)) {}
} // namespace spaic::comp

0 comments on commit f206105

Please sign in to comment.