src/relpipe-out-tabular.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 22 Oct 2019 21:59:41 +0200
branchv_0
changeset 24 992dde455b04
parent 11 663e3c9fe7ef
child 30 3c6374467a82
permissions -rw-r--r--
fix license version: GNU GPLv3
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
24
992dde455b04 fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
9
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     8
 *
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
     9
 * 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
    10
 * 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
    11
 * 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
    12
 * GNU General Public License for more details.
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    13
 *
86d69cfbacc9 license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    14
 * 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
    15
 * 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
    16
 */
3
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#include <cstdlib>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <memory>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <relpipe/cli/CLI.h>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <relpipe/cli/RelpipeCLIException.h>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/reader/Factory.h>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/reader/RelationalReader.h>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/reader/RelpipeReaderException.h>
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
11
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    26
#include "TabularPrefetchingHandler.h"
3
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
using namespace relpipe::cli;
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
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
    30
using namespace relpipe::out::tabular;
3
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
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
    33
	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
    34
	CLI::untieStdIO();
3
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	CLI cli(argc, argv);
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	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
    38
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	try {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		// if (cli.arguments().size() > 0) {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
		// const wstring commandName = cli.arguments()[0];
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		// 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
    44
		// 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
    45
		//	arguments[i - 1] = cli.arguments()[i];
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		// }
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
		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
    49
		TabularPrefetchingHandler handler(std::cout);
3
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		reader->addHandler(&handler);
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		reader->process();
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
		resultCode = CLI::EXIT_CODE_SUCCESS;
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		// } else {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		//	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
    57
		// }
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	} catch (RelpipeCLIException e) {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
		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
    60
		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
    61
		resultCode = e.getExitCode();
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	} catch (RelpipeReaderException e) {
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
		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
    64
		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
    65
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
	}
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
	return resultCode;
9a4062b12fc9 DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
}