src/types/StringDataTypeWriter.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 22 Jul 2018 10:26:22 +0200
branchv_0
changeset 15 8fd6c4d44071
parent 10 40ab091e5dfa
child 23 d505eaedc35e
permissions -rw-r--r--
use more TypeId enum
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#pragma once
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#include <string>
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
#include <sstream>
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
#include <iostream>
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
#include <vector>
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#include <locale>
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
#include <codecvt>
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
10
40ab091e5dfa move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    10
#include "../DataTypeWriter.h"
40ab091e5dfa move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    11
#include "../format.h"
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    13
namespace relpipe {
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    14
namespace writer {
10
40ab091e5dfa move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    15
namespace types {
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
10
40ab091e5dfa move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    17
using namespace relpipe::writer;
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
/**
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
 * The prototype does not recognize any encoding,
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
 * it just works with c++ strings in encoding default to given platform. 
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
 * In the real implementation of relational pipes, there will be DataTypes for particular encodings.
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
 */
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    23
class StringDataTypeWriter : public DataTypeWriter<string_t> {
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
private:
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    25
	IntegerDataTypeWriter integerType;
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    26
	std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
public:
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    29
	StringDataTypeWriter() : DataTypeWriter<string_t>(TypeId::STRING, DATA_TYPE_CODE_STRING) {
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
	}
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    32
	void writeValue(std::ostream &output, const string_t &value) override {
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    33
		std::string s = convertor.to_bytes(value);
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
		integerType.writeValue(output, s.length());
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		output << s.c_str();
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	}
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    38
	wstring toValue(const string_t &stringValue) override {
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		return stringValue;
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	}
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
};
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    44
}
10
40ab091e5dfa move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    45
}
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
}