Archived
1
0

clang format

This commit is contained in:
Jeff Becker
2017-10-17 10:29:56 -04:00
parent 85248787fc
commit 841c5c6afe
69 changed files with 2381 additions and 2448 deletions

View File

@@ -2,34 +2,25 @@
#include <boost/variant/static_visitor.hpp>
#include "mstch/mstch.hpp"
#include "has_token.hpp"
#include "mstch/mstch.hpp"
namespace mstch {
namespace mstch
{
class get_token: public boost::static_visitor<const mstch::node&> {
public:
get_token(const std::string& token, const mstch::node& node):
m_token(token), m_node(node)
{
}
class get_token : public boost::static_visitor<const mstch::node &>
{
public:
get_token(const std::string &token, const mstch::node &node) : m_token(token), m_node(node) {}
template<class T>
const mstch::node& operator()(const T&) const {
return m_node;
}
template <class T> const mstch::node &operator()(const T &) const { return m_node; }
const mstch::node& operator()(const map& map) const {
return map.at(m_token);
}
const mstch::node &operator()(const map &map) const { return map.at(m_token); }
const mstch::node& operator()(const std::shared_ptr<object>& object) const {
return object->at(m_token);
}
const mstch::node &operator()(const std::shared_ptr<object> &object) const { return object->at(m_token); }
private:
const std::string& m_token;
const mstch::node& m_node;
private:
const std::string &m_token;
const mstch::node &m_node;
};
}

View File

@@ -4,28 +4,21 @@
#include "mstch/mstch.hpp"
namespace mstch {
namespace mstch
{
class has_token: public boost::static_visitor<bool> {
public:
has_token(const std::string& token): m_token(token) {
}
class has_token : public boost::static_visitor<bool>
{
public:
has_token(const std::string &token) : m_token(token) {}
template<class T>
bool operator()(const T&) const {
return m_token == ".";
}
template <class T> bool operator()(const T &) const { return m_token == "."; }
bool operator()(const map& map) const {
return map.count(m_token) == 1;
}
bool operator()(const map &map) const { return map.count(m_token) == 1; }
bool operator()(const std::shared_ptr<object>& object) const {
return object->has(m_token);
}
bool operator()(const std::shared_ptr<object> &object) const { return object->has(m_token); }
private:
const std::string& m_token;
private:
const std::string &m_token;
};
}

View File

@@ -4,38 +4,24 @@
#include "mstch/mstch.hpp"
namespace mstch {
namespace mstch
{
class is_node_empty: public boost::static_visitor<bool> {
public:
template<class T>
bool operator()(const T&) const {
return false;
}
class is_node_empty : public boost::static_visitor<bool>
{
public:
template <class T> bool operator()(const T &) const { return false; }
bool operator()(const std::nullptr_t&) const {
return true;
}
bool operator()(const std::nullptr_t &) const { return true; }
bool operator()(const int& value) const {
return value == 0;
}
bool operator()(const int &value) const { return value == 0; }
bool operator()(const double& value) const {
return value == 0;
}
bool operator()(const double &value) const { return value == 0; }
bool operator()(const bool& value) const {
return !value;
}
bool operator()(const bool &value) const { return !value; }
bool operator()(const std::string& value) const {
return value == "";
}
bool operator()(const std::string &value) const { return value == ""; }
bool operator()(const array& array) const {
return array.size() == 0;
}
bool operator()(const array &array) const { return array.size() == 0; }
};
}

View File

@@ -1,56 +1,52 @@
#pragma once
#include <sstream>
#include <boost/variant/static_visitor.hpp>
#include <sstream>
#include "../render_context.hpp"
#include "mstch/mstch.hpp"
#include "../utils.hpp"
#include "mstch/mstch.hpp"
namespace mstch {
namespace mstch
{
class render_node: public boost::static_visitor<std::string> {
public:
enum class flag { none, escape_html };
render_node(render_context& ctx, flag p_flag = flag::none):
m_ctx(ctx), m_flag(p_flag)
class render_node : public boost::static_visitor<std::string>
{
public:
enum class flag
{
}
none,
escape_html
};
render_node(render_context &ctx, flag p_flag = flag::none) : m_ctx(ctx), m_flag(p_flag) {}
template<class T>
std::string operator()(const T&) const {
return "";
}
template <class T> std::string operator()(const T &) const { return ""; }
std::string operator()(const int& value) const {
return std::to_string(value);
}
std::string operator()(const int &value) const { return std::to_string(value); }
std::string operator()(const double& value) const {
std::string operator()(const double &value) const
{
std::stringstream ss;
ss << value;
return ss.str();
}
std::string operator()(const bool& value) const {
return value ? "true" : "false";
}
std::string operator()(const bool &value) const { return value ? "true" : "false"; }
std::string operator()(const lambda& value) const {
template_type interpreted{value([this](const mstch::node& n) {
return visit(render_node(m_ctx), n);
})};
std::string operator()(const lambda &value) const
{
template_type interpreted{value([this](const mstch::node &n) { return visit(render_node(m_ctx), n); })};
auto rendered = render_context::push(m_ctx).render(interpreted);
return (m_flag == flag::escape_html) ? html_escape(rendered) : rendered;
}
std::string 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:
render_context& m_ctx;
private:
render_context &m_ctx;
flag m_flag;
};
}

View File

@@ -3,55 +3,56 @@
#include <boost/variant/static_visitor.hpp>
#include "../render_context.hpp"
#include "mstch/mstch.hpp"
#include "../utils.hpp"
#include "mstch/mstch.hpp"
#include "render_node.hpp"
namespace mstch {
namespace mstch
{
class render_section: public boost::static_visitor<std::string> {
public:
enum class flag { none, keep_array };
render_section(
render_context& ctx,
const template_type& section,
const delim_type& delims,
flag p_flag = flag::none):
m_ctx(ctx), m_section(section), m_delims(delims), m_flag(p_flag)
class render_section : public boost::static_visitor<std::string>
{
public:
enum class flag
{
none,
keep_array
};
render_section(render_context &ctx, const template_type &section, const delim_type &delims, flag p_flag = flag::none)
: m_ctx(ctx), m_section(section), m_delims(delims), m_flag(p_flag)
{
}
template<class T>
std::string operator()(const T& t) const {
template <class T> std::string operator()(const T &t) const
{
return render_context::push(m_ctx, t).render(m_section);
}
std::string operator()(const lambda& fun) const {
std::string operator()(const lambda &fun) const
{
std::string section_str;
for (auto& token: m_section)
for (auto &token : m_section)
section_str += token.raw();
template_type interpreted{fun([this](const mstch::node& n) {
return visit(render_node(m_ctx), n);
}, section_str), m_delims};
template_type interpreted{fun([this](const mstch::node &n) { return visit(render_node(m_ctx), n); }, section_str),
m_delims};
return render_context::push(m_ctx).render(interpreted);
}
std::string 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(m_ctx, array).render(m_section);
else
for (auto& item: array)
out += visit(render_section(
m_ctx, m_section, m_delims, flag::keep_array), item);
for (auto &item : array)
out += visit(render_section(m_ctx, m_section, m_delims, flag::keep_array), item);
return out;
}
private:
render_context& m_ctx;
const template_type& m_section;
const delim_type& m_delims;
private:
render_context &m_ctx;
const template_type &m_section;
const delim_type &m_delims;
flag m_flag;
};
}