diff -r 03750aff8619 -r 0a40752e401d src/StreamRelationalWriter.h --- /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 +#include +#include + +#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 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 > attributes, boolean_t writeHeader) override { + output << "startRelation(…)" << std::endl; + } + + void writeRecord(std::vector attributes) override { + output << "writeRecord(…)" << std::endl; + } + +}; + +} +} \ No newline at end of file