author | František Kučera <franta-hg@frantovo.cz> |
Fri, 01 Jul 2022 23:38:15 +0200 | |
branch | v_0 |
changeset 40 | 59f3cb26bfe7 |
parent 34 | 508b51f094b8 |
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 |
|
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 | 8 |
* |
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
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 | 26 |
#include "TabularPrefetchingHandler.h" |
30
3c6374467a82
change CLI interface: options: --relation --print-types --print-relation-name --print-record-count
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
27 |
#include "Configuration.h" |
3c6374467a82
change CLI interface: options: --relation --print-types --print-relation-name --print-record-count
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
28 |
#include "CLIParser.h" |
3
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
using namespace relpipe::cli; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
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
|
32 |
using namespace relpipe::out::tabular; |
3
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
CLI::untieStdIO(); |
3
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
CLI cli(argc, argv); |
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 |
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
|
40 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
try { |
30
3c6374467a82
change CLI interface: options: --relation --print-types --print-relation-name --print-record-count
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
42 |
CLIParser cliParser; |
3c6374467a82
change CLI interface: options: --relation --print-types --print-relation-name --print-record-count
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
43 |
Configuration configuration = cliParser.parse(cli.arguments()); |
3
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
std::shared_ptr<RelationalReader> reader(Factory::create(std::cin)); |
30
3c6374467a82
change CLI interface: options: --relation --print-types --print-relation-name --print-record-count
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
45 |
TabularPrefetchingHandler handler(std::cout, configuration); |
3
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
reader->addHandler(&handler); |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
reader->process(); |
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 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
// } else { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
// 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
|
53 |
// } |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
} catch (RelpipeCLIException e) { |
34
508b51f094b8
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
55 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
3
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
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
|
57 |
resultCode = e.getExitCode(); |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
} catch (RelpipeReaderException e) { |
34
508b51f094b8
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
30
diff
changeset
|
59 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str()); |
3
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 = CLI::EXIT_CODE_DATA_ERROR; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
} |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
return resultCode; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
} |