# HG changeset patch # User František Kučera # Date 1532187025 -7200 # Node ID 0a40752e401d13bf3cdcccfec34caf7d05004cd4 # Parent 03750aff86196e3b25df1bb82a978ee13af8a388 shared library with pure abstract class (interface) diff -r 03750aff8619 -r 0a40752e401d include/DataTypeWriter.h --- 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 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 diff -r 03750aff8619 -r 0a40752e401d include/DataTypeWriterBase.h --- 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 -#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 diff -r 03750aff8619 -r 0a40752e401d include/RelationalWriter.h --- /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 +#include +#include + +#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> attributes, boolean_t writeHeader) = 0; + + virtual void writeRecord(std::vector attributes) = 0; + + static RelationalWriter* create(std::ostream &output); +}; + +} +} diff -r 03750aff8619 -r 0a40752e401d nbproject/Makefile-Debug.mk --- 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: diff -r 03750aff8619 -r 0a40752e401d nbproject/Makefile-Release.mk --- 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: diff -r 03750aff8619 -r 0a40752e401d nbproject/configurations.xml --- 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"> src/BooleanDataTypeWriter.h - include/DataTypeWriter.h - include/DataTypeWriterBase.h - src/DataTypeWriterCatalog.h + src/DataTypeWriter.h + src/DataTypeWriterBase.h src/IntegerDataTypeWriter.h + include/RelationalWriter.h include/RelpipeWriterException.h + src/StreamRelationalWriter.h src/StringDataTypeWriter.h src/format.h include/typedefs.h @@ -21,8 +22,7 @@ - src/DataTypeWriter.cpp - src/DataTypeWriterBase.cpp + src/RelationalWriter.cpp - - - + @@ -56,14 +54,16 @@ - + - - - + + + + + @@ -89,9 +89,7 @@ 5 - - - + @@ -99,14 +97,16 @@ - + - - - + + + + + diff -r 03750aff8619 -r 0a40752e401d src/BooleanDataTypeWriter.h --- 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 #include -#include "../include/DataTypeWriter.h" +#include "DataTypeWriter.h" #include "../include/RelpipeWriterException.h" #include "format.h" diff -r 03750aff8619 -r 0a40752e401d src/DataTypeWriter.cpp --- 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 void DataTypeWriter::writeString(std::ostream& output, const string_t &stringValue) { - writeValue(output, toValue(stringValue)); -}; - -} -} diff -r 03750aff8619 -r 0a40752e401d src/DataTypeWriter.h --- /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 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 diff -r 03750aff8619 -r 0a40752e401d src/DataTypeWriterBase.cpp --- 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 -#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; -} - -} -} diff -r 03750aff8619 -r 0a40752e401d src/DataTypeWriterBase.h --- /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 +#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; + } +}; + +} +} diff -r 03750aff8619 -r 0a40752e401d src/DataTypeWriterCatalog.h --- 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 -#include -#include - -#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 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 diff -r 03750aff8619 -r 0a40752e401d src/IntegerDataTypeWriter.h --- 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 #include -#include "../include/DataTypeWriter.h" +#include "DataTypeWriter.h" #include "format.h" namespace relpipe { diff -r 03750aff8619 -r 0a40752e401d src/RelationalWriter.cpp --- /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 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 diff -r 03750aff8619 -r 0a40752e401d src/StringDataTypeWriter.h --- 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 #include -#include "../include/DataTypeWriter.h" +#include "DataTypeWriter.h" #include "format.h" namespace relpipe {