src/GuileHandler.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 20 Jan 2019 01:02:40 +0100
branchv_0
changeset 1 9179406ab3b3
parent 0 f36bf14d45cb
child 2 7fb4d2c70e8c
permissions -rw-r--r--
link to the Guile library and add some Guile demo code – evaluate code from CLI argument try: relpipe-in-fstab | relpipe-tr-guile 'fstab' '(or (= a b) (= a a) )' | relpipe-out-tabular relpipe-in-fstab | relpipe-tr-guile 'fstab' '(or (= a b) (= a 9) )' | relpipe-out-tabular
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * (at your option) any later version.
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 */
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#pragma once
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <memory>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <string>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <vector>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <iostream>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <sstream>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <locale>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <codecvt>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <regex>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
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
    29
#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
    30
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
#include <relpipe/reader/typedefs.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
#include <relpipe/reader/TypeId.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
#include <relpipe/reader/handlers/RelationalReaderStringHandler.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
#include <relpipe/reader/handlers/AttributeMetadata.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
#include <relpipe/writer/Factory.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
#include <relpipe/cli/RelpipeCLIException.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
namespace relpipe {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
namespace tr {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
namespace guile {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
using namespace std;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
using namespace relpipe;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
using namespace relpipe::reader;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
using namespace relpipe::reader::handlers;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
class GuileHandler : public RelationalReaderStringHadler {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
private:
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
    51
	std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
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
    52
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	shared_ptr<writer::RelationalWriter> relationalWriter;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	wregex relationNameRegEx;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
	vector<AttributeMetadata> currentMetadata;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	vector<string_t> currentRecord;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
	integer_t currentAttributeIndex = 0;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	boolean_t includeCurrentRecord = false;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	boolean_t filterCurrentRelation = 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
    62
	string_t guileCode;
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
    63
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
    64
	SCM toGuileSymbol(const string_t& name) {
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
		return scm_string_to_symbol(scm_from_locale_string(convertor.to_bytes(name).c_str()));
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
    66
	}
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
    67
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
    68
	SCM toGuileString(const string_t& value) {
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
    69
		return scm_from_locale_string(convertor.to_bytes(value).c_str());
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
    70
	}
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
    71
	
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
    72
	SCM toGuileInteger(const string_t& value) {
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
		return scm_from_uint64(stoul(value));
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
	}
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
    75
	
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
    76
	SCM toGuileBoolean(const string_t& value) {
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
		return value == L"true" ? SCM_BOOL_T : SCM_BOOL_F;
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
    78
	}
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
    79
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
    80
	void defineGuileVariable(const string_t& name, TypeId type, const string_t& value) {
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
		// TODO: RelationalReaderValueHadler?
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
    82
		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
    83
			case TypeId::BOOLEAN:
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
				scm_define(toGuileSymbol(name), toGuileBoolean(value));
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
				break;
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
    86
			case TypeId::INTEGER:
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
    87
				scm_define(toGuileSymbol(name), toGuileInteger(value));
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
    88
				break;
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
    89
			case TypeId::STRING:
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
    90
				scm_define(toGuileSymbol(name), toGuileString(value));
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
				break;
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
    92
			default:
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
    93
				throw cli::RelpipeCLIException(L"Unsupported type in defineGuileVariable()", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR);
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
    94
		}
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
    95
	}
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
    96
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
	void undefineGuileVariable(const string_t& name, TypeId type, const string_t& value) {
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
    98
		scm_define(toGuileSymbol(name), scm_make_undefined_variable()); // undefined != (define n)
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
    99
	}
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   100
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
public:
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   102
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   103
	GuileHandler(ostream& output, const vector<string_t>& arguments) {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   104
		relationalWriter.reset(writer::Factory::create(output));
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   105
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   106
		// TODO: options and parser
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
   107
		if (arguments.size() == 2) {
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   108
			relationNameRegEx = wregex(arguments[0]);
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
   109
			guileCode = arguments[1];
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   110
		} else {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   111
			throw cli::RelpipeCLIException(L"Usage: relpipe-tr-guile <relationNameRegExp>", cli::CLI::EXIT_CODE_UNKNOWN_COMMAND);
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   112
		}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   113
	}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   114
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   115
	void startRelation(string_t name, vector<AttributeMetadata> attributes) override {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   116
		currentMetadata = attributes;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   117
		// TODO: move to a reusable method (or use same metadata on both reader and writer side?)
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   118
		vector<writer::AttributeMetadata> writerMetadata;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   119
		for (AttributeMetadata readerMetadata : attributes) {
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
   120
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   121
			writerMetadata.push_back({readerMetadata.getAttributeName(), relationalWriter->toTypeId(readerMetadata.getTypeName())});
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   122
		}
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
   123
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   124
		currentRecord.resize(attributes.size());
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   125
		filterCurrentRelation = regex_match(name, relationNameRegEx);
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   126
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   127
		relationalWriter->startRelation(name, writerMetadata, true);
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   128
	}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   129
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   130
	void attribute(const string_t& value) override {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   131
		if (filterCurrentRelation) {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   132
			// TODO: evaluate condition and updates in Guile
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   133
			currentRecord[currentAttributeIndex] = value;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   134
			includeCurrentRecord = false;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   135
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
   136
			// TODO: remove, just a demo code
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
   137
			defineGuileVariable(L"hello", TypeId::STRING, L"world");
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
   138
			defineGuileVariable(L"a", TypeId::INTEGER, L"123");
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
   139
			defineGuileVariable(L"b", TypeId::INTEGER, L"456");
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
   140
			defineGuileVariable(L"tr", TypeId::BOOLEAN, L"true");
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
   141
			defineGuileVariable(L"fa", TypeId::BOOLEAN, L"false");
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
   142
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
   143
			//integer_t guileResult = scm_to_uint64(scm_eval_string(toGuileString(guileCode)));
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
   144
			//std::wcerr << "result from Guile: " << guileResult << std::endl;
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
   145
			
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
   146
			includeCurrentRecord = scm_to_bool(scm_eval_string(toGuileString(guileCode)));
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
   147
			//scm_shell(0, nullptr);
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
   148
			// --------
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
   149
			
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
   150
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   151
			currentAttributeIndex++;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   152
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   153
			if (currentAttributeIndex > 0 && currentAttributeIndex % currentMetadata.size() == 0) {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   154
				if (includeCurrentRecord) for (string_t v : currentRecord) relationalWriter->writeAttribute(v);
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   155
				includeCurrentRecord = false;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   156
			}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   157
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   158
			currentAttributeIndex = currentAttributeIndex % currentMetadata.size();
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   159
		} else {
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
   160
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   161
			relationalWriter->writeAttribute(value);
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   162
		}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   163
	}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   164
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   165
	void endOfPipe() {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   166
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   167
	}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   168
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   169
};
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   170
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   171
}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   172
}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   173
}