# HG changeset patch # User František Kučera # Date 1532247982 -7200 # Node ID 8fd6c4d44071d12dafd5e7f25d8789b4bba723c6 # Parent 733334eca89b3dc51ab45ec3a8a969b3f551fa93 use more TypeId enum diff -r 733334eca89b -r 8fd6c4d44071 include/RelationalWriter.h --- a/include/RelationalWriter.h Sun Jul 22 00:08:13 2018 +0200 +++ b/include/RelationalWriter.h Sun Jul 22 10:26:22 2018 +0200 @@ -15,9 +15,9 @@ virtual ~RelationalWriter() = default; - virtual integer_t toTypeId(const string_t typeCode) = 0; + virtual TypeId toTypeId(const string_t typeCode) = 0; - virtual string_t toTypeCode(const integer_t typeId) = 0; + virtual string_t toTypeCode(const TypeId typeId) = 0; virtual void startRelation(string_t name, std::vector> attributes, boolean_t writeHeader) = 0; diff -r 733334eca89b -r 8fd6c4d44071 src/DataTypeWriter.h --- a/src/DataTypeWriter.h Sun Jul 22 00:08:13 2018 +0200 +++ b/src/DataTypeWriter.h Sun Jul 22 10:26:22 2018 +0200 @@ -8,7 +8,7 @@ template class DataTypeWriter : public DataTypeWriterBase { public: - DataTypeWriter(const integer_t typeId, const string_t typeCode) : DataTypeWriterBase(typeId, typeCode) { + DataTypeWriter(const TypeId typeId, const string_t typeCode) : DataTypeWriterBase(typeId, typeCode) { } virtual ~DataTypeWriter() { diff -r 733334eca89b -r 8fd6c4d44071 src/DataTypeWriterBase.h --- a/src/DataTypeWriterBase.h Sun Jul 22 00:08:13 2018 +0200 +++ b/src/DataTypeWriterBase.h Sun Jul 22 10:26:22 2018 +0200 @@ -11,11 +11,11 @@ */ class DataTypeWriterBase { private: - const integer_t typeId; + const TypeId typeId; const string_t typeCode; public: - DataTypeWriterBase(const integer_t typeId, const string_t typeCode) : + DataTypeWriterBase(const TypeId typeId, const string_t typeCode) : typeId(typeId), typeCode(typeCode) { } @@ -35,7 +35,7 @@ * @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) { + virtual bool supports(const TypeId &dataType) { return dataType == typeId; } @@ -47,7 +47,7 @@ return dataType == typeCode; } - integer_t getTypeId() { + TypeId getTypeId() { return typeId; } diff -r 733334eca89b -r 8fd6c4d44071 src/StreamRelationalWriter.h --- a/src/StreamRelationalWriter.h Sun Jul 22 00:08:13 2018 +0200 +++ b/src/StreamRelationalWriter.h Sun Jul 22 10:26:22 2018 +0200 @@ -23,20 +23,20 @@ types::IntegerDataTypeWriter integerWriter; types::StringDataTypeWriter stringWriter; vector writers = {&booleanWriter, &integerWriter, &stringWriter}; - + /** * count of columns in the current table */ integer_t columnCount; - + /** * types of columns in the current table */ - vector columnTypes; + vector columnTypes; - void writeString(const string_t &stringValue, const integer_t typeId) { + void writeString(const string_t &stringValue, const TypeId typeId) { for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->writeString(output, stringValue); - throw RelpipeWriterException(L"Unsupported data type: " + typeId); + throw RelpipeWriterException(L"Unsupported data type: " + static_cast(typeId)); } public: @@ -45,16 +45,16 @@ output(output) { } - integer_t toTypeId(const string_t typeCode) override { + TypeId 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 { + string_t toTypeCode(const TypeId typeId) override { for (DataTypeWriterBase* writer : writers) if (writer->supports(typeId)) return writer->getTypeCode(); - throw RelpipeWriterException(L"Unsupported data type: " + typeId); + throw RelpipeWriterException(L"Unsupported data type: " + static_cast(typeId)); } - + void startRelation(string_t name, std::vector > attributes, boolean_t writeHeader) override { string_t tableName = name; columnCount = attributes.size(); @@ -69,14 +69,14 @@ // Write column names: for (size_t c = 0; c < columnCount; c++) { - wstring columnName = attributes[c].first; + wstring columnName = attributes[c].first; stringWriter.writeValue(output, columnName); } // Write column types: for (size_t c = 0; c < columnCount; c++) { - integer_t typeId = static_cast(attributes[c].second); - integerWriter.writeValue(output, typeId); + TypeId typeId = attributes[c].second; + integerWriter.writeValue(output, static_cast(typeId)); columnTypes[c] = typeId; } @@ -91,7 +91,7 @@ } wstring stringValue = attributes[c]; - integer_t typeId = columnTypes[c % columnCount]; + TypeId typeId = columnTypes[c % columnCount]; writeString(stringValue, typeId); } } diff -r 733334eca89b -r 8fd6c4d44071 src/format.h --- a/src/format.h Sun Jul 22 00:08:13 2018 +0200 +++ b/src/format.h Sun Jul 22 10:26:22 2018 +0200 @@ -8,10 +8,6 @@ namespace relpipe { namespace writer { -const integer_t DATA_TYPE_ID_BOOLEAN = static_cast(TypeId::BOOLEAN); -const integer_t DATA_TYPE_ID_INTEGER = static_cast(TypeId::INTEGER); -const integer_t DATA_TYPE_ID_STRING = static_cast(TypeId::STRING); - const string_t DATA_TYPE_CODE_BOOLEAN = L"boolean"; const string_t DATA_TYPE_CODE_INTEGER = L"integer"; const string_t DATA_TYPE_CODE_STRING = L"string"; diff -r 733334eca89b -r 8fd6c4d44071 src/types/BooleanDataTypeWriter.h --- a/src/types/BooleanDataTypeWriter.h Sun Jul 22 00:08:13 2018 +0200 +++ b/src/types/BooleanDataTypeWriter.h Sun Jul 22 10:26:22 2018 +0200 @@ -19,7 +19,7 @@ const string_t FALSE = L"false"; public: - BooleanDataTypeWriter() : DataTypeWriter(DATA_TYPE_ID_BOOLEAN, DATA_TYPE_CODE_BOOLEAN) { + BooleanDataTypeWriter() : DataTypeWriter(TypeId::BOOLEAN, DATA_TYPE_CODE_BOOLEAN) { } void writeValue(std::ostream &output, const boolean_t &value) override { diff -r 733334eca89b -r 8fd6c4d44071 src/types/IntegerDataTypeWriter.h --- a/src/types/IntegerDataTypeWriter.h Sun Jul 22 00:08:13 2018 +0200 +++ b/src/types/IntegerDataTypeWriter.h Sun Jul 22 10:26:22 2018 +0200 @@ -82,7 +82,7 @@ public: - IntegerDataTypeWriter() : DataTypeWriter(DATA_TYPE_ID_INTEGER, DATA_TYPE_CODE_INTEGER) { + IntegerDataTypeWriter() : DataTypeWriter(TypeId::INTEGER, DATA_TYPE_CODE_INTEGER) { } void writeValue(std::ostream &output, const integer_t &value) override { diff -r 733334eca89b -r 8fd6c4d44071 src/types/StringDataTypeWriter.h --- a/src/types/StringDataTypeWriter.h Sun Jul 22 00:08:13 2018 +0200 +++ b/src/types/StringDataTypeWriter.h Sun Jul 22 10:26:22 2018 +0200 @@ -26,7 +26,7 @@ std::wstring_convert> convertor; // TODO: support also other encodings. public: - StringDataTypeWriter() : DataTypeWriter(DATA_TYPE_ID_STRING, DATA_TYPE_CODE_STRING) { + StringDataTypeWriter() : DataTypeWriter(TypeId::STRING, DATA_TYPE_CODE_STRING) { } void writeValue(std::ostream &output, const string_t &value) override {