work with writer instead of ostream v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 23 Sep 2020 11:26:33 +0200
branchv_0
changeset 15 157bb1d5e08a
parent 14 012d491e219a
child 16 15ee963675af
work with writer instead of ostream
src/CSVCommand.cpp
src/CSVCommand.h
src/relpipe-in-csv.cpp
--- a/src/CSVCommand.cpp	Wed Sep 23 11:23:12 2020 +0200
+++ b/src/CSVCommand.cpp	Wed Sep 23 11:26:33 2020 +0200
@@ -87,9 +87,8 @@
 	return false;
 }
 
-void CSVCommand::processDataStream(std::ostream& output, std::istream& input, const vector<relpipe::writer::string_t>& args) {
+void CSVCommand::process(std::istream& input, const vector<relpipe::writer::string_t>& args, std::shared_ptr<writer::RelationalWriter> writer) {
 	wstring_convert < codecvt_utf8<wchar_t>> convertor; // UTF-8 is required for CSV
-	std::shared_ptr<RelationalWriter> writer(Factory::create(output));
 	vector<AttributeMetadata> metadata;
 	bool headerDone = false;
 	bool lastInRecord = false;
--- a/src/CSVCommand.h	Wed Sep 23 11:23:12 2020 +0200
+++ b/src/CSVCommand.h	Wed Sep 23 11:26:33 2020 +0200
@@ -19,6 +19,7 @@
 #include <iostream>
 #include <sstream>
 #include <vector>
+#include <memory>
 
 #include <relpipe/writer/TypeId.h>
 
@@ -30,7 +31,7 @@
 private:
 	bool readValue(std::istream& input, std::stringstream& currentValue, bool& lastInRecord);
 public:
-	void processDataStream(std::ostream &output, std::istream& input, const vector<relpipe::writer::string_t>& args);
+	void process(std::istream& input, const vector<relpipe::writer::string_t>& args, std::shared_ptr<writer::RelationalWriter> writer);
 
 };
 
--- a/src/relpipe-in-csv.cpp	Wed Sep 23 11:23:12 2020 +0200
+++ b/src/relpipe-in-csv.cpp	Wed Sep 23 11:26:33 2020 +0200
@@ -45,7 +45,8 @@
 
 	try {
 		CSVCommand command;
-		command.processDataStream(cout, cin, cli.arguments());
+		std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout));
+		command.process(cin, cli.arguments(), writer);
 		resultCode = CLI::EXIT_CODE_SUCCESS;
 	} catch (RelpipeWriterException e) {
 		fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str());