author | František Kučera <franta-hg@frantovo.cz> |
Mon, 13 Aug 2018 21:30:32 +0200 | |
branch | v_0 |
changeset 10 | 7fe3975f7e4b |
parent 9 | 517888868e55 |
child 12 | 2d7109286408 |
permissions | -rw-r--r-- |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
#pragma once |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
|
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
#include <string> |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
#include <sstream> |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
#include <iostream> |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
#include <vector> |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
#include <locale> |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
#include <codecvt> |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
10 |
#include "../include/typedefs.h" |
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
11 |
#include "../include/DataTypeReader.h" |
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
12 |
#include "format.h" |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
14 |
namespace relpipe { |
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
15 |
namespace reader { |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
|
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
/** |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
* The prototype does not recognize any encoding, |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
* it just works with c++ strings in encoding default to given platform. |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
* In the real implementation of relational pipes, there will be DataTypes for particular encodings. |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
*/ |
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
22 |
class StringDataTypeReader : public DataTypeReader<string_t> { |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
private: |
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
24 |
IntegerDataTypeReader integerType; |
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
25 |
std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
public: |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
28 |
StringDataTypeReader() : DataTypeReader<string_t>(DATA_TYPE_ID_STRING, DATA_TYPE_CODE_STRING) { |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
} |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
31 |
string_t readValue(std::istream &input) override { |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
integer_t length = integerType.readValue(input); |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
// TODO: check maximum length of single field |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
// if (length > 4000) throw RelpipeException("data too long", EXIT_CODE_DATA_ERROR); |
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
35 |
std::vector<char> buf(length); |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
input.read(buf.data(), length); |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
if (input.good()) { |
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
38 |
return convertor.from_bytes(std::string(buf.data(), length)); |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
} else { |
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
40 |
throw RelpipeReaderException(L"Error while reading string from the stream."); |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
} |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
} |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
44 |
string_t toString(const string_t &value) override { |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
return value; |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
} |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
|
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
}; |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
50 |
} |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
} |