author | František Kučera <franta-hg@frantovo.cz> |
Sun, 22 Jul 2018 17:19:33 +0200 | |
branch | v_0 |
changeset 7 | 9ac885dd8037 |
parent 6 | 4585c212a767 |
child 8 | c1472544d95a |
permissions | -rw-r--r-- |
0 | 1 |
#include <cstdlib> |
1
7e43750deca8
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
2 |
#include <memory> |
0 | 3 |
|
7
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
4 |
#include <tuple> |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
5 |
|
1
7e43750deca8
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
6 |
#include <RelationalWriter.h> |
6
4585c212a767
move create() method to a factory
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
7 |
#include <Factory.h> |
5
83dd71fe5cfd
use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
8 |
#include <TypeId.h> |
0 | 9 |
|
10 |
int main(int argc, char** argv) { |
|
5
83dd71fe5cfd
use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
11 |
using namespace relpipe::writer; |
6
4585c212a767
move create() method to a factory
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
12 |
std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout)); |
0 | 13 |
|
7
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
14 |
|
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
15 |
// All strings |
3
7d4525147bf7
multiple records, no nullptr
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
16 |
writer->startRelation(L"my_first_table",{ |
5
83dd71fe5cfd
use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
17 |
{L"a1", TypeId::STRING}, |
83dd71fe5cfd
use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
18 |
{L"a2", TypeId::STRING}, |
83dd71fe5cfd
use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
19 |
{L"a3", TypeId::STRING} |
3
7d4525147bf7
multiple records, no nullptr
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
20 |
}, true); |
7d4525147bf7
multiple records, no nullptr
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
21 |
|
7d4525147bf7
multiple records, no nullptr
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
22 |
writer->writeRecord({L"1.1", L"1.2", L"1.3"}); |
7d4525147bf7
multiple records, no nullptr
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
23 |
writer->writeRecord({L"2.1", L"2.2", L"2.3"}); |
7d4525147bf7
multiple records, no nullptr
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
24 |
writer->writeRecord({L"3.1", L"3.2", L"3.3"}); |
7
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
25 |
|
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
26 |
|
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
27 |
// Various data types passed as strings |
4
e615c7d87279
multiple relations, various data types
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
28 |
writer->startRelation(L"my_second_table",{ |
5
83dd71fe5cfd
use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
29 |
{L"s", TypeId::STRING}, |
83dd71fe5cfd
use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
30 |
{L"i", TypeId::INTEGER}, |
83dd71fe5cfd
use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
31 |
{L"b", TypeId::BOOLEAN} |
4
e615c7d87279
multiple relations, various data types
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
32 |
}, true); |
e615c7d87279
multiple relations, various data types
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
33 |
|
e615c7d87279
multiple relations, various data types
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
34 |
writer->writeRecord({L"a", L"1", L"true"}); |
e615c7d87279
multiple relations, various data types
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
35 |
writer->writeRecord({L"b", L"2", L"false"}); |
e615c7d87279
multiple relations, various data types
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
36 |
writer->writeRecord({L"c", L"3", L"true"}); |
3
7d4525147bf7
multiple records, no nullptr
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
37 |
|
7
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
38 |
|
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
39 |
// Various data types passed as raw pointers + typeids |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
40 |
writer->startRelation(L"my_raw_table",{ |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
41 |
{L"s", TypeId::STRING}, |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
42 |
{L"i", TypeId::INTEGER}, |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
43 |
{L"b", TypeId::BOOLEAN} |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
44 |
}, true); |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
45 |
|
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
46 |
for (int i = 0; i < 3; i++) { |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
47 |
string_t sValue = L"s"; |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
48 |
integer_t iValue = i; |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
49 |
boolean_t bValue = i % 2 == 0; |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
50 |
|
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
51 |
writer->writeAttribute(&sValue, typeid(sValue)); |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
52 |
writer->writeAttribute(&iValue, typeid(iValue)); |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
53 |
writer->writeAttribute(&bValue, typeid(bValue)); |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
54 |
} |
9ac885dd8037
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
55 |
|
3
7d4525147bf7
multiple records, no nullptr
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
56 |
return 0; |
0 | 57 |
} |