From 3998b9839f52308d3aa1eb92d79984d1fdcc9d54 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 24 Mar 2022 17:19:42 +0100 Subject: [PATCH] kraken: refactor to interleave input and output --- src/kraken.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/kraken.cc b/src/kraken.cc index 6adfd8f..e228e55 100644 --- a/src/kraken.cc +++ b/src/kraken.cc @@ -1,5 +1,6 @@ #include +#include "csv/read-csv.hh" #include "csv/write-csv.hh" #include "engine/csv-engine-listener.hh" #include "engine/engine.hh" @@ -15,13 +16,17 @@ int main(int argc, char** argv) { } } - auto const orders = kraken::parse::parse_orders(std::cin); - auto listener = std::make_shared(); - auto engine = kraken::engine::Engine(listener, cross_behaviour); - engine.process_orders(orders); + for (std::string line; std::getline(std::cin, line);) { + auto const order = kraken::parse::parse_single_order( + kraken::csv::read_csv_line(line)); - kraken::csv::write_csv(std::cout, listener->output()); + engine.process_single_order(order); + + auto& output = listener->output(); + kraken::csv::write_csv(std::cout, output); + output.resize(0); + } }