author | František Kučera <franta-hg@frantovo.cz> |
Mon, 03 Sep 2018 23:44:34 +0200 | |
branch | v_0 |
changeset 3 | 9a4062b12fc9 |
child 5 | 911ec74cce33 |
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 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
using namespace relpipe::cli; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
using namespace relpipe::reader; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
class DemoHandler : public handlers::RelationalReaderStringHadler { |
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 |
void startRelation(string_t name, std::vector<std::pair<string_t, TypeId> > attributes) override { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
std::wcout << L"start relation: " << name << std::endl << std::flush; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
for (int i = 0; i < attributes.size(); i++) { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
std::wcout << L"\tcolumn: " << attributes[i].first << L" / " << (int) attributes[i].second << std::endl << std::flush; |
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 |
} |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
void attribute(const string_t& value) override { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
std::wcout << L"attribute: " << value << std::endl << std::flush; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
} |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
|
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
|
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 |
int main(int argc, char** argv) { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
CLI cli(argc, argv); |
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 resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
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 |
try { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
// if (cli.arguments().size() > 0) { |
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 |
// const wstring commandName = cli.arguments()[0]; |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
// 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
|
40 |
// 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
|
41 |
// arguments[i - 1] = cli.arguments()[i]; |
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 |
|
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)); |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
DemoHandler handler; |
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) { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
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
|
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) { |
9a4062b12fc9
DemoHandler (not an actual tabular handler)
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
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
|
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 |
} |