use TypeId enum instead of numeric constants v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 21 Jul 2018 23:46:29 +0200
branchv_0
changeset 13 e7234dd45166
parent 12 640e88aedf8f
child 14 733334eca89b
use TypeId enum instead of numeric constants
include/RelationalWriter.h
include/TypeId.h
nbproject/configurations.xml
src/StreamRelationalWriter.h
src/format.h
src/types/BooleanDataTypeWriter.h
--- a/include/RelationalWriter.h	Sat Jul 21 23:01:47 2018 +0200
+++ b/include/RelationalWriter.h	Sat Jul 21 23:46:29 2018 +0200
@@ -4,7 +4,8 @@
 #include <iostream>
 #include <vector>
 
-#include "../include/typedefs.h"
+#include "typedefs.h"
+#include "TypeId.h"
 
 namespace relpipe {
 namespace writer {
@@ -18,7 +19,7 @@
 
 	virtual string_t toTypeCode(const integer_t typeId) = 0;
 
-	virtual void startRelation(string_t name, std::vector<std::pair<string_t, string_t>> attributes, boolean_t writeHeader) = 0;
+	virtual void startRelation(string_t name, std::vector<std::pair<string_t, TypeId>> attributes, boolean_t writeHeader) = 0;
 
 	virtual void writeRecord(std::vector<string_t> attributes) = 0;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/TypeId.h	Sat Jul 21 23:46:29 2018 +0200
@@ -0,0 +1,13 @@
+#pragma once
+
+namespace relpipe {
+namespace writer {
+
+enum class TypeId {
+	BOOLEAN = 1,
+	INTEGER = 2,
+	STRING = 3,
+};
+
+}
+}
\ No newline at end of file
--- a/nbproject/configurations.xml	Sat Jul 21 23:01:47 2018 +0200
+++ b/nbproject/configurations.xml	Sat Jul 21 23:46:29 2018 +0200
@@ -12,6 +12,7 @@
       <itemPath>include/RelpipeWriterException.h</itemPath>
       <itemPath>src/StreamRelationalWriter.h</itemPath>
       <itemPath>src/types/StringDataTypeWriter.h</itemPath>
+      <itemPath>include/TypeId.h</itemPath>
       <itemPath>src/format.h</itemPath>
       <itemPath>include/typedefs.h</itemPath>
     </logicalFolder>
@@ -50,6 +51,8 @@
       </item>
       <item path="include/RelpipeWriterException.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="include/TypeId.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="include/typedefs.h" ex="false" tool="3" flavor2="0">
       </item>
       <item path="src/DataTypeWriter.h" ex="false" tool="3" flavor2="0">
@@ -93,6 +96,8 @@
       </item>
       <item path="include/RelpipeWriterException.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="include/TypeId.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="include/typedefs.h" ex="false" tool="3" flavor2="0">
       </item>
       <item path="src/DataTypeWriter.h" ex="false" tool="3" flavor2="0">
--- a/src/StreamRelationalWriter.h	Sat Jul 21 23:01:47 2018 +0200
+++ b/src/StreamRelationalWriter.h	Sat Jul 21 23:46:29 2018 +0200
@@ -6,6 +6,7 @@
 
 #include "../include/typedefs.h"
 #include "../include/RelationalWriter.h"
+#include "../include/TypeId.h"
 #include "format.h"
 #include "DataTypeWriterBase.h"
 #include "types/BooleanDataTypeWriter.h"
@@ -54,7 +55,7 @@
 		throw RelpipeWriterException(L"Unsupported data type: " + typeId);
 	}
 
-	void startRelation(string_t name, std::vector<std::pair<string_t, string_t> > attributes, boolean_t writeHeader) override {
+	void startRelation(string_t name, std::vector<std::pair<string_t, TypeId> > attributes, boolean_t writeHeader) override {
 		string_t tableName = name;
 		columnCount = attributes.size();
 
@@ -74,8 +75,7 @@
 
 		// Write column types:
 		for (size_t c = 0; c < columnCount; c++) {
-			wstring typeCode = attributes[c].second;
-			integer_t typeId = toTypeId(typeCode);
+			integer_t typeId = static_cast<integer_t>(attributes[c].second);
 			integerWriter.writeValue(output, typeId);
 			columnTypes[c] = typeId;
 		}
--- a/src/format.h	Sat Jul 21 23:01:47 2018 +0200
+++ b/src/format.h	Sat Jul 21 23:46:29 2018 +0200
@@ -3,12 +3,14 @@
 #include <cstdint>
 #include <string>
 
+#include "../include/TypeId.h"
+
 namespace relpipe {
 namespace writer {
 
-const integer_t DATA_TYPE_ID_BOOLEAN = 1;
-const integer_t DATA_TYPE_ID_INTEGER = 2;
-const integer_t DATA_TYPE_ID_STRING = 3;
+const integer_t DATA_TYPE_ID_BOOLEAN = static_cast<integer_t>(TypeId::BOOLEAN);
+const integer_t DATA_TYPE_ID_INTEGER = static_cast<integer_t>(TypeId::INTEGER);
+const integer_t DATA_TYPE_ID_STRING = static_cast<integer_t>(TypeId::STRING);
 
 const string_t DATA_TYPE_CODE_BOOLEAN = L"boolean";
 const string_t DATA_TYPE_CODE_INTEGER = L"integer";
--- a/src/types/BooleanDataTypeWriter.h	Sat Jul 21 23:01:47 2018 +0200
+++ b/src/types/BooleanDataTypeWriter.h	Sat Jul 21 23:46:29 2018 +0200
@@ -15,7 +15,7 @@
 
 class BooleanDataTypeWriter : public DataTypeWriter<boolean_t> {
 private:
-	const string_t TRUE = L"true";
+    const string_t TRUE = L"true";
 	const string_t FALSE = L"false";
 public:
 
@@ -36,4 +36,4 @@
 
 }
 }
-}
\ No newline at end of file
+}