author | František Kučera <franta-hg@frantovo.cz> |
Sun, 09 Sep 2018 21:01:33 +0200 | |
branch | v_0 |
changeset 6 | fc1e746e26a5 |
parent 5 | 911ec74cce33 |
child 9 | 86d69cfbacc9 |
permissions | -rw-r--r-- |
3
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
#include <cstdlib> |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
#include <memory> |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
#include <relpipe/cli/CLI.h> |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
#include <relpipe/cli/RelpipeCLIException.h> |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
#include <relpipe/reader/Factory.h> |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
#include <relpipe/reader/RelationalReader.h> |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
#include <relpipe/reader/RelpipeReaderException.h> |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
|
5
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
10 |
#include "src/TabularPrefetchingHandler.h" |
3
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
using namespace relpipe::cli; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
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
|
14 |
using namespace relpipe::out::tabular; |
3
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
int main(int argc, char** argv) { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
CLI cli(argc, argv); |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
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
|
20 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
try { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
// if (cli.arguments().size() > 0) { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
// const wstring commandName = cli.arguments()[0]; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
// 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
|
26 |
// 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
|
27 |
// arguments[i - 1] = cli.arguments()[i]; |
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 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
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
|
31 |
TabularPrefetchingHandler handler(std::cout); |
3
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
reader->addHandler(&handler); |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
reader->process(); |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
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 |
// } else { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
// 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
|
39 |
// } |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
} catch (RelpipeCLIException e) { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
resultCode = e.getExitCode(); |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
} catch (RelpipeReaderException e) { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
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 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
return resultCode; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
} |