|
1 /** |
|
2 * Relational pipes |
|
3 * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 #pragma once |
|
19 |
|
20 #include <memory> |
|
21 #include <string> |
|
22 #include <vector> |
|
23 #include <iostream> |
|
24 #include <sstream> |
|
25 #include <locale> |
|
26 #include <codecvt> |
|
27 #include <regex> |
|
28 |
|
29 #include <relpipe/reader/typedefs.h> |
|
30 #include <relpipe/reader/TypeId.h> |
|
31 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h> |
|
32 #include <relpipe/reader/handlers/AttributeMetadata.h> |
|
33 |
|
34 #include <relpipe/writer/Factory.h> |
|
35 |
|
36 namespace relpipe { |
|
37 namespace tr { |
|
38 namespace validator { |
|
39 |
|
40 using namespace relpipe; |
|
41 using namespace relpipe::reader; |
|
42 using namespace relpipe::reader::handlers; |
|
43 |
|
44 // TODO: use rather RelationalReaderStringHadler |
|
45 class PassthroughHandler : public RelationalReaderStringHadler { |
|
46 private: |
|
47 writer::RelationalWriter* relationalWriter; |
|
48 public: |
|
49 |
|
50 PassthroughHandler(std::ostream& output) : relationalWriter(writer::Factory::create(output)) { |
|
51 } |
|
52 |
|
53 virtual ~PassthroughHandler() { |
|
54 delete relationalWriter; |
|
55 } |
|
56 |
|
57 void startRelation(string_t name, std::vector<AttributeMetadata> attributes) override { |
|
58 // TODO: move to a reusable method (or use same metadata on both reader and writer side?) |
|
59 std::vector<writer::AttributeMetadata> writerMetadata; |
|
60 for (AttributeMetadata readerMetadata : attributes) { |
|
61 writerMetadata.push_back({readerMetadata.getAttributeName(), relationalWriter->toTypeId(readerMetadata.getTypeName())}); |
|
62 } |
|
63 |
|
64 relationalWriter->startRelation(name, writerMetadata, true); |
|
65 } |
|
66 |
|
67 void attribute(const string_t& value) override { |
|
68 relationalWriter->writeAttribute(value); |
|
69 } |
|
70 |
|
71 void endOfPipe() { |
|
72 |
|
73 } |
|
74 |
|
75 }; |
|
76 |
|
77 } |
|
78 } |
|
79 } |