diff -r 31ef97e63eb0 -r 9a4062b12fc9 relpipe-out-tabular.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/relpipe-out-tabular.cpp Mon Sep 03 23:44:34 2018 +0200 @@ -0,0 +1,65 @@ +#include +#include + +#include +#include +#include +#include +#include + + +using namespace relpipe::cli; +using namespace relpipe::reader; + +class DemoHandler : public handlers::RelationalReaderStringHadler { + + void startRelation(string_t name, std::vector > attributes) override { + std::wcout << L"start relation: " << name << std::endl << std::flush; + for (int i = 0; i < attributes.size(); i++) { + std::wcout << L"\tcolumn: " << attributes[i].first << L" / " << (int) attributes[i].second << std::endl << std::flush; + } + } + + void attribute(const string_t& value) override { + std::wcout << L"attribute: " << value << std::endl << std::flush; + } + + +}; + +int main(int argc, char** argv) { + CLI cli(argc, argv); + + int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; + + try { + // if (cli.arguments().size() > 0) { + + // const wstring commandName = cli.arguments()[0]; + // vector arguments(cli.arguments().size() - 1); + // for (int i = 1; i < cli.arguments().size(); i++) { + // arguments[i - 1] = cli.arguments()[i]; + // } + + std::shared_ptr reader(Factory::create(std::cin)); + DemoHandler handler; + reader->addHandler(&handler); + reader->process(); + + resultCode = CLI::EXIT_CODE_SUCCESS; + + // } else { + // throw RelpipeCLIException(L"Missing command…", CLI::EXIT_CODE_BAD_SYNTAX); + // } + } catch (RelpipeCLIException e) { + fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str()); + fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); + resultCode = e.getExitCode(); + } catch (RelpipeReaderException e) { + fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str()); + fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); + resultCode = CLI::EXIT_CODE_DATA_ERROR; + } + + return resultCode; +}