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 <cstdlib> |
|
21 #include <iostream> |
|
22 #include <string> |
|
23 #include <vector> |
|
24 #include <algorithm> |
|
25 |
|
26 #include <relpipe/writer/typedefs.h> |
|
27 #include <relpipe/writer/AttributeMetadata.h> |
|
28 |
|
29 #include "Command.h" |
|
30 |
|
31 namespace relpipe { |
|
32 namespace in { |
|
33 namespace cli { |
|
34 |
|
35 class ArgumentsCommand : public Command { |
|
36 public: |
|
37 |
|
38 void process(std::istream& input, std::ostream& output, const relpipe::writer::string_t& command, const std::vector<relpipe::writer::string_t>& arguments) override { |
|
39 using namespace relpipe::writer; |
|
40 |
|
41 size_t i = 0; |
|
42 string_t relationName = arguments[i++]; |
|
43 integer_t attributeCount = std::stoul(arguments[i++]); // TODO: use integer data type's method? |
|
44 boolean_t writeHeader = true; // TODO: add option for header omitting |
|
45 |
|
46 // TODO: check argument count |
|
47 |
|
48 std::shared_ptr<RelationalWriter> writer(Factory::create(output)); |
|
49 |
|
50 std::vector<AttributeMetadata> attributes(attributeCount); |
|
51 |
|
52 for (size_t j = 0; j < attributeCount; j++) { |
|
53 string_t attributeName = arguments[i++]; |
|
54 TypeId attributeType = writer->toTypeId(arguments[i++]); |
|
55 attributes[j] = {attributeName, attributeType}; |
|
56 } |
|
57 |
|
58 writer->startRelation(relationName, attributes, writeHeader); |
|
59 |
|
60 for (; i < arguments.size(); i++) { |
|
61 writer->writeAttribute(arguments[i]); |
|
62 } |
|
63 } |
|
64 }; |
|
65 |
|
66 } |
|
67 } |
|
68 } |
|