Skip to content

Commit

Permalink
SpaicDom 모듈 코드 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
kmc7468 committed Mar 17, 2020
1 parent 0df41d6 commit 0f12eac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
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);
}
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

0 comments on commit 0f12eac

Please sign in to comment.