author | František Kučera <franta-hg@frantovo.cz> |
Sat, 08 Sep 2018 19:42:29 +0200 | |
branch | v_0 |
changeset 19 | 3e1308e7606d |
parent 18 | e11f1ad20826 |
child 21 | abd3e7f26584 |
permissions | -rw-r--r-- |
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
#pragma once |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
#include <string> |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
#include <iostream> |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
#include <vector> |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
#include <relpipe/protocol/constants.h> |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
#include "../include/relpipe/reader/typedefs.h" |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
#include "../include/relpipe/reader/RelationalReader.h" |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
#include "../include/relpipe/reader/TypeId.h" |
16 | 12 |
#include "../include/relpipe/reader/handlers/RelationalReaderBaseHandler.h" |
13 |
#include "../include/relpipe/reader/handlers/RelationalReaderStringHandler.h" |
|
14 |
#include "../include/relpipe/reader/handlers/RelationalReaderValueHandler.h" |
|
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
#include "DataTypeReaderBase.h" |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
#include "types/BooleanDataTypeReader.h" |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
#include "types/IntegerDataTypeReader.h" |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
#include "types/StringDataTypeReader.h" |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
namespace relpipe { |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
namespace reader { |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
using namespace relpipe::protocol; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
class StreamRelationalReader : public RelationalReader { |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
private: |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
std::istream &input; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
types::BooleanDataTypeReader booleanReader; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
types::IntegerDataTypeReader integerReader; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
types::StringDataTypeReader stringReader; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
std::vector<DataTypeReaderBase*> readers = {&booleanReader, &integerReader, &stringReader}; |
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
32 |
|
17
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
33 |
std::vector<handlers::RelationalReaderStringHadler*> stringHandlers; |
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
34 |
std::vector<handlers::RelationalReaderValueHadler*> valueHandlers; |
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
/** |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
* count of columns in the current table |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
*/ |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
integer_t columnCount; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
/** |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
* number of column (0 = first) that will be written; after writing, the number is increased and prepared for next one |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
*/ |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
integer_t currentColumn; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
/** |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
* types of columns in the current table |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
*/ |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
std::vector<TypeId> columnTypes; |
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
49 |
std::vector<string_t> columnNames; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
50 |
std::vector<std::pair<string_t, TypeId>> columns; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
51 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
52 |
/** |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
53 |
* TODO: remove? |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
54 |
*/ |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
55 |
string_t readString(std::istream &input, const TypeId typeId) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
56 |
for (DataTypeReaderBase* reader : readers) if (reader->supports(typeId)) return reader->readString(input); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
57 |
throw RelpipeReaderException(L"Unsupported data type: " + (int) typeId); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
58 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
59 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
60 |
void read(std::istream &input, std::function<void(const void *, const std::type_info&) > handler, const TypeId typeId) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
61 |
for (DataTypeReaderBase* reader : readers) if (reader->supports(typeId)) return reader->read(input, handler); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
62 |
throw RelpipeReaderException(L"Unsupported data type: " + (int) typeId); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
63 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
64 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
65 |
void read(std::istream &input, std::function<void(const string_t&, const void *, const std::type_info&) > handler, const TypeId typeId) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
66 |
for (DataTypeReaderBase* reader : readers) if (reader->supports(typeId)) return reader->read(input, handler); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
67 |
throw RelpipeReaderException(L"Unsupported data type: " + (int) typeId); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
68 |
} |
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
|
19
3e1308e7606d
add endOfPipe() to handlers
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
70 |
void endOfPipe() { |
3e1308e7606d
add endOfPipe() to handlers
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
71 |
for (int i = 0; i < stringHandlers.size(); i++) stringHandlers[i]->endOfPipe(); |
3e1308e7606d
add endOfPipe() to handlers
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
72 |
for (int i = 0; i < valueHandlers.size(); i++) valueHandlers[i]->endOfPipe(); |
3e1308e7606d
add endOfPipe() to handlers
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
73 |
} |
3e1308e7606d
add endOfPipe() to handlers
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
74 |
|
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
75 |
public: |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
StreamRelationalReader(std::istream &input) : |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
input(input) { |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
79 |
} |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
80 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
81 |
string_t toTypeCode(const TypeId typeId) override { |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
82 |
for (DataTypeReaderBase* reader : readers) if (reader->supports(typeId)) return reader->getTypeCode(); |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
83 |
throw RelpipeReaderException(L"Unsupported data type: " + static_cast<integer_t> (typeId)); |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
84 |
} |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
85 |
|
17
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
86 |
void addHandler(handlers::RelationalReaderStringHadler* handler) override { |
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
87 |
stringHandlers.push_back(handler); |
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
88 |
} |
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
89 |
|
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
90 |
void addHandler(handlers::RelationalReaderValueHadler* handler) override { |
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
91 |
valueHandlers.push_back(handler); |
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
92 |
} |
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
93 |
|
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
94 |
void process() override { |
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
95 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
96 |
while (true) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
97 |
integer_t dataPart; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
98 |
try { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
99 |
dataPart = integerReader.readValue(input); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
100 |
// output << "dataPart: " << dataPart << endl; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
101 |
} catch (RelpipeReaderException e) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
102 |
if (input.eof() && input.gcount() == 0) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
103 |
if (dataPart == DATA_PART_ROW) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
104 |
// last part was row |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
105 |
// input was fully read |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
106 |
// we are finished |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
107 |
// TODO: printCachedData(output); ??? |
19
3e1308e7606d
add endOfPipe() to handlers
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
108 |
endOfPipe(); |
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
109 |
return; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
110 |
} else if (dataPart == DATA_PART_START) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
111 |
// Empty relation might be weird but it is valid data. |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
112 |
// Actually, it is not so weird as it looks. |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
113 |
// fwprintf(stderr, L"Warning: The table has no rows. Weird… but OK.\n"); |
19
3e1308e7606d
add endOfPipe() to handlers
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
114 |
endOfPipe(); |
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
115 |
return; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
116 |
} else { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
117 |
// in current format, there is no other data part |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
118 |
// so this will never happen |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
119 |
// but maybe later… |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
120 |
throw RelpipeReaderException(L"Unexpected EOF"); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
121 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
122 |
} else if (input.eof()) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
123 |
fwprintf(stderr, L"Error: found some unexpected data on the input stream: %d\n", input.gcount()); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
124 |
throw e; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
125 |
} else { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
126 |
// other error |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
127 |
throw e; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
128 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
129 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
130 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
131 |
if (dataPart == DATA_PART_START) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
132 |
// Print data of previous table |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
133 |
// TODO: if (values.size() > 0) printCachedData(output); ??? |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
134 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
135 |
// Read table name |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
136 |
string_t tableName = stringReader.readValue(input); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
137 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
138 |
// Read column count |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
139 |
columnCount = integerReader.readValue(input); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
140 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
141 |
columnTypes.resize(columnCount); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
142 |
columnNames.resize(columnCount); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
143 |
columns.resize(columnCount); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
144 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
145 |
// Read column names |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
146 |
for (int i = 0; i < columnCount; i++) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
147 |
columnNames[i] = stringReader.readValue(input); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
148 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
149 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
150 |
// Read column types |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
151 |
for (int i = 0; i < columnCount; i++) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
152 |
TypeId typeId = (TypeId) integerReader.readValue(input); // TODO: přetypování OK? |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
153 |
string_t typeCode = toTypeCode(typeId); // validate typeId TODO: je potřeba? |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
154 |
columnTypes[i] = typeId; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
155 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
156 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
157 |
for (int i = 0; i < columnCount; i++) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
158 |
columns[i] = {columnNames[i], columnTypes[i]}; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
159 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
160 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
161 |
for (int i = 0; i < stringHandlers.size(); i++) stringHandlers[i]->startRelation(tableName, columns); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
162 |
for (int i = 0; i < valueHandlers.size(); i++) valueHandlers[i]->startRelation(tableName, columns); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
163 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
164 |
} else if (dataPart == DATA_PART_ROW) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
165 |
for (int i = 0; i < columnCount; i++) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
166 |
TypeId typeId = columnTypes[i]; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
167 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
168 |
if (stringHandlers.empty()) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
169 |
read(input, [&](const void * rawValue, const std::type_info & typeInfo) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
170 |
for (int i = 0; i < valueHandlers.size(); i++) valueHandlers[i]->attribute(rawValue, typeInfo); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
171 |
}, typeId); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
172 |
} else { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
173 |
read(input, [&](const string_t& stringValue, const void * rawValue, const std::type_info & typeInfo) { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
174 |
for (int i = 0; i < stringHandlers.size(); i++) stringHandlers[i]->attribute(stringValue); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
175 |
for (int i = 0; i < valueHandlers.size(); i++) valueHandlers[i]->attribute(rawValue, typeInfo); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
176 |
}, typeId); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
177 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
178 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
179 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
180 |
} else { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
181 |
throw RelpipeReaderException(L"Unknown data part"); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
182 |
} |
17
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
183 |
} |
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
184 |
|
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
185 |
throw RelpipeReaderException(L"Unexpected exception"); // should never happen |
17
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
186 |
|
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
187 |
} |
ec750c536705
interface + dummy implementation
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
188 |
|
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
189 |
}; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
190 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
191 |
} |
19
3e1308e7606d
add endOfPipe() to handlers
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
192 |
} |