author | František Kučera <franta-hg@frantovo.cz> |
Sun, 03 Feb 2019 19:02:50 +0100 | |
branch | v_0 |
changeset 8 | 1e6206284c6c |
parent 7 | 61fc569b77e6 |
child 9 | 65f9d6b94f5c |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2019 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 <memory> |
|
21 |
#include <string> |
|
22 |
#include <vector> |
|
23 |
#include <iostream> |
|
24 |
#include <sstream> |
|
25 |
#include <locale> |
|
26 |
#include <codecvt> |
|
27 |
#include <regex> |
|
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
28 |
#include <assert.h> |
0 | 29 |
|
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
30 |
#include <libguile.h> |
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
31 |
|
0 | 32 |
#include <relpipe/reader/typedefs.h> |
33 |
#include <relpipe/reader/TypeId.h> |
|
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
34 |
#include <relpipe/reader/handlers/RelationalReaderValueHandler.h> |
0 | 35 |
#include <relpipe/reader/handlers/AttributeMetadata.h> |
36 |
||
37 |
#include <relpipe/writer/Factory.h> |
|
38 |
||
39 |
#include <relpipe/cli/RelpipeCLIException.h> |
|
40 |
||
6
4062b8436838
CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
41 |
#include "Configuration.h" |
4062b8436838
CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
42 |
|
0 | 43 |
namespace relpipe { |
44 |
namespace tr { |
|
45 |
namespace guile { |
|
46 |
||
47 |
using namespace std; |
|
48 |
using namespace relpipe; |
|
49 |
using namespace relpipe::reader; |
|
50 |
using namespace relpipe::reader::handlers; |
|
51 |
||
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
52 |
class GuileHandler : public RelationalReaderValueHadler { |
0 | 53 |
private: |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
54 |
std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings or use always UTF-8 between C++ and Guile |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
55 |
|
6
4062b8436838
CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
56 |
Configuration configuration; |
7
61fc569b77e6
RelationalWriter dependency injection
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
57 |
writer::RelationalWriter* relationalWriter; |
0 | 58 |
|
8
1e6206284c6c
Guile can now process multiple relations in the stream
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
59 |
RelationConfiguration* currentRelationConfiguration = nullptr; |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
60 |
vector<AttributeMetadata> currentReaderMetadata; |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
61 |
vector<writer::AttributeMetadata> currentWriterMetadata; |
0 | 62 |
vector<string_t> currentRecord; |
63 |
integer_t currentAttributeIndex = 0; |
|
64 |
boolean_t includeCurrentRecord = false; |
|
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
65 |
|
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
66 |
/** |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
67 |
* @param attributeName name from relational pipe |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
68 |
* @return variable name in Guile |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
69 |
*/ |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
70 |
string_t a2v(const string_t& attributeName) { |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
71 |
// TODO: escape spaces and special characters |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
72 |
return L"$" + attributeName; |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
73 |
} |
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
74 |
|
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
75 |
SCM toGuileSymbol(const string_t& name) { |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
76 |
return scm_string_to_symbol(scm_from_locale_string(convertor.to_bytes(name).c_str())); |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
77 |
} |
2
7fb4d2c70e8c
record filtering in Guile
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
78 |
|
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
79 |
SCM evalGuileCode(const string_t& value) { |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
80 |
return scm_eval_string(toGuileValue(&value, typeid (string_t), TypeId::STRING)); |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
81 |
} |
2
7fb4d2c70e8c
record filtering in Guile
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
82 |
|
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
83 |
SCM toGuileValue(const void* value, const std::type_info& typeInfo, TypeId type) { |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
84 |
switch (type) { |
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
85 |
case TypeId::BOOLEAN: |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
86 |
{ |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
87 |
assert(typeInfo == typeid (boolean_t)); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
88 |
auto* typedValue = static_cast<const boolean_t*> (value); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
89 |
return *typedValue ? SCM_BOOL_T : SCM_BOOL_F; |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
90 |
} |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
91 |
case TypeId::INTEGER: |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
92 |
{ |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
93 |
assert(typeInfo == typeid (integer_t)); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
94 |
auto* typedValue = static_cast<const integer_t*> (value); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
95 |
return scm_from_uint64(*typedValue); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
96 |
} |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
97 |
case TypeId::STRING: |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
98 |
{ |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
99 |
assert(typeInfo == typeid (string_t)); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
100 |
auto* typedValue = static_cast<const string_t*> (value); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
101 |
return scm_from_locale_string(convertor.to_bytes(*typedValue).c_str()); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
102 |
} |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
103 |
default: |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
104 |
throw cli::RelpipeCLIException(L"Unsupported type in toGuileValue()", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
105 |
} |
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
106 |
} |
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
107 |
|
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
108 |
void defineGuileVariable(const string_t& name, const void* value, const std::type_info& typeInfo, TypeId type) { |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
109 |
scm_define(toGuileSymbol(name), toGuileValue(value, typeInfo, type)); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
110 |
} |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
111 |
|
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
112 |
void undefineGuileVariable(const string_t& name) { |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
113 |
scm_define(toGuileSymbol(name), scm_make_undefined_variable()); // undefined != (define n) |
3
d4d0e50f54da
add $ prefix to attribute variables
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
114 |
// TODO: or use: scm_variable_unset_x() ? |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
115 |
} |
0 | 116 |
|
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
117 |
void writeGuileValueToAttribute(const writer::AttributeMetadata& attribute) { |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
118 |
string_t variableName = a2v(attribute.attributeName); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
119 |
SCM guileValue = scm_eval_string(toGuileValue(&variableName, typeid (variableName), TypeId::STRING)); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
120 |
|
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
121 |
switch (attribute.typeId) { |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
122 |
case writer::TypeId::BOOLEAN: |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
123 |
{ |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
124 |
boolean_t value = scm_to_bool(guileValue); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
125 |
return relationalWriter->writeAttribute(&value, typeid (value)); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
126 |
} |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
127 |
case writer::TypeId::INTEGER: |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
128 |
{ |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
129 |
integer_t value = scm_to_uint64(guileValue); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
130 |
return relationalWriter->writeAttribute(&value, typeid (value)); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
131 |
} |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
132 |
case writer::TypeId::STRING: |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
133 |
{ |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
134 |
char* ch = scm_to_locale_string(guileValue); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
135 |
string_t value = convertor.from_bytes(ch); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
136 |
free(ch); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
137 |
return relationalWriter->writeAttribute(&value, typeid (value)); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
138 |
} |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
139 |
default: |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
140 |
throw cli::RelpipeCLIException(L"Unsupported type in writeGuileValueToAttribute()", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
141 |
} |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
142 |
} |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
143 |
|
0 | 144 |
public: |
145 |
||
7
61fc569b77e6
RelationalWriter dependency injection
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
146 |
GuileHandler(writer::RelationalWriter* relationalWriter, Configuration& configuration, const vector<string_t>& arguments) : relationalWriter(relationalWriter), configuration(configuration) { |
0 | 147 |
} |
148 |
||
149 |
void startRelation(string_t name, vector<AttributeMetadata> attributes) override { |
|
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
150 |
for (auto attribute : currentReaderMetadata) undefineGuileVariable(attribute.getAttributeName()); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
151 |
currentReaderMetadata = attributes; |
0 | 152 |
// TODO: move to a reusable method (or use same metadata on both reader and writer side?) |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
153 |
// TODO: allow structural changes during transformation |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
154 |
currentWriterMetadata.clear(); |
0 | 155 |
for (AttributeMetadata readerMetadata : attributes) { |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
156 |
currentWriterMetadata.push_back({readerMetadata.getAttributeName(), relationalWriter->toTypeId(readerMetadata.getTypeName())}); |
0 | 157 |
} |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
158 |
|
0 | 159 |
currentRecord.resize(attributes.size()); |
8
1e6206284c6c
Guile can now process multiple relations in the stream
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
160 |
|
1e6206284c6c
Guile can now process multiple relations in the stream
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
161 |
for (int i = 0; i < configuration.relationConfigurations.size(); i++) { |
1e6206284c6c
Guile can now process multiple relations in the stream
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
162 |
if (regex_match(name, wregex(configuration.relationConfigurations[i].relation))) { |
1e6206284c6c
Guile can now process multiple relations in the stream
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
163 |
currentRelationConfiguration = &configuration.relationConfigurations[i]; |
1e6206284c6c
Guile can now process multiple relations in the stream
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
164 |
break; // it there are multiple matches, only the first configuration is used |
1e6206284c6c
Guile can now process multiple relations in the stream
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
165 |
} |
1e6206284c6c
Guile can now process multiple relations in the stream
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
166 |
} |
0 | 167 |
|
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
168 |
relationalWriter->startRelation(name, currentWriterMetadata, true); |
0 | 169 |
} |
170 |
||
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
171 |
void attribute(const void* value, const std::type_info& type) override { |
8
1e6206284c6c
Guile can now process multiple relations in the stream
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
172 |
if (currentRelationConfiguration) { |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
173 |
defineGuileVariable(a2v(currentReaderMetadata[currentAttributeIndex].getAttributeName()), value, type, currentReaderMetadata[currentAttributeIndex].getTypeId()); |
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
174 |
|
0 | 175 |
currentAttributeIndex++; |
176 |
||
7
61fc569b77e6
RelationalWriter dependency injection
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
177 |
// TODO: > 0 ?: |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
178 |
if (currentAttributeIndex > 0 && currentAttributeIndex % currentReaderMetadata.size() == 0) { |
8
1e6206284c6c
Guile can now process multiple relations in the stream
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
179 |
includeCurrentRecord = scm_to_bool(evalGuileCode(currentRelationConfiguration->guileWhere)); |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
180 |
if (includeCurrentRecord) for (auto attribute : currentWriterMetadata) writeGuileValueToAttribute(attribute); |
0 | 181 |
includeCurrentRecord = false; |
182 |
} |
|
183 |
||
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
184 |
currentAttributeIndex = currentAttributeIndex % currentReaderMetadata.size(); |
0 | 185 |
} else { |
5
17bb45570099
ValueHandler instead of StringHandler interface; Guile now allows filtering and record modifications
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
186 |
relationalWriter->writeAttribute(value, type); |
0 | 187 |
} |
188 |
} |
|
189 |
||
190 |
void endOfPipe() { |
|
191 |
||
192 |
} |
|
193 |
||
194 |
}; |
|
195 |
||
196 |
} |
|
197 |
} |
|
198 |
} |