From 12a2c9bbf2c7654c3cf20614ee8ddf59b7ccafda Mon Sep 17 00:00:00 2001 From: pantor Date: Wed, 1 Sep 2021 16:40:43 +0200 Subject: [PATCH] unify json data type --- include/inja/environment.hpp | 4 ---- include/inja/function_storage.hpp | 2 -- include/inja/inja.hpp | 4 ++++ include/inja/node.hpp | 6 ++---- include/inja/parser.hpp | 1 - include/inja/renderer.hpp | 4 +--- single_include/inja/inja.hpp | 21 +++++++-------------- test/benchmark.cpp | 5 ++--- 8 files changed, 16 insertions(+), 31 deletions(-) diff --git a/include/inja/environment.hpp b/include/inja/environment.hpp index c4bd7de..18563a8 100644 --- a/include/inja/environment.hpp +++ b/include/inja/environment.hpp @@ -7,8 +7,6 @@ #include #include -#include - #include "config.hpp" #include "function_storage.hpp" #include "parser.hpp" @@ -19,8 +17,6 @@ namespace inja { -using json = nlohmann::json; - /*! * \brief Class for changing the configuration. */ diff --git a/include/inja/function_storage.hpp b/include/inja/function_storage.hpp index 3e8e513..1e30a0f 100644 --- a/include/inja/function_storage.hpp +++ b/include/inja/function_storage.hpp @@ -7,8 +7,6 @@ namespace inja { -using json = nlohmann::json; - using Arguments = std::vector; using CallbackFunction = std::function; using VoidCallbackFunction = std::function; diff --git a/include/inja/inja.hpp b/include/inja/inja.hpp index d4e2ab1..569edc2 100644 --- a/include/inja/inja.hpp +++ b/include/inja/inja.hpp @@ -27,6 +27,10 @@ SOFTWARE. #include +namespace inja { + using json = nlohmann::json; +} + #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(INJA_NOEXCEPTION) #ifndef INJA_THROW #define INJA_THROW(exception) throw exception diff --git a/include/inja/node.hpp b/include/inja/node.hpp index cafd83c..9e8ed32 100644 --- a/include/inja/node.hpp +++ b/include/inja/node.hpp @@ -4,8 +4,6 @@ #include #include -#include - #include "function_storage.hpp" #include "string_view.hpp" @@ -100,9 +98,9 @@ public: class LiteralNode : public ExpressionNode { public: - const nlohmann::json value; + const json value; - explicit LiteralNode(const nlohmann::json& value, size_t pos) : ExpressionNode(pos), value(value) { } + explicit LiteralNode(const json& value, size_t pos) : ExpressionNode(pos), value(value) { } void accept(NodeVisitor& v) const { v.visit(*this); diff --git a/include/inja/parser.hpp b/include/inja/parser.hpp index 6eea857..65e4bce 100644 --- a/include/inja/parser.hpp +++ b/include/inja/parser.hpp @@ -17,7 +17,6 @@ #include "token.hpp" #include "utils.hpp" -#include namespace inja { diff --git a/include/inja/renderer.hpp b/include/inja/renderer.hpp index 54e7322..063600c 100644 --- a/include/inja/renderer.hpp +++ b/include/inja/renderer.hpp @@ -7,8 +7,6 @@ #include #include -#include - #include "config.hpp" #include "exceptions.hpp" #include "node.hpp" @@ -689,7 +687,7 @@ class Renderer : public NodeVisitor { std::string ptr = node.key; replace_substring(ptr, ".", "/"); ptr = "/" + ptr; - json_additional_data[nlohmann::json::json_pointer(ptr)] = *eval_expression_list(node.expression); + json_additional_data[json::json_pointer(ptr)] = *eval_expression_list(node.expression); } public: diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp index 8d73d34..7cbdb97 100644 --- a/single_include/inja/inja.hpp +++ b/single_include/inja/inja.hpp @@ -27,6 +27,10 @@ SOFTWARE. #include +namespace inja { + using json = nlohmann::json; +} + #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(INJA_NOEXCEPTION) #ifndef INJA_THROW #define INJA_THROW(exception) throw exception @@ -51,8 +55,6 @@ SOFTWARE. #include #include -#include - // #include "config.hpp" #ifndef INCLUDE_INJA_CONFIG_HPP_ #define INCLUDE_INJA_CONFIG_HPP_ @@ -1562,8 +1564,6 @@ struct RenderConfig { namespace inja { -using json = nlohmann::json; - using Arguments = std::vector; using CallbackFunction = std::function; using VoidCallbackFunction = std::function; @@ -2367,8 +2367,6 @@ public: #include #include -#include - // #include "function_storage.hpp" // #include "string_view.hpp" @@ -2465,9 +2463,9 @@ public: class LiteralNode : public ExpressionNode { public: - const nlohmann::json value; + const json value; - explicit LiteralNode(const nlohmann::json& value, size_t pos) : ExpressionNode(pos), value(value) { } + explicit LiteralNode(const json& value, size_t pos) : ExpressionNode(pos), value(value) { } void accept(NodeVisitor& v) const { v.visit(*this); @@ -2860,7 +2858,6 @@ using TemplateStorage = std::map; // #include "utils.hpp" -#include namespace inja { @@ -3498,8 +3495,6 @@ public: #include #include -#include - // #include "config.hpp" // #include "exceptions.hpp" @@ -4185,7 +4180,7 @@ class Renderer : public NodeVisitor { std::string ptr = node.key; replace_substring(ptr, ".", "/"); ptr = "/" + ptr; - json_additional_data[nlohmann::json::json_pointer(ptr)] = *eval_expression_list(node.expression); + json_additional_data[json::json_pointer(ptr)] = *eval_expression_list(node.expression); } public: @@ -4221,8 +4216,6 @@ public: namespace inja { -using json = nlohmann::json; - /*! * \brief Class for changing the configuration. */ diff --git a/test/benchmark.cpp b/test/benchmark.cpp index 571a3ed..2cfc07b 100644 --- a/test/benchmark.cpp +++ b/test/benchmark.cpp @@ -3,14 +3,13 @@ #include "hayai/hayai.hpp" #include -using json = nlohmann::json; inja::Environment env; const std::string test_file_directory {"../test/data/benchmark/"}; -json small_data = env.load_json(test_file_directory + "small_data.json"); -json large_data = env.load_json(test_file_directory + "large_data.json"); +auto small_data = env.load_json(test_file_directory + "small_data.json"); +auto large_data = env.load_json(test_file_directory + "large_data.json"); std::string medium_template = env.load_file(test_file_directory + "medium_template.txt"); std::string large_template = env.load_file(test_file_directory + "large_template.txt");