author | František Kučera <franta-hg@frantovo.cz> |
Mon, 13 Aug 2018 20:31:09 +0200 | |
branch | v_0 |
changeset 20 | a18b6964d300 |
parent 12 | bc6fe00dd831 |
child 24 | c31fdd965028 |
permissions | -rw-r--r-- |
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
1 |
#pragma once |
0 | 2 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
3 |
#include <cstdlib> |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
4 |
#include <iostream> |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
5 |
#include <string> |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
6 |
#include <vector> |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
7 |
#include <algorithm> |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
8 |
|
20
a18b6964d300
relpipe-lib-writer: move public header files to: include/relpipe/writer/
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
9 |
#include <relpipe/writer/typedefs.h> |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
10 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
11 |
#include "Command.h" |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
12 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
13 |
namespace relpipe { |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
14 |
namespace in { |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
15 |
namespace cli { |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
16 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
17 |
class DemoCommand : public Command { |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
18 |
public: |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
19 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
20 |
void process(std::istream& input, std::ostream& output, const relpipe::writer::string_t& command, const std::vector<relpipe::writer::string_t>& arguments) override { |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
21 |
using namespace relpipe::writer; |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
22 |
std::shared_ptr<RelationalWriter> writer(Factory::create(output)); |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
23 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
24 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
25 |
// Various data types passed as strings |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
26 |
writer->startRelation(L"table_from_strings",{ |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
27 |
{L"s", TypeId::STRING}, |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
28 |
{L"i", TypeId::INTEGER}, |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
29 |
{L"b", TypeId::BOOLEAN} |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
30 |
}, true); |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
31 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
32 |
writer->writeAttribute(L"a"); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
33 |
writer->writeAttribute(L"1"); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
34 |
writer->writeAttribute(L"true"); |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
35 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
36 |
writer->writeAttribute(L"b"); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
37 |
writer->writeAttribute(L"2"); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
38 |
writer->writeAttribute(L"false"); |
0 | 39 |
|
7
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
40 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
41 |
// Various data types passed as raw pointers + typeids |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
42 |
writer->startRelation(L"from_raw_pointers",{ |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
43 |
{L"s", TypeId::STRING}, |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
44 |
{L"i", TypeId::INTEGER}, |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
45 |
{L"b", TypeId::BOOLEAN} |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
46 |
}, true); |
4
e615c7d87279
multiple relations, various data types
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
47 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
48 |
string_t sValue; |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
49 |
integer_t iValue; |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
50 |
boolean_t bValue; |
7
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
51 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
52 |
for (int i = 0; i < 8; i++) { |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
53 |
sValue.append(L"*"); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
54 |
iValue = i + 1; |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
55 |
bValue = iValue % 2 == 0; |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
56 |
writer->writeAttribute(&sValue, typeid (sValue)); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
57 |
writer->writeAttribute(&iValue, typeid (iValue)); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
58 |
writer->writeAttribute(&bValue, typeid (bValue)); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
59 |
} |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
60 |
} |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
61 |
}; |
8
c1472544d95a
replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
62 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
63 |
} |
0 | 64 |
} |
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
65 |
} |