|
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 |
|
28 #include "Command.h" |
|
29 |
|
30 namespace relpipe { |
|
31 namespace in { |
|
32 namespace cli { |
|
33 |
|
34 class DemoCommand : public Command { |
|
35 public: |
|
36 |
|
37 void process(std::istream& input, std::ostream& output, const relpipe::writer::string_t& command, const std::vector<relpipe::writer::string_t>& arguments) override { |
|
38 using namespace relpipe::writer; |
|
39 std::shared_ptr<RelationalWriter> writer(Factory::create(output)); |
|
40 |
|
41 |
|
42 // Various data types passed as strings |
|
43 writer->startRelation(L"table_from_strings",{ |
|
44 {L"s", TypeId::STRING}, |
|
45 {L"i", TypeId::INTEGER}, |
|
46 {L"b", TypeId::BOOLEAN} |
|
47 }, true); |
|
48 |
|
49 writer->writeAttribute(L"a"); |
|
50 writer->writeAttribute(L"1"); |
|
51 writer->writeAttribute(L"true"); |
|
52 |
|
53 writer->writeAttribute(L"b"); |
|
54 writer->writeAttribute(L"2"); |
|
55 writer->writeAttribute(L"false"); |
|
56 |
|
57 |
|
58 // Various data types passed as raw pointers + typeids |
|
59 writer->startRelation(L"from_raw_pointers",{ |
|
60 {L"s", TypeId::STRING}, |
|
61 {L"i", TypeId::INTEGER}, |
|
62 {L"b", TypeId::BOOLEAN} |
|
63 }, true); |
|
64 |
|
65 string_t sValue; |
|
66 integer_t iValue; |
|
67 boolean_t bValue; |
|
68 |
|
69 for (int i = 0; i < 8; i++) { |
|
70 sValue.append(L"*"); |
|
71 iValue = i + 1; |
|
72 bValue = iValue % 2 == 0; |
|
73 writer->writeAttribute(&sValue, typeid (sValue)); |
|
74 writer->writeAttribute(&iValue, typeid (iValue)); |
|
75 writer->writeAttribute(&bValue, typeid (bValue)); |
|
76 } |
|
77 } |
|
78 }; |
|
79 |
|
80 } |
|
81 } |
|
82 } |