replace writeRecord() with sequence of writeAttribute() v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 22 Jul 2018 22:21:49 +0200
branchv_0
changeset 17 f2cccaa9dd38
parent 16 3613617d3076
child 18 90efe2db1ca8
replace writeRecord() with sequence of writeAttribute()
include/RelationalWriter.h
src/StreamRelationalWriter.h
--- a/include/RelationalWriter.h	Sun Jul 22 17:19:25 2018 +0200
+++ b/include/RelationalWriter.h	Sun Jul 22 22:21:49 2018 +0200
@@ -21,12 +21,14 @@
 
 	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;
-	
+	virtual void writeAttribute(const string_t& value) = 0;
+
+	// TODO: fluent interface?
+	// TODO: << operator?
 	// TODO: write bitmap + attribute:
 	// virtual void writeBitmap(...) = 0;
 	// virtual void writeAttribute(string_t attribute) = 0;
-	
+
 	virtual void writeAttribute(const void* value, const std::type_info& type) = 0;
 
 };
--- a/src/StreamRelationalWriter.h	Sun Jul 22 17:19:25 2018 +0200
+++ b/src/StreamRelationalWriter.h	Sun Jul 22 22:21:49 2018 +0200
@@ -92,19 +92,10 @@
 
 	}
 
-	void writeRecord(std::vector<string_t> attributes) override {
-		// FIXME: check vector size
-		// FIXME: check currentColumn == 0
-		for (size_t c = 0; c < columnCount; c++) {
-			// TODO: do not support multiple rows in a single method call
-			if (c % columnCount == 0) {
-				integerWriter.writeValue(output, DATA_PART_ROW);
-			}
-
-			wstring stringValue = attributes[c];
-			TypeId typeId = columnTypes[c % columnCount];
-			writeString(stringValue, typeId);
-		}
+	void writeAttribute(const string_t& value) override {
+		if (currentColumn == 0) integerWriter.writeValue(output, DATA_PART_ROW);
+		writeString(value, columnTypes[currentColumn]);
+		if (++currentColumn == columnCount) currentColumn = 0;
 	}
 
 	void writeAttribute(const void* value, const std::type_info& type) override {