|
1 /** |
|
2 * Relational pipes |
|
3 * Copyright © 2019 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 <iostream> |
|
21 #include <string> |
|
22 #include <sstream> |
|
23 #include <vector> |
|
24 |
|
25 #include <relpipe/writer/typedefs.h> |
|
26 |
|
27 namespace relpipe { |
|
28 namespace in { |
|
29 namespace recfile { |
|
30 |
|
31 using namespace relpipe::writer; |
|
32 |
|
33 class RecfileCommand { |
|
34 private: |
|
35 |
|
36 enum class RecfileLineType { |
|
37 METADATA, |
|
38 DATA |
|
39 }; |
|
40 |
|
41 class RecfileHandler { |
|
42 private: |
|
43 RelationalWriter* writer; |
|
44 public: |
|
45 |
|
46 RecfileHandler(RelationalWriter* writer) : writer(writer) { |
|
47 } |
|
48 |
|
49 virtual ~RecfileHandler() { |
|
50 } |
|
51 |
|
52 void logicalLine(const string_t& name, const string_t& value, RecfileLineType type) { |
|
53 std::wcerr << L"logicalLine(" << name << L", " << value << L", " << (int) type << L");" << std::endl; // TODO: remove debug |
|
54 // TODO: writer->startRelation() |
|
55 // TODO: writer->writeAttribute() |
|
56 } |
|
57 |
|
58 }; |
|
59 |
|
60 class RecfileParser { |
|
61 private: |
|
62 RecfileHandler& handler; |
|
63 public: |
|
64 |
|
65 RecfileParser(RecfileHandler& handler) : handler(handler) { |
|
66 } |
|
67 |
|
68 virtual ~RecfileParser() { |
|
69 } |
|
70 |
|
71 void parse(std::istream& input) { |
|
72 // TODO: parse |
|
73 handler.logicalLine(L"nnn", L"vvv", RecfileLineType::METADATA); // TODO: remove debug |
|
74 handler.logicalLine(L"nnn", L"vvv", RecfileLineType::DATA); // TODO: remove debug |
|
75 } |
|
76 |
|
77 }; |
|
78 |
|
79 |
|
80 |
|
81 public: |
|
82 |
|
83 void process(std::istream& input, std::ostream& output) { |
|
84 unique_ptr<RelationalWriter> writer(Factory::create(output)); |
|
85 RecfileHandler handler(writer.get()); |
|
86 RecfileParser parser(handler); |
|
87 parser.parse(input); |
|
88 } |
|
89 }; |
|
90 |
|
91 } |
|
92 } |
|
93 } |