src/DataTypeWriterBase.h
branchv_0
changeset 9 0a40752e401d
parent 5 7fe870c3362f
child 15 8fd6c4d44071
--- /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;
+	}
+};
+
+}
+}