AttributeMetadata: pImpl / d-pointer version but with memory-leak and unwanted empty constructor v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 15 Sep 2018 22:52:15 +0200
branchv_0
changeset 24 6f7acc3b274c
parent 23 25a53f4cd9eb
child 25 fc0d05b72214
AttributeMetadata: pImpl / d-pointer version but with memory-leak and unwanted empty constructor
include/relpipe/reader/handlers/AttributeMetadata.h
nbproject/configurations.xml
src/AttributeMetadataPrivate.h
src/StreamRelationalReader.h
--- a/include/relpipe/reader/handlers/AttributeMetadata.h	Sun Sep 09 22:47:18 2018 +0200
+++ b/include/relpipe/reader/handlers/AttributeMetadata.h	Sat Sep 15 22:52:15 2018 +0200
@@ -6,11 +6,30 @@
 namespace reader {
 namespace handlers {
 
+class AttributeMetadataPrivate;
+
 class AttributeMetadata {
+private:
+	AttributeMetadataPrivate* impl;
 public:
-	string_t attributeName;
-	relpipe::reader::TypeId typeId;
-	string_t typeName;
+	~AttributeMetadata();
+
+	AttributeMetadata() {
+		std::cout << "FIXME: why call AttributeMetadata() ?" << std::endl;
+	}
+
+	AttributeMetadata(AttributeMetadataPrivate* impl) :
+	impl(impl) {
+	}
+
+	AttributeMetadata(const AttributeMetadata& other) :
+	impl(other.impl) {
+	}
+
+	string_t getAttributeName() const;
+	relpipe::reader::TypeId getTypeId() const;
+	string_t getTypeName() const;
+
 };
 
 }
--- a/nbproject/configurations.xml	Sun Sep 09 22:47:18 2018 +0200
+++ b/nbproject/configurations.xml	Sat Sep 15 22:52:15 2018 +0200
@@ -5,6 +5,7 @@
                    displayName="Header Files"
                    projectFiles="true">
       <itemPath>include/relpipe/reader/handlers/AttributeMetadata.h</itemPath>
+      <itemPath>src/AttributeMetadataPrivate.h</itemPath>
       <itemPath>src/types/BooleanDataTypeReader.h</itemPath>
       <itemPath>src/DataTypeReader.h</itemPath>
       <itemPath>src/DataTypeReaderBase.h</itemPath>
@@ -95,6 +96,8 @@
       </item>
       <item path="include/relpipe/reader/typedefs.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="src/AttributeMetadataPrivate.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="src/DataTypeReader.h" ex="false" tool="3" flavor2="0">
       </item>
       <item path="src/DataTypeReaderBase.h" ex="false" tool="3" flavor2="0">
@@ -171,6 +174,8 @@
       </item>
       <item path="include/relpipe/reader/typedefs.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="src/AttributeMetadataPrivate.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="src/DataTypeReader.h" ex="false" tool="3" flavor2="0">
       </item>
       <item path="src/DataTypeReaderBase.h" ex="false" tool="3" flavor2="0">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/AttributeMetadataPrivate.h	Sat Sep 15 22:52:15 2018 +0200
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "../include/relpipe/reader/typedefs.h"
+#include "../include/relpipe/reader/TypeId.h"
+#include "../include/relpipe/reader/handlers/AttributeMetadata.h"
+
+namespace relpipe {
+namespace reader {
+namespace handlers {
+
+class AttributeMetadataPrivate {
+public:
+	string_t attributeName;
+	relpipe::reader::TypeId typeId;
+	string_t typeName;
+};
+
+AttributeMetadata::~AttributeMetadata() {
+	// delete impl;
+	std::cout << "FIXME: delete impl in ~AttributeMetadata() but no double-delete / smart pointer" << std::endl;
+}
+
+string_t AttributeMetadata::getAttributeName() const {
+	return impl->attributeName;
+}
+
+relpipe::reader::TypeId AttributeMetadata::getTypeId() const {
+	return impl->typeId;
+}
+
+string_t AttributeMetadata::getTypeName() const {
+	return impl->typeName;
+}
+
+}
+}
+}
--- a/src/StreamRelationalReader.h	Sun Sep 09 22:47:18 2018 +0200
+++ b/src/StreamRelationalReader.h	Sat Sep 15 22:52:15 2018 +0200
@@ -12,6 +12,7 @@
 #include "../include/relpipe/reader/handlers/RelationalReaderBaseHandler.h"
 #include "../include/relpipe/reader/handlers/RelationalReaderStringHandler.h"
 #include "../include/relpipe/reader/handlers/RelationalReaderValueHandler.h"
+#include "AttributeMetadataPrivate.h"
 #include "DataTypeReaderBase.h"
 #include "types/BooleanDataTypeReader.h"
 #include "types/IntegerDataTypeReader.h"
@@ -157,7 +158,8 @@
 					columnTypes[i] = typeId;
 
 					// put together names, type ids and type codes:
-					columns[i] = {columnNames[i], columnTypes[i], typeCode};
+					handlers::AttributeMetadataPrivate* xxx = new handlers::AttributeMetadataPrivate({columnNames[i], columnTypes[i], typeCode});
+					columns[i] = handlers::AttributeMetadata(xxx);
 				}
 
 				for (StringHandler* handler : stringHandlers) handler->startRelation(tableName, columns);