src/StreamRelationalReader.h
branchv_0
changeset 14 e8de089f95dd
child 16 9b8139bb0519
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/StreamRelationalReader.h	Sat Aug 25 18:16:53 2018 +0200
@@ -0,0 +1,58 @@
+#pragma once
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+#include <relpipe/protocol/constants.h>
+
+#include "../include/relpipe/reader/typedefs.h"
+#include "../include/relpipe/reader/RelationalReader.h"
+#include "../include/relpipe/reader/TypeId.h"
+#include "DataTypeReaderBase.h"
+#include "types/BooleanDataTypeReader.h"
+#include "types/IntegerDataTypeReader.h"
+#include "types/StringDataTypeReader.h"
+
+namespace relpipe {
+namespace reader {
+
+using namespace relpipe::protocol;
+
+class StreamRelationalReader : public RelationalReader {
+private:
+	std::istream &input;
+	types::BooleanDataTypeReader booleanReader;
+	types::IntegerDataTypeReader integerReader;
+	types::StringDataTypeReader stringReader;
+	std::vector<DataTypeReaderBase*> readers = {&booleanReader, &integerReader, &stringReader};
+
+	/**
+	 * count of columns in the current table
+	 */
+	integer_t columnCount;
+	/**
+	 * number of column (0 = first) that will be written; after writing, the number is increased and prepared for next one
+	 */
+	integer_t currentColumn;
+
+	/**
+	 * types of columns in the current table
+	 */
+	std::vector<TypeId> columnTypes;
+
+public:
+
+	StreamRelationalReader(std::istream &input) :
+	input(input) {
+	}
+
+	string_t toTypeCode(const TypeId typeId) override {
+		for (DataTypeReaderBase* reader : readers) if (reader->supports(typeId)) return reader->getTypeCode();
+		throw RelpipeReaderException(L"Unsupported data type: " + static_cast<integer_t> (typeId));
+	}
+
+};
+
+}
+}
\ No newline at end of file