src/relpipe-out-xml.cpp
author František Kučera <franta-hg@frantovo.cz>
Sun, 16 Sep 2018 14:39:10 +0200
branchv_0
changeset 1 82ba555a97d1
child 2 13a41e435ea0
permissions -rw-r--r--
relpipe-out-xml skeleton
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#include <cstdlib>
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
#include <memory>
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
#include <relpipe/cli/CLI.h>
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
#include <relpipe/cli/RelpipeCLIException.h>
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
#include <relpipe/reader/Factory.h>
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#include <relpipe/reader/RelationalReader.h>
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
#include <relpipe/reader/RelpipeReaderException.h>
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
#include "XmlHandler.h"
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
using namespace relpipe::cli;
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
using namespace relpipe::reader;
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
using namespace relpipe::out::tabular;
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
int main(int argc, char** argv) {
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
	CLI cli(argc, argv);
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	try {
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
		XmlHandler handler(std::cout);
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
		reader->addHandler(&handler);
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
		reader->process();
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		resultCode = CLI::EXIT_CODE_SUCCESS;
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
	} catch (RelpipeCLIException e) {
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
		resultCode = e.getExitCode();
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	} catch (RelpipeReaderException e) {
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str());
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	}
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	return resultCode;
82ba555a97d1 relpipe-out-xml skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
}