|
1 #pragma once |
|
2 |
|
3 #include <cstdlib> |
|
4 #include <iostream> |
|
5 #include <string> |
|
6 #include <vector> |
|
7 #include <algorithm> |
|
8 |
|
9 #include <typedefs.h> |
|
10 |
|
11 #include "Command.h" |
|
12 |
|
13 namespace relpipe { |
|
14 namespace in { |
|
15 namespace cli { |
|
16 |
|
17 class DemoCommand : public Command { |
|
18 public: |
|
19 |
|
20 void process(std::istream& input, std::ostream& output, const relpipe::writer::string_t& command, const std::vector<relpipe::writer::string_t>& arguments) override { |
|
21 using namespace relpipe::writer; |
|
22 std::shared_ptr<RelationalWriter> writer(Factory::create(output)); |
|
23 |
|
24 |
|
25 // Various data types passed as strings |
|
26 writer->startRelation(L"table_from_strings",{ |
|
27 {L"s", TypeId::STRING}, |
|
28 {L"i", TypeId::INTEGER}, |
|
29 {L"b", TypeId::BOOLEAN} |
|
30 }, true); |
|
31 |
|
32 writer->writeAttribute(L"a"); |
|
33 writer->writeAttribute(L"1"); |
|
34 writer->writeAttribute(L"true"); |
|
35 |
|
36 writer->writeAttribute(L"b"); |
|
37 writer->writeAttribute(L"2"); |
|
38 writer->writeAttribute(L"false"); |
|
39 |
|
40 |
|
41 // Various data types passed as raw pointers + typeids |
|
42 writer->startRelation(L"from_raw_pointers",{ |
|
43 {L"s", TypeId::STRING}, |
|
44 {L"i", TypeId::INTEGER}, |
|
45 {L"b", TypeId::BOOLEAN} |
|
46 }, true); |
|
47 |
|
48 string_t sValue; |
|
49 integer_t iValue; |
|
50 boolean_t bValue; |
|
51 |
|
52 for (int i = 0; i < 8; i++) { |
|
53 sValue.append(L"*"); |
|
54 iValue = i + 1; |
|
55 bValue = iValue % 2 == 0; |
|
56 writer->writeAttribute(&sValue, typeid (sValue)); |
|
57 writer->writeAttribute(&iValue, typeid (iValue)); |
|
58 writer->writeAttribute(&bValue, typeid (bValue)); |
|
59 } |
|
60 } |
|
61 }; |
|
62 |
|
63 } |
|
64 } |
|
65 } |