src/RecfileCommand.h
branchv_0
changeset 0 515a697cc9cd
child 1 8dfb42e5c088
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/RecfileCommand.h	Fri Apr 05 18:02:19 2019 +0200
@@ -0,0 +1,93 @@
+/**
+ * Relational pipes
+ * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <vector>
+
+#include <relpipe/writer/typedefs.h>
+
+namespace relpipe {
+namespace in {
+namespace recfile {
+
+using namespace relpipe::writer;
+
+class RecfileCommand {
+private:
+
+	enum class RecfileLineType {
+		METADATA,
+		DATA
+	};
+
+	class RecfileHandler {
+	private:
+		RelationalWriter* writer;
+	public:
+
+		RecfileHandler(RelationalWriter* writer) : writer(writer) {
+		}
+
+		virtual ~RecfileHandler() {
+		}
+
+		void logicalLine(const string_t& name, const string_t& value, RecfileLineType type) {
+			std::wcerr << L"logicalLine(" << name << L", " << value << L", " << (int) type << L");" << std::endl; // TODO: remove debug
+			// TODO: writer->startRelation()
+			// TODO: writer->writeAttribute()
+		}
+
+	};
+
+	class RecfileParser {
+	private:
+		RecfileHandler& handler;
+	public:
+
+		RecfileParser(RecfileHandler& handler) : handler(handler) {
+		}
+
+		virtual ~RecfileParser() {
+		}
+
+		void parse(std::istream& input) {
+			// TODO: parse
+			handler.logicalLine(L"nnn", L"vvv", RecfileLineType::METADATA); // TODO: remove debug
+			handler.logicalLine(L"nnn", L"vvv", RecfileLineType::DATA); // TODO: remove debug
+		}
+
+	};
+
+
+
+public:
+
+	void process(std::istream& input, std::ostream& output) {
+		unique_ptr<RelationalWriter> writer(Factory::create(output));
+		RecfileHandler handler(writer.get());
+		RecfileParser parser(handler);
+		parser.parse(input);
+	}
+};
+
+}
+}
+}