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