src/relpipe-in-yaml.cpp
author František Kučera <franta-hg@frantovo.cz>
Thu, 03 Dec 2020 17:16:09 +0100
branchv_0
changeset 1 8d2d8f4077af
parent 0 66a454290286
child 10 15a151aa93b1
permissions -rw-r--r--
OOP wrapper for yaml.h + list event types
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
1
8d2d8f4077af OOP wrapper for yaml.h + list event types
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
     3
 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
0
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
66a454290286 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
66a454290286 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
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#include <cstdlib>
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <fstream>
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <relpipe/writer/RelationalWriter.h>
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/writer/RelpipeWriterException.h>
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/writer/Factory.h>
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/writer/TypeId.h>
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/cli/CLI.h>
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
#include "YAMLCommand.h"
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
using namespace relpipe::cli;
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
using namespace relpipe::writer;
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
using namespace relpipe::in::yaml;
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
int main(int argc, char** argv) {
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	setlocale(LC_ALL, "");
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	CLI::untieStdIO();
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	CLI cli(argc, argv);
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	try {
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
		YAMLCommand command;
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout));
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		command.process(cin, writer);
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		resultCode = CLI::EXIT_CODE_SUCCESS;
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	} catch (RelpipeWriterException& e) {
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str());
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	}
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	return resultCode;
66a454290286 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
}