From 73707c2ad0dc57dc8bf064d95a9004bc7d7bf4dd Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 12 May 2017 22:18:03 +0100 Subject: [PATCH] Revert "Pass the ResponseFactory object down to the Response itself." This reverts commit 3bc6c56c035ed5b3adf1c020c715fb2b375f6a22. --- src/tawashi/main.cpp | 10 ++-------- src/tawashi_implem/index_response.cpp | 3 +-- src/tawashi_implem/index_response.hpp | 1 - src/tawashi_implem/pastie_response.cpp | 3 +-- src/tawashi_implem/pastie_response.hpp | 1 - src/tawashi_implem/response.cpp | 4 ---- src/tawashi_implem/response.hpp | 3 --- src/tawashi_implem/response_factory.cpp | 5 ++--- src/tawashi_implem/response_factory.hpp | 8 ++------ src/tawashi_implem/submit_paste_response.cpp | 3 +-- src/tawashi_implem/submit_paste_response.hpp | 1 - test/unit/test_index_response.cpp | 7 ++----- 12 files changed, 11 insertions(+), 38 deletions(-) diff --git a/src/tawashi/main.cpp b/src/tawashi/main.cpp index c9d4241..1074f08 100644 --- a/src/tawashi/main.cpp +++ b/src/tawashi/main.cpp @@ -54,14 +54,8 @@ namespace { } template - std::unique_ptr make_response ( - const Kakoune::SafePtr& parFactory, - const Kakoune::SafePtr& parSettings, - const Kakoune::SafePtr& parCgiEnv - ) { - return static_cast>( - std::make_unique(parFactory, parSettings, &std::cout, parCgiEnv) - ); + std::unique_ptr make_response (const Kakoune::SafePtr& parSettings, const Kakoune::SafePtr& parCgiEnv) { + return static_cast>(std::make_unique(parSettings, &std::cout, parCgiEnv)); } void fill_defaults (tawashi::SettingsBag& parSettings) { diff --git a/src/tawashi_implem/index_response.cpp b/src/tawashi_implem/index_response.cpp index 2bc58d0..76847f0 100644 --- a/src/tawashi_implem/index_response.cpp +++ b/src/tawashi_implem/index_response.cpp @@ -20,12 +20,11 @@ namespace tawashi { IndexResponse::IndexResponse ( - const Kakoune::SafePtr& parFactory, const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv ) : - Response(parFactory, parSettings, parStreamOut, parCgiEnv, false) + Response(parSettings, parStreamOut, parCgiEnv, false) { } } //namespace tawashi diff --git a/src/tawashi_implem/index_response.hpp b/src/tawashi_implem/index_response.hpp index fd6899a..66963ae 100644 --- a/src/tawashi_implem/index_response.hpp +++ b/src/tawashi_implem/index_response.hpp @@ -24,7 +24,6 @@ namespace tawashi { class IndexResponse : public Response { public: IndexResponse ( - const Kakoune::SafePtr& parFactory, const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv diff --git a/src/tawashi_implem/pastie_response.cpp b/src/tawashi_implem/pastie_response.cpp index 005b209..18df2b2 100644 --- a/src/tawashi_implem/pastie_response.cpp +++ b/src/tawashi_implem/pastie_response.cpp @@ -31,12 +31,11 @@ namespace tawashi { } //unnamed namespace PastieResponse::PastieResponse ( - const Kakoune::SafePtr& parFactory, const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv ) : - Response(parFactory, parSettings, parStreamOut, parCgiEnv, true), + Response(parSettings, parStreamOut, parCgiEnv, true), m_langmap_dir(parSettings->as("langmap_dir")), m_plain_text(false), m_syntax_highlight(true) diff --git a/src/tawashi_implem/pastie_response.hpp b/src/tawashi_implem/pastie_response.hpp index f373b8b..8301f99 100644 --- a/src/tawashi_implem/pastie_response.hpp +++ b/src/tawashi_implem/pastie_response.hpp @@ -25,7 +25,6 @@ namespace tawashi { class PastieResponse : public Response { public: PastieResponse ( - const Kakoune::SafePtr& parFactory, const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv diff --git a/src/tawashi_implem/response.cpp b/src/tawashi_implem/response.cpp index 386855c..fe32365 100644 --- a/src/tawashi_implem/response.cpp +++ b/src/tawashi_implem/response.cpp @@ -23,7 +23,6 @@ #include "pathname/pathname.hpp" #include "list_highlight_langs.hpp" #include "cgi_env.hpp" -#include "response_factory.hpp" #include #include #include @@ -109,14 +108,12 @@ namespace tawashi { } //unnamed namespace Response::Response ( - const Kakoune::SafePtr& parFactory, const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv, bool parWantRedis ) : m_resp_value(g_def_response_type), - m_factory(parFactory), //m_page_basename(fetch_page_basename(m_cgi_env)), m_cgi_env(parCgiEnv), m_settings(parSettings), @@ -127,7 +124,6 @@ namespace tawashi { { assert(m_cgi_env); assert(m_stream_out); - assert(m_factory); if (parWantRedis) { m_redis = std::make_unique(make_incredis(*parSettings)); diff --git a/src/tawashi_implem/response.hpp b/src/tawashi_implem/response.hpp index 910930e..b84f01b 100644 --- a/src/tawashi_implem/response.hpp +++ b/src/tawashi_implem/response.hpp @@ -30,7 +30,6 @@ namespace redis { namespace tawashi { class SettingsBag; - class ResponseFactory; namespace cgi { class Env; @@ -49,7 +48,6 @@ namespace tawashi { }; Response ( - const Kakoune::SafePtr& parFactory, const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv, @@ -69,7 +67,6 @@ namespace tawashi { virtual std::string on_mustache_retrieve(); std::string m_resp_value; - Kakoune::SafePtr m_factory; Kakoune::SafePtr m_cgi_env; Kakoune::SafePtr m_settings; std::string m_website_root; diff --git a/src/tawashi_implem/response_factory.cpp b/src/tawashi_implem/response_factory.cpp index aabf6f1..208e2cd 100644 --- a/src/tawashi_implem/response_factory.cpp +++ b/src/tawashi_implem/response_factory.cpp @@ -45,12 +45,11 @@ namespace tawashi { //spdlog::get("statuslog")->info("making response object for \"{}\"", parName); auto maker_it = m_local_data->makers.find(std::string(parName.data(), parName.size())); - Kakoune::SafePtr self(this); if (m_local_data->makers.end() != maker_it) { - return maker_it->second(self, m_local_data->settings, m_local_data->cgi_env); + return maker_it->second(m_local_data->settings, m_local_data->cgi_env); } else if (m_local_data->jolly_maker) { - return m_local_data->jolly_maker(self, m_local_data->settings, m_local_data->cgi_env); + return m_local_data->jolly_maker(m_local_data->settings, m_local_data->cgi_env); } else { assert(false); diff --git a/src/tawashi_implem/response_factory.hpp b/src/tawashi_implem/response_factory.hpp index 2129468..bc42e92 100644 --- a/src/tawashi_implem/response_factory.hpp +++ b/src/tawashi_implem/response_factory.hpp @@ -28,13 +28,9 @@ namespace tawashi { class Env; } //namespace cgi - class ResponseFactory : public Kakoune::SafeCountable { + class ResponseFactory { public: - typedef std::function( - const Kakoune::SafePtr&, - const Kakoune::SafePtr&, - const Kakoune::SafePtr& - )> ResponseMakerFunc; + typedef std::function(const Kakoune::SafePtr&, const Kakoune::SafePtr& parCgiEnv)> ResponseMakerFunc; explicit ResponseFactory (const Kakoune::SafePtr& parSettings, const Kakoune::SafePtr& parCgiEnv); ~ResponseFactory() noexcept; diff --git a/src/tawashi_implem/submit_paste_response.cpp b/src/tawashi_implem/submit_paste_response.cpp index a93d3e5..1b0820d 100644 --- a/src/tawashi_implem/submit_paste_response.cpp +++ b/src/tawashi_implem/submit_paste_response.cpp @@ -90,12 +90,11 @@ namespace tawashi { } //unnamed namespace SubmitPasteResponse::SubmitPasteResponse ( - const Kakoune::SafePtr& parFactory, const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv ) : - Response(parFactory, parSettings, parStreamOut, parCgiEnv, true) + Response(parSettings, parStreamOut, parCgiEnv, true) { this->change_type(Response::ContentType, "text/plain"); } diff --git a/src/tawashi_implem/submit_paste_response.hpp b/src/tawashi_implem/submit_paste_response.hpp index d40d09a..55ad0f5 100644 --- a/src/tawashi_implem/submit_paste_response.hpp +++ b/src/tawashi_implem/submit_paste_response.hpp @@ -26,7 +26,6 @@ namespace tawashi { class SubmitPasteResponse : public Response { public: SubmitPasteResponse ( - const Kakoune::SafePtr& parFactory, const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv diff --git a/test/unit/test_index_response.cpp b/test/unit/test_index_response.cpp index 8cf1051..1e4bc95 100644 --- a/test/unit/test_index_response.cpp +++ b/test/unit/test_index_response.cpp @@ -21,7 +21,6 @@ #include "ini_file.hpp" #include "settings_bag.hpp" #include "safe_stack_object.hpp" -#include "response_factory.hpp" #include #include #include @@ -58,12 +57,11 @@ namespace tawashi { class IndexResponseCustomMustache : public IndexResponse { public: IndexResponseCustomMustache ( - const Kakoune::SafePtr& parFactory, const Kakoune::SafePtr& parSettings, std::ostream* parStreamOut, const Kakoune::SafePtr& parCgiEnv ) : - IndexResponse(parFactory, parSettings, parStreamOut, parCgiEnv) + IndexResponse(parSettings, parStreamOut, parCgiEnv) { } @@ -108,8 +106,7 @@ TEST_CASE ("Index response", "[index][response]") { std::stringstream response_stream; - SafeStackObject resp_factory(settings, fake_env); - tawashi::IndexResponseCustomMustache response(resp_factory, settings, &response_stream, fake_env); + tawashi::IndexResponseCustomMustache response(settings, &response_stream, fake_env); response.send(); response_stream.seekg(0);