src/relpipe-out-tabular.cpp
author František Kučera <franta-hg@frantovo.cz>
Wed, 20 Feb 2019 11:30:50 +0100
branchv_0
changeset 19 8d9d94a5332b
parent 11 663e3c9fe7ef
child 24 992dde455b04
permissions -rw-r--r--
Added tag v0.10 for changeset bbd89ca03878
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     1
/**
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     2
 * Relational pipes
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     3
 * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info)
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     4
 *
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     8
 * (at your option) any later version.
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     9
 *
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    13
 * GNU General Public License for more details.
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    14
 *
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    15
 * You should have received a copy of the GNU General Public License
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    17
 */
3
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <cstdlib>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <relpipe/cli/CLI.h>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/cli/RelpipeCLIException.h>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/reader/Factory.h>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/reader/RelationalReader.h>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <relpipe/reader/RelpipeReaderException.h>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
11
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    27
#include "TabularPrefetchingHandler.h"
3
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
using namespace relpipe::cli;
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
using namespace relpipe::reader;
5
911ec74cce33 tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    31
using namespace relpipe::out::tabular;
3
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
int main(int argc, char** argv) {
10
6af5371af82d CLI: untieStdIO() to avoid unwanted implicit flush() calls on std::cout → less write() calls
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    34
	setlocale(LC_ALL, "");
6af5371af82d CLI: untieStdIO() to avoid unwanted implicit flush() calls on std::cout → less write() calls
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    35
	CLI::untieStdIO();
3
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	CLI cli(argc, argv);
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	try {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		// if (cli.arguments().size() > 0) {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		// const wstring commandName = cli.arguments()[0];
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		// vector<wstring> arguments(cli.arguments().size() - 1);
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		// for (int i = 1; i < cli.arguments().size(); i++) {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		//	arguments[i - 1] = cli.arguments()[i];
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		// }
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
5
911ec74cce33 tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    50
		TabularPrefetchingHandler handler(std::cout);
3
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		reader->addHandler(&handler);
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		reader->process();
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		resultCode = CLI::EXIT_CODE_SUCCESS;
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		// } else {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
		//	throw RelpipeCLIException(L"Missing command…", CLI::EXIT_CODE_BAD_SYNTAX);
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
		// }
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
	} catch (RelpipeCLIException e) {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
		resultCode = e.getExitCode();
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
	} catch (RelpipeReaderException e) {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str());
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
	}
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
	return resultCode;
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
}