author | František Kučera <franta-hg@frantovo.cz> |
Thu, 20 Dec 2018 00:26:00 +0100 | |
branch | v_0 |
changeset 16 | 655770e4d416 |
parent 11 | 663e3c9fe7ef |
child 24 | 992dde455b04 |
permissions | -rw-r--r-- |
9 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
|
8 |
* (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
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 | 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 |
} |