--- a/include/DataTypeWriter.h Sun Jul 15 00:45:21 2018 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#pragma once
-
-#include "DataTypeWriterBase.h"
-
-namespace relpipe {
-namespace writer {
-
-template<typename T> class DataTypeWriter : public DataTypeWriterBase {
-public:
-
- DataTypeWriter(const integer_t typeId, const string_t typeCode) : DataTypeWriterBase(typeId, typeCode) {
- }
-
- virtual ~DataTypeWriter() {
- };
-
- virtual void writeValue(std::ostream& output, const T& value) = 0;
-
- virtual void writeString(std::ostream& output, const string_t &stringValue);
-
- virtual T toValue(const string_t &stringValue) = 0;
-
-};
-
-}
-}
\ No newline at end of file
--- a/include/DataTypeWriterBase.h Sun Jul 15 00:45:21 2018 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-#pragma once
-
-#include <string>
-#include "typedefs.h"
-
-namespace relpipe {
-namespace writer {
-
-/**
- * This class contains common features that are independent from particular data type (generic/template type)
- */
-class DataTypeWriterBase {
-private:
- const integer_t typeId;
- const string_t typeCode;
-public:
-
- DataTypeWriterBase(const integer_t typeId, const string_t typeCode) :
- typeId(typeId), typeCode(typeCode) {
- }
-
- virtual ~DataTypeWriterBase() {
- };
-
- /**
- * @param output output stream, should be at position where the value is to be written; the stream will not be closed not flushed after writing
- * @param stringValue write value as given data type (e.g. integer or boolean); stringValue parameter contains given value in string representation of given data type
- * E.g. integer 123 is passed as a character string "123"
- * boolean true is passed as a character string "true".
- * See Relational pipes format specification for details.
- */
- virtual void writeString(std::ostream& output, const string_t &stringValue) = 0;
-
- /**
- * @param dataType data type code as defined in DDP L0
- * @return whether this class supports conversions of this type
- */
- virtual bool supports(const integer_t &dataType);
-
- /**
- * @param dataType data type name as defined in DDP L0
- * @return whether this class supports conversions of this type
- */
- virtual bool supports(const string_t &dataType);
-
- integer_t getTypeId();
-
- string_t getTypeCode();
-};
-
-}
-}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/RelationalWriter.h Sat Jul 21 17:30:25 2018 +0200
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+#include "../include/typedefs.h"
+
+namespace relpipe {
+namespace writer {
+
+class RelationalWriter {
+public:
+
+ virtual ~RelationalWriter() = default;
+
+ virtual integer_t toTypeId(const string_t typeCode) = 0;
+
+ virtual string_t toTypeCode(const integer_t typeId) = 0;
+
+ virtual void startRelation(std::vector<std::pair<string_t, string_t>> attributes, boolean_t writeHeader) = 0;
+
+ virtual void writeRecord(std::vector<string_t> attributes) = 0;
+
+ static RelationalWriter* create(std::ostream &output);
+};
+
+}
+}
--- a/nbproject/Makefile-Debug.mk Sun Jul 15 00:45:21 2018 +0200
+++ b/nbproject/Makefile-Debug.mk Sat Jul 21 17:30:25 2018 +0200
@@ -35,8 +35,7 @@
# Object Files
OBJECTFILES= \
- ${OBJECTDIR}/src/DataTypeWriter.o \
- ${OBJECTDIR}/src/DataTypeWriterBase.o
+ ${OBJECTDIR}/src/RelationalWriter.o
# C Compiler Flags
@@ -63,15 +62,10 @@
${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librelpipe-lib-writer.cpp.${CND_DLIB_EXT} ${OBJECTFILES} ${LDLIBSOPTIONS} -shared -fPIC
-${OBJECTDIR}/src/DataTypeWriter.o: src/DataTypeWriter.cpp
+${OBJECTDIR}/src/RelationalWriter.o: src/RelationalWriter.cpp
${MKDIR} -p ${OBJECTDIR}/src
${RM} "$@.d"
- $(COMPILE.cc) -g -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/DataTypeWriter.o src/DataTypeWriter.cpp
-
-${OBJECTDIR}/src/DataTypeWriterBase.o: src/DataTypeWriterBase.cpp
- ${MKDIR} -p ${OBJECTDIR}/src
- ${RM} "$@.d"
- $(COMPILE.cc) -g -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/DataTypeWriterBase.o src/DataTypeWriterBase.cpp
+ $(COMPILE.cc) -g -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/RelationalWriter.o src/RelationalWriter.cpp
# Subprojects
.build-subprojects:
--- a/nbproject/Makefile-Release.mk Sun Jul 15 00:45:21 2018 +0200
+++ b/nbproject/Makefile-Release.mk Sat Jul 21 17:30:25 2018 +0200
@@ -35,8 +35,7 @@
# Object Files
OBJECTFILES= \
- ${OBJECTDIR}/src/DataTypeWriter.o \
- ${OBJECTDIR}/src/DataTypeWriterBase.o
+ ${OBJECTDIR}/src/RelationalWriter.o
# C Compiler Flags
@@ -63,15 +62,10 @@
${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librelpipe-lib-writer.cpp.${CND_DLIB_EXT} ${OBJECTFILES} ${LDLIBSOPTIONS} -shared -fPIC
-${OBJECTDIR}/src/DataTypeWriter.o: src/DataTypeWriter.cpp
+${OBJECTDIR}/src/RelationalWriter.o: src/RelationalWriter.cpp
${MKDIR} -p ${OBJECTDIR}/src
${RM} "$@.d"
- $(COMPILE.cc) -O2 -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/DataTypeWriter.o src/DataTypeWriter.cpp
-
-${OBJECTDIR}/src/DataTypeWriterBase.o: src/DataTypeWriterBase.cpp
- ${MKDIR} -p ${OBJECTDIR}/src
- ${RM} "$@.d"
- $(COMPILE.cc) -O2 -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/DataTypeWriterBase.o src/DataTypeWriterBase.cpp
+ $(COMPILE.cc) -O2 -fPIC -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/RelationalWriter.o src/RelationalWriter.cpp
# Subprojects
.build-subprojects:
--- a/nbproject/configurations.xml Sun Jul 15 00:45:21 2018 +0200
+++ b/nbproject/configurations.xml Sat Jul 21 17:30:25 2018 +0200
@@ -5,11 +5,12 @@
displayName="Header Files"
projectFiles="true">
<itemPath>src/BooleanDataTypeWriter.h</itemPath>
- <itemPath>include/DataTypeWriter.h</itemPath>
- <itemPath>include/DataTypeWriterBase.h</itemPath>
- <itemPath>src/DataTypeWriterCatalog.h</itemPath>
+ <itemPath>src/DataTypeWriter.h</itemPath>
+ <itemPath>src/DataTypeWriterBase.h</itemPath>
<itemPath>src/IntegerDataTypeWriter.h</itemPath>
+ <itemPath>include/RelationalWriter.h</itemPath>
<itemPath>include/RelpipeWriterException.h</itemPath>
+ <itemPath>src/StreamRelationalWriter.h</itemPath>
<itemPath>src/StringDataTypeWriter.h</itemPath>
<itemPath>src/format.h</itemPath>
<itemPath>include/typedefs.h</itemPath>
@@ -21,8 +22,7 @@
<logicalFolder name="SourceFiles"
displayName="Source Files"
projectFiles="true">
- <itemPath>src/DataTypeWriter.cpp</itemPath>
- <itemPath>src/DataTypeWriterBase.cpp</itemPath>
+ <itemPath>src/RelationalWriter.cpp</itemPath>
</logicalFolder>
<logicalFolder name="TestFiles"
displayName="Test Files"
@@ -46,9 +46,7 @@
</toolsSet>
<compileType>
</compileType>
- <item path="include/DataTypeWriter.h" ex="false" tool="3" flavor2="0">
- </item>
- <item path="include/DataTypeWriterBase.h" ex="false" tool="3" flavor2="0">
+ <item path="include/RelationalWriter.h" ex="false" tool="3" flavor2="0">
</item>
<item path="include/RelpipeWriterException.h" ex="false" tool="3" flavor2="0">
</item>
@@ -56,14 +54,16 @@
</item>
<item path="src/BooleanDataTypeWriter.h" ex="false" tool="3" flavor2="0">
</item>
- <item path="src/DataTypeWriter.cpp" ex="false" tool="1" flavor2="0">
+ <item path="src/DataTypeWriter.h" ex="false" tool="3" flavor2="0">
</item>
- <item path="src/DataTypeWriterBase.cpp" ex="false" tool="1" flavor2="0">
- </item>
- <item path="src/DataTypeWriterCatalog.h" ex="false" tool="3" flavor2="0">
+ <item path="src/DataTypeWriterBase.h" ex="false" tool="3" flavor2="0">
</item>
<item path="src/IntegerDataTypeWriter.h" ex="false" tool="3" flavor2="0">
</item>
+ <item path="src/RelationalWriter.cpp" ex="false" tool="1" flavor2="0">
+ </item>
+ <item path="src/StreamRelationalWriter.h" ex="false" tool="3" flavor2="0">
+ </item>
<item path="src/StringDataTypeWriter.h" ex="false" tool="3" flavor2="0">
</item>
<item path="src/format.h" ex="false" tool="3" flavor2="0">
@@ -89,9 +89,7 @@
<developmentMode>5</developmentMode>
</asmTool>
</compileType>
- <item path="include/DataTypeWriter.h" ex="false" tool="3" flavor2="0">
- </item>
- <item path="include/DataTypeWriterBase.h" ex="false" tool="3" flavor2="0">
+ <item path="include/RelationalWriter.h" ex="false" tool="3" flavor2="0">
</item>
<item path="include/RelpipeWriterException.h" ex="false" tool="3" flavor2="0">
</item>
@@ -99,14 +97,16 @@
</item>
<item path="src/BooleanDataTypeWriter.h" ex="false" tool="3" flavor2="0">
</item>
- <item path="src/DataTypeWriter.cpp" ex="false" tool="1" flavor2="0">
+ <item path="src/DataTypeWriter.h" ex="false" tool="3" flavor2="0">
</item>
- <item path="src/DataTypeWriterBase.cpp" ex="false" tool="1" flavor2="0">
- </item>
- <item path="src/DataTypeWriterCatalog.h" ex="false" tool="3" flavor2="0">
+ <item path="src/DataTypeWriterBase.h" ex="false" tool="3" flavor2="0">
</item>
<item path="src/IntegerDataTypeWriter.h" ex="false" tool="3" flavor2="0">
</item>
+ <item path="src/RelationalWriter.cpp" ex="false" tool="1" flavor2="0">
+ </item>
+ <item path="src/StreamRelationalWriter.h" ex="false" tool="3" flavor2="0">
+ </item>
<item path="src/StringDataTypeWriter.h" ex="false" tool="3" flavor2="0">
</item>
<item path="src/format.h" ex="false" tool="3" flavor2="0">
--- a/src/BooleanDataTypeWriter.h Sun Jul 15 00:45:21 2018 +0200
+++ b/src/BooleanDataTypeWriter.h Sat Jul 21 17:30:25 2018 +0200
@@ -3,7 +3,7 @@
#include <string>
#include <iostream>
-#include "../include/DataTypeWriter.h"
+#include "DataTypeWriter.h"
#include "../include/RelpipeWriterException.h"
#include "format.h"
--- a/src/DataTypeWriter.cpp Sun Jul 15 00:45:21 2018 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-#include "../include/DataTypeWriter.h"
-
-namespace relpipe {
-namespace writer {
-
-template<typename T> void DataTypeWriter<T>::writeString(std::ostream& output, const string_t &stringValue) {
- writeValue(output, toValue(stringValue));
-};
-
-}
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/DataTypeWriter.h Sat Jul 21 17:30:25 2018 +0200
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "DataTypeWriterBase.h"
+
+namespace relpipe {
+namespace writer {
+
+template<typename T> class DataTypeWriter : public DataTypeWriterBase {
+public:
+
+ DataTypeWriter(const integer_t typeId, const string_t typeCode) : DataTypeWriterBase(typeId, typeCode) {
+ }
+
+ virtual ~DataTypeWriter() {
+ };
+
+ virtual void writeValue(std::ostream& output, const T& value) = 0;
+
+ void writeString(std::ostream& output, const string_t &stringValue) override {
+ writeValue(output, toValue(stringValue));
+ }
+
+ virtual T toValue(const string_t &stringValue) = 0;
+
+};
+
+}
+}
\ No newline at end of file
--- a/src/DataTypeWriterBase.cpp Sun Jul 15 00:45:21 2018 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#include <string>
-#include "../include/DataTypeWriterBase.h"
-
-namespace relpipe {
-namespace writer {
-
-bool DataTypeWriterBase::supports(const integer_t &dataType) {
- return dataType == typeId;
-}
-
-bool DataTypeWriterBase::supports(const string_t &dataType) {
- return dataType == typeCode;
-}
-
-integer_t DataTypeWriterBase::getTypeId() {
- return typeId;
-}
-
-string_t DataTypeWriterBase::getTypeCode() {
- return typeCode;
-}
-
-}
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/DataTypeWriterBase.h Sat Jul 21 17:30:25 2018 +0200
@@ -0,0 +1,60 @@
+#pragma once
+
+#include <string>
+#include "../include/typedefs.h"
+
+namespace relpipe {
+namespace writer {
+
+/**
+ * This class contains common features that are independent from particular data type (generic/template type)
+ */
+class DataTypeWriterBase {
+private:
+ const integer_t typeId;
+ const string_t typeCode;
+public:
+
+ DataTypeWriterBase(const integer_t typeId, const string_t typeCode) :
+ typeId(typeId), typeCode(typeCode) {
+ }
+
+ virtual ~DataTypeWriterBase() {
+ };
+
+ /**
+ * @param output output stream, should be at position where the value is to be written; the stream will not be closed not flushed after writing
+ * @param stringValue write value as given data type (e.g. integer or boolean); stringValue parameter contains given value in string representation of given data type
+ * E.g. integer 123 is passed as a character string "123"
+ * boolean true is passed as a character string "true".
+ * See Relational pipes format specification for details.
+ */
+ virtual void writeString(std::ostream& output, const string_t &stringValue) = 0;
+
+ /**
+ * @param dataType data type code as defined in DDP L0
+ * @return whether this class supports conversions of this type
+ */
+ virtual bool supports(const integer_t &dataType) {
+ return dataType == typeId;
+ }
+
+ /**
+ * @param dataType data type name as defined in DDP L0
+ * @return whether this class supports conversions of this type
+ */
+ virtual bool supports(const string_t &dataType) {
+ return dataType == typeCode;
+ }
+
+ integer_t getTypeId() {
+ return typeId;
+ }
+
+ string_t getTypeCode() {
+ return typeCode;
+ }
+};
+
+}
+}
--- a/src/DataTypeWriterCatalog.h Sun Jul 15 00:45:21 2018 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-#pragma once
-
-#include <string>
-#include <iostream>
-#include <vector>
-
-#include "../include/typedefs.h"
-#include "../include/DataTypeWriterBase.h"
-#include "BooleanDataTypeWriter.h"
-#include "IntegerDataTypeWriter.h"
-#include "StringDataTypeWriter.h"
-
-namespace relpipe {
-namespace writer {
-
-class DataTypeCatalog {
-private:
- BooleanDataTypeWriter booleanWriter;
- IntegerDataTypeWriter integerWriter;
- StringDataTypeWriter stringWriter;
- vector<DataTypeWriterBase*> writers = {&booleanWriter, &integerWriter, &stringWriter};
-public:
-
- integer_t toTypeId(const string_t typeCode) {
- 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) {
- for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->getTypeCode();
- throw RelpipeWriterException(L"Unsupported data type: " + typeId);
- }
-
- void writeString(std::ostream &output, 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);
- }
-
-};
-
-}
-}
\ No newline at end of file
--- a/src/IntegerDataTypeWriter.h Sun Jul 15 00:45:21 2018 +0200
+++ b/src/IntegerDataTypeWriter.h Sat Jul 21 17:30:25 2018 +0200
@@ -5,7 +5,7 @@
#include <cassert>
#include <limits>
-#include "../include/DataTypeWriter.h"
+#include "DataTypeWriter.h"
#include "format.h"
namespace relpipe {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/RelationalWriter.cpp Sat Jul 21 17:30:25 2018 +0200
@@ -0,0 +1,12 @@
+#include "../include/RelationalWriter.h"
+#include "StreamRelationalWriter.h"
+
+namespace relpipe {
+namespace writer {
+
+RelationalWriter* RelationalWriter::create(std::ostream& output) {
+ return new StreamRelationalWriter(output);
+}
+
+}
+}
\ No newline at end of file
--- /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
--- a/src/StringDataTypeWriter.h Sun Jul 15 00:45:21 2018 +0200
+++ b/src/StringDataTypeWriter.h Sat Jul 21 17:30:25 2018 +0200
@@ -7,7 +7,7 @@
#include <locale>
#include <codecvt>
-#include "../include/DataTypeWriter.h"
+#include "DataTypeWriter.h"
#include "format.h"
namespace relpipe {