base classes v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 08 Jul 2018 01:40:38 +0200
branchv_0
changeset 1 6e3494943c91
parent 0 ea747b9d46d0
child 2 1a574113da20
base classes
.hgignore
DataTypeWriter.cpp
DataTypeWriter.h
DataTypeWriterBase.cpp
DataTypeWriterBase.h
common.h
nbproject/Makefile-Debug.mk
nbproject/Makefile-Release.mk
nbproject/configurations.xml
nbproject/project.xml
--- a/.hgignore	Sat Jul 07 18:13:02 2018 +0200
+++ b/.hgignore	Sun Jul 08 01:40:38 2018 +0200
@@ -6,6 +6,7 @@
 
 ^temp/
 
+^\.dep\.inc
 ^dist/
 ^build/
 ^nbproject/private/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DataTypeWriter.cpp	Sun Jul 08 01:40:38 2018 +0200
@@ -0,0 +1,15 @@
+#include "DataTypeWriter.h"
+
+namespace relpipe {
+namespace writer {
+
+template<typename T> string_t DataTypeWriter<T>::readString(std::istream &input) {
+	return toString(readValue(input));
+};
+
+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/DataTypeWriter.h	Sun Jul 08 01:40:38 2018 +0200
@@ -0,0 +1,31 @@
+#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 T readValue(std::istream& input) = 0;
+
+	virtual string_t readString(std::istream &input);
+
+	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;
+	virtual string_t toString(const T& value) = 0;
+
+};
+
+}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DataTypeWriterBase.cpp	Sun Jul 08 01:40:38 2018 +0200
@@ -0,0 +1,24 @@
+#include <string>
+#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/DataTypeWriterBase.h	Sun Jul 08 01:40:38 2018 +0200
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <string>
+#include "common.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() {
+	};
+
+	virtual string_t readString(std::istream &input) = 0;
+
+	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/common.h	Sun Jul 08 01:40:38 2018 +0200
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <cstdint>
+#include <string>
+
+namespace relpipe {
+namespace writer {
+
+using octet_t = uint8_t;
+using integer_t = uint64_t;
+using boolean_t = bool;
+using string_t = std::wstring;
+
+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 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";
+
+
+/**
+ * With respect for the tradition and computer pioneers, we use same numbers as in ASCII texts:
+ * 
+ * 1C    FS  ␜  File Separator
+ * 1D    GS  ␝  Group Separator
+ * 1E    RS  ␞  Record Separator
+ * 1F    US  ␟  Unit Separator
+ * 
+ */
+const integer_t DATA_PART_START = 0x1D;
+const integer_t DATA_PART_ROW = 0x1E;
+
+}
+}
\ No newline at end of file
--- a/nbproject/Makefile-Debug.mk	Sat Jul 07 18:13:02 2018 +0200
+++ b/nbproject/Makefile-Debug.mk	Sun Jul 08 01:40:38 2018 +0200
@@ -34,7 +34,9 @@
 OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}
 
 # Object Files
-OBJECTFILES=
+OBJECTFILES= \
+	${OBJECTDIR}/DataTypeWriter.o \
+	${OBJECTDIR}/DataTypeWriterBase.o
 
 
 # C Compiler Flags
@@ -59,7 +61,17 @@
 
 ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librelpipe-lib-writer.cpp.${CND_DLIB_EXT}: ${OBJECTFILES}
 	${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
-	${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librelpipe-lib-writer.cpp.${CND_DLIB_EXT} ${OBJECTFILES} ${LDLIBSOPTIONS} -shared -fPIC
+	${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librelpipe-lib-writer.cpp.${CND_DLIB_EXT} ${OBJECTFILES} ${LDLIBSOPTIONS} -shared -fPIC
+
+${OBJECTDIR}/DataTypeWriter.o: DataTypeWriter.cpp
+	${MKDIR} -p ${OBJECTDIR}
+	${RM} "$@.d"
+	$(COMPILE.cc) -g -fPIC  -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/DataTypeWriter.o DataTypeWriter.cpp
+
+${OBJECTDIR}/DataTypeWriterBase.o: DataTypeWriterBase.cpp
+	${MKDIR} -p ${OBJECTDIR}
+	${RM} "$@.d"
+	$(COMPILE.cc) -g -fPIC  -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/DataTypeWriterBase.o DataTypeWriterBase.cpp
 
 # Subprojects
 .build-subprojects:
--- a/nbproject/Makefile-Release.mk	Sat Jul 07 18:13:02 2018 +0200
+++ b/nbproject/Makefile-Release.mk	Sun Jul 08 01:40:38 2018 +0200
@@ -34,7 +34,9 @@
 OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}
 
 # Object Files
-OBJECTFILES=
+OBJECTFILES= \
+	${OBJECTDIR}/DataTypeWriter.o \
+	${OBJECTDIR}/DataTypeWriterBase.o
 
 
 # C Compiler Flags
@@ -59,7 +61,17 @@
 
 ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librelpipe-lib-writer.cpp.${CND_DLIB_EXT}: ${OBJECTFILES}
 	${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
-	${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librelpipe-lib-writer.cpp.${CND_DLIB_EXT} ${OBJECTFILES} ${LDLIBSOPTIONS} -shared -fPIC
+	${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/librelpipe-lib-writer.cpp.${CND_DLIB_EXT} ${OBJECTFILES} ${LDLIBSOPTIONS} -shared -fPIC
+
+${OBJECTDIR}/DataTypeWriter.o: DataTypeWriter.cpp
+	${MKDIR} -p ${OBJECTDIR}
+	${RM} "$@.d"
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/DataTypeWriter.o DataTypeWriter.cpp
+
+${OBJECTDIR}/DataTypeWriterBase.o: DataTypeWriterBase.cpp
+	${MKDIR} -p ${OBJECTDIR}
+	${RM} "$@.d"
+	$(COMPILE.cc) -O2 -fPIC  -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/DataTypeWriterBase.o DataTypeWriterBase.cpp
 
 # Subprojects
 .build-subprojects:
--- a/nbproject/configurations.xml	Sat Jul 07 18:13:02 2018 +0200
+++ b/nbproject/configurations.xml	Sun Jul 08 01:40:38 2018 +0200
@@ -4,6 +4,9 @@
     <logicalFolder name="HeaderFiles"
                    displayName="Header Files"
                    projectFiles="true">
+      <itemPath>DataTypeWriter.h</itemPath>
+      <itemPath>DataTypeWriterBase.h</itemPath>
+      <itemPath>common.h</itemPath>
     </logicalFolder>
     <logicalFolder name="ResourceFiles"
                    displayName="Resource Files"
@@ -12,6 +15,8 @@
     <logicalFolder name="SourceFiles"
                    displayName="Source Files"
                    projectFiles="true">
+      <itemPath>DataTypeWriter.cpp</itemPath>
+      <itemPath>DataTypeWriterBase.cpp</itemPath>
     </logicalFolder>
     <logicalFolder name="TestFiles"
                    displayName="Test Files"
@@ -35,6 +40,16 @@
       </toolsSet>
       <compileType>
       </compileType>
+      <item path="DataTypeWriter.cpp" ex="false" tool="1" flavor2="0">
+      </item>
+      <item path="DataTypeWriter.h" ex="false" tool="3" flavor2="0">
+      </item>
+      <item path="DataTypeWriterBase.cpp" ex="false" tool="1" flavor2="0">
+      </item>
+      <item path="DataTypeWriterBase.h" ex="false" tool="3" flavor2="0">
+      </item>
+      <item path="common.h" ex="false" tool="3" flavor2="0">
+      </item>
     </conf>
     <conf name="Release" type="2">
       <toolsSet>
@@ -56,6 +71,16 @@
           <developmentMode>5</developmentMode>
         </asmTool>
       </compileType>
+      <item path="DataTypeWriter.cpp" ex="false" tool="1" flavor2="0">
+      </item>
+      <item path="DataTypeWriter.h" ex="false" tool="3" flavor2="0">
+      </item>
+      <item path="DataTypeWriterBase.cpp" ex="false" tool="1" flavor2="0">
+      </item>
+      <item path="DataTypeWriterBase.h" ex="false" tool="3" flavor2="0">
+      </item>
+      <item path="common.h" ex="false" tool="3" flavor2="0">
+      </item>
     </conf>
   </confs>
 </configurationDescriptor>
--- a/nbproject/project.xml	Sat Jul 07 18:13:02 2018 +0200
+++ b/nbproject/project.xml	Sun Jul 08 01:40:38 2018 +0200
@@ -5,8 +5,9 @@
         <data xmlns="http://www.netbeans.org/ns/make-project/1">
             <name>relpipe-lib-writer.cpp</name>
             <c-extensions/>
-            <cpp-extensions/>
-            <header-extensions/>
+            <cpp-extensions>cpp</cpp-extensions>
+            <header-extensions>h</header-extensions>
+            <sourceEncoding>UTF-8</sourceEncoding>
             <make-dep-projects/>
             <sourceRootList/>
             <confList>
@@ -19,7 +20,6 @@
                     <type>2</type>
                 </confElem>
             </confList>
-            <sourceEncoding>UTF-8</sourceEncoding>
             <formatting>
                 <project-formatting-style>false</project-formatting-style>
             </formatting>