equal
deleted
inserted
replaced
|
1 #pragma once |
|
2 |
|
3 #include <string> |
|
4 #include <sstream> |
|
5 #include <iostream> |
|
6 #include <vector> |
|
7 #include <locale> |
|
8 #include <codecvt> |
|
9 |
|
10 #include "../include/DataTypeWriter.h" |
|
11 #include "format.h" |
|
12 |
|
13 namespace relpipe { |
|
14 namespace writer { |
|
15 |
|
16 /** |
|
17 * The prototype does not recognize any encoding, |
|
18 * it just works with c++ strings in encoding default to given platform. |
|
19 * In the real implementation of relational pipes, there will be DataTypes for particular encodings. |
|
20 */ |
|
21 class StringDataTypeWriter : public DataTypeWriter<string_t> { |
|
22 private: |
|
23 IntegerDataTypeWriter integerType; |
|
24 std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
|
25 public: |
|
26 |
|
27 StringDataTypeWriter() : DataTypeWriter<string_t>(DATA_TYPE_ID_STRING, DATA_TYPE_CODE_STRING) { |
|
28 } |
|
29 |
|
30 void writeValue(std::ostream &output, const string_t &value) override { |
|
31 std::string s = convertor.to_bytes(value); |
|
32 integerType.writeValue(output, s.length()); |
|
33 output << s.c_str(); |
|
34 } |
|
35 |
|
36 wstring toValue(const string_t &stringValue) override { |
|
37 return stringValue; |
|
38 } |
|
39 |
|
40 }; |
|
41 |
|
42 } |
|
43 } |