src/StreamRelationalWriter.h
branchv_0
changeset 9 0a40752e401d
parent 8 03750aff8619
child 10 40ab091e5dfa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/StreamRelationalWriter.h	Sat Jul 21 17:30:25 2018 +0200
@@ -0,0 +1,57 @@
+#pragma once
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+#include "../include/typedefs.h"
+#include "../include/RelationalWriter.h"
+#include "DataTypeWriterBase.h"
+#include "BooleanDataTypeWriter.h"
+#include "IntegerDataTypeWriter.h"
+#include "StringDataTypeWriter.h"
+
+namespace relpipe {
+namespace writer {
+
+class StreamRelationalWriter : public RelationalWriter {
+private:
+	std::ostream &output;
+	BooleanDataTypeWriter booleanWriter;
+	IntegerDataTypeWriter integerWriter;
+	StringDataTypeWriter stringWriter;
+	vector<DataTypeWriterBase*> writers = {&booleanWriter, &integerWriter, &stringWriter};
+
+	void writeString(const string_t &stringValue, const integer_t typeId) {
+		for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->writeString(output, stringValue);
+		throw RelpipeWriterException(L"Unsupported data type: " + typeId);
+	}
+
+public:
+
+	StreamRelationalWriter(std::ostream &output) :
+	output(output) {
+	}
+
+	integer_t toTypeId(const string_t typeCode) override {
+		for (DataTypeWriterBase* writer : writers) if (writer->supports(typeCode)) return writer->getTypeId();
+		throw RelpipeWriterException(L"Unsupported data type: " + typeCode);
+	}
+
+	string_t toTypeCode(const integer_t typeId) override {
+		for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->getTypeCode();
+		throw RelpipeWriterException(L"Unsupported data type: " + typeId);
+	}
+
+	void startRelation(std::vector<std::pair<string_t, string_t> > attributes, boolean_t writeHeader) override {
+		output << "startRelation(…)" << std::endl;
+	}
+
+	void writeRecord(std::vector<string_t> attributes) override {
+		output << "writeRecord(…)" << std::endl;
+	}
+
+};
+
+}
+}
\ No newline at end of file