no need for template specialization
This commit is contained in:
parent
105e708d42
commit
8fa398252d
@ -15,25 +15,21 @@ class get_token: public boost::static_visitor<const mstch::node&> {
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline const mstch::node& operator()(const T& t) const {
|
||||
const mstch::node& operator()(const T& t) const {
|
||||
return node;
|
||||
}
|
||||
|
||||
const mstch::node& operator()(const map& map) const {
|
||||
return map.at(token);
|
||||
}
|
||||
|
||||
const mstch::node& operator()(const std::shared_ptr<object>& object) const {
|
||||
return object->at(token);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string& token;
|
||||
const mstch::node& node;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline const mstch::node& get_token::operator()(const map& map) const {
|
||||
return map.at(token);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline const mstch::node& get_token::operator()(
|
||||
const std::shared_ptr<object>& object) const
|
||||
{
|
||||
return object->at(token);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,18 +16,16 @@ class has_token: public boost::static_visitor<bool> {
|
||||
return token == ".";
|
||||
}
|
||||
|
||||
bool operator()(const map& map) const {
|
||||
return map.count(token) == 1;
|
||||
}
|
||||
|
||||
bool operator()(const std::shared_ptr<object>& object) const {
|
||||
return object->has(token);
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string& token;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool has_token::operator()(const map& map) const {
|
||||
return map.count(token) == 1;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool has_token::operator()(const std::shared_ptr<object>& object) const {
|
||||
return object->has(token);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,36 +12,30 @@ class is_node_empty: public boost::static_visitor<bool> {
|
||||
inline bool operator()(const T& t) const {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is_node_empty::operator()(const std::nullptr_t& nul) const {
|
||||
bool operator()(const std::nullptr_t& nul) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool is_node_empty::operator()(const int& value) const {
|
||||
bool operator()(const int& value) const {
|
||||
return value == 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool is_node_empty::operator()(const double& value) const {
|
||||
bool operator()(const double& value) const {
|
||||
return value == 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool is_node_empty::operator()(const bool& value) const {
|
||||
bool operator()(const bool& value) const {
|
||||
return !value;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool is_node_empty::operator()(const std::string& value) const {
|
||||
bool operator()(const std::string& value) const {
|
||||
return value == "";
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool is_node_empty::operator()(const array& array) const {
|
||||
bool operator()(const array& array) const {
|
||||
return array.size() == 0;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -19,35 +19,30 @@ class render_node: public boost::static_visitor<std::string> {
|
||||
return "";
|
||||
}
|
||||
|
||||
private:
|
||||
flag m_flag;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline std::string render_node::operator()(const int& value) const {
|
||||
std::string operator()(const int& value) const {
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::string render_node::operator()(const double& value) const {
|
||||
std::string operator()(const double& value) const {
|
||||
std::stringstream ss;
|
||||
ss << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::string render_node::operator()(const bool& value) const {
|
||||
std::string operator()(const bool& value) const {
|
||||
return value ? "true" : "false";
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::string render_node::operator()(const lambda& value) const {
|
||||
std::string operator()(const lambda& value) const {
|
||||
return (m_flag == flag::escape_html) ? html_escape(value()) : value();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::string render_node::operator()(const std::string& value) const {
|
||||
std::string operator()(const std::string& value) const {
|
||||
return (m_flag == flag::escape_html) ? html_escape(value) : value;
|
||||
}
|
||||
|
||||
private:
|
||||
flag m_flag;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -24,14 +24,7 @@ class render_section: public boost::static_visitor<std::string> {
|
||||
return render_context::push(ctx, t).render(section);
|
||||
}
|
||||
|
||||
private:
|
||||
render_context& ctx;
|
||||
const template_type& section;
|
||||
flag m_flag;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline std::string render_section::operator()(const lambda& fun) const {
|
||||
std::string operator()(const lambda& fun) const {
|
||||
std::string section_str;
|
||||
for(auto& token: section)
|
||||
section_str += token.raw();
|
||||
@ -41,8 +34,7 @@ inline std::string render_section::operator()(const lambda& fun) const {
|
||||
});
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::string render_section::operator()(const array& array) const {
|
||||
std::string operator()(const array& array) const {
|
||||
std::string out;
|
||||
if(m_flag == flag::keep_array)
|
||||
return render_context::push(ctx, array).render(section);
|
||||
@ -52,4 +44,10 @@ inline std::string render_section::operator()(const array& array) const {
|
||||
return out;
|
||||
}
|
||||
|
||||
private:
|
||||
render_context& ctx;
|
||||
const template_type& section;
|
||||
flag m_flag;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user