author | František Kučera <franta-hg@frantovo.cz> |
Tue, 22 Oct 2019 19:48:51 +0200 | |
branch | v_0 |
changeset 37 | 27f0ffa712d9 |
parent 26 | aadef824dc93 |
permissions | -rw-r--r-- |
24
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
1 |
/** |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
2 |
* Relational pipes |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
3 |
* Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
4 |
* |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
37
27f0ffa712d9
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
24
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
8 |
* |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
12 |
* GNU General Public License for more details. |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
13 |
* |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
c31fdd965028
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
16 |
*/ |
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
17 |
#pragma once |
0 | 18 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
19 |
#include <cstdlib> |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
20 |
#include <iostream> |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
21 |
#include <string> |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
22 |
#include <vector> |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
23 |
#include <algorithm> |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
24 |
|
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
|
25 |
#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
|
26 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
27 |
#include "Command.h" |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
28 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
29 |
namespace relpipe { |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
30 |
namespace in { |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
31 |
namespace cli { |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
32 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
33 |
class DemoCommand : public Command { |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
34 |
public: |
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 |
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
|
37 |
using namespace relpipe::writer; |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
38 |
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
|
39 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
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 strings |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
42 |
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
|
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); |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
47 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
48 |
writer->writeAttribute(L"a"); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
49 |
writer->writeAttribute(L"1"); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
50 |
writer->writeAttribute(L"true"); |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
51 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
52 |
writer->writeAttribute(L"b"); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
53 |
writer->writeAttribute(L"2"); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
54 |
writer->writeAttribute(L"false"); |
0 | 55 |
|
7
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
56 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
57 |
// 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
|
58 |
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
|
59 |
{L"s", TypeId::STRING}, |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
60 |
{L"i", TypeId::INTEGER}, |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
61 |
{L"b", TypeId::BOOLEAN} |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
62 |
}, true); |
4
e615c7d87279
multiple relations, various data types
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
63 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
64 |
string_t sValue; |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
65 |
integer_t iValue; |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
66 |
boolean_t bValue; |
7
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
67 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
68 |
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
|
69 |
sValue.append(L"*"); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
70 |
iValue = i + 1; |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
71 |
bValue = iValue % 2 == 0; |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
72 |
writer->writeAttribute(&sValue, typeid (sValue)); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
73 |
writer->writeAttribute(&iValue, typeid (iValue)); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
74 |
writer->writeAttribute(&bValue, typeid (bValue)); |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
75 |
} |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
76 |
} |
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
77 |
}; |
8
c1472544d95a
replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
78 |
|
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
79 |
} |
0 | 80 |
} |
12
bc6fe00dd831
move demo code to DemoCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
81 |
} |