From af7f6768fd2caa17043ce746e33fea2ba0cfc862 Mon Sep 17 00:00:00 2001 From: bog Date: Sat, 14 Oct 2023 18:03:21 +0200 Subject: [PATCH] :building_construction: interpreter doesn't depends on std::cout anymore. --- src/Interpreter.cpp | 18 ++++++++++-------- src/Interpreter.hpp | 5 +++-- src/main.cpp | 2 +- tests/Interpreter.cpp | 3 ++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Interpreter.cpp b/src/Interpreter.cpp index 4096370..97de129 100644 --- a/src/Interpreter.cpp +++ b/src/Interpreter.cpp @@ -7,10 +7,12 @@ namespace sn { /*explicit*/ Interpreter::Interpreter(std::shared_ptr state, std::shared_ptr loader, - std::shared_ptr executor) + std::shared_ptr executor, + std::ostream& ostream) : m_state { state } , m_loader { loader } , m_executor { executor } + , m_ostream { ostream } { } @@ -106,19 +108,19 @@ namespace sn int const SPACE = 2; int const WIDTH = max_w + SQUARES_W + SPACE; - std::cout << std::setw(WIDTH); - std::cout << std::left; + m_ostream << std::setw(WIDTH); + m_ostream << std::left; - std::cout << "[" + file.filename().string() + "]"; + m_ostream << "[" + file.filename().string() + "]"; - std::cout << std::setw(WIDTH); - std::cout << script << std::endl; + m_ostream << std::setw(WIDTH); + m_ostream << script << std::endl; auto ret = execute(script); if (ret.empty() == false) { - std::cout << ret << std::endl; + m_ostream << ret << std::endl; } } } @@ -128,7 +130,7 @@ namespace sn if (sorted.empty()) { - std::cout << "everything is up to date" << std::endl; + m_ostream << "everything is up to date" << std::endl; } } diff --git a/src/Interpreter.hpp b/src/Interpreter.hpp index 5ad755a..3a5468c 100644 --- a/src/Interpreter.hpp +++ b/src/Interpreter.hpp @@ -23,7 +23,8 @@ namespace sn public: explicit Interpreter(std::shared_ptr state, std::shared_ptr loader, - std::shared_ptr executor); + std::shared_ptr executor, + std::ostream& ostream); virtual ~Interpreter(); void run(); @@ -32,7 +33,7 @@ namespace sn std::shared_ptr m_state; std::shared_ptr m_loader; std::shared_ptr m_executor; - + std::ostream& m_ostream; std::unordered_map> m_dependencies; diff --git a/src/main.cpp b/src/main.cpp index 5d2a7d9..e655120 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,7 @@ int main(int, char**) auto loader = std::make_shared(); auto executor = std::make_shared(); - sn::Interpreter interpreter {state, loader, executor}; + sn::Interpreter interpreter {state, loader, executor, std::cout}; interpreter.run(); return 0; diff --git a/tests/Interpreter.cpp b/tests/Interpreter.cpp index 5bb6b59..bf556a2 100644 --- a/tests/Interpreter.cpp +++ b/tests/Interpreter.cpp @@ -70,7 +70,8 @@ public: auto loader = std::make_shared(snakefile); auto executor = std::make_shared(); - Interpreter interpreter {state, loader, executor}; + std::stringstream ss; + Interpreter interpreter {state, loader, executor, ss}; interpreter.run(); return executor->history;