# HG changeset patch # User František Kučera # Date 1532780204 -7200 # Node ID bc6fe00dd8313e518208932219435b326adbec40 # Parent 3798b6bc9aea7816a8c78e55c367c2b30f4daca7 move demo code to DemoCommand.h diff -r 3798b6bc9aea -r bc6fe00dd831 DemoCommand.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DemoCommand.h Sat Jul 28 14:16:44 2018 +0200 @@ -0,0 +1,65 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include + +#include "Command.h" + +namespace relpipe { +namespace in { +namespace cli { + +class DemoCommand : public Command { +public: + + void process(std::istream& input, std::ostream& output, const relpipe::writer::string_t& command, const std::vector& arguments) override { + using namespace relpipe::writer; + std::shared_ptr writer(Factory::create(output)); + + + // Various data types passed as strings + writer->startRelation(L"table_from_strings",{ + {L"s", TypeId::STRING}, + {L"i", TypeId::INTEGER}, + {L"b", TypeId::BOOLEAN} + }, true); + + writer->writeAttribute(L"a"); + writer->writeAttribute(L"1"); + writer->writeAttribute(L"true"); + + writer->writeAttribute(L"b"); + writer->writeAttribute(L"2"); + writer->writeAttribute(L"false"); + + + // Various data types passed as raw pointers + typeids + writer->startRelation(L"from_raw_pointers",{ + {L"s", TypeId::STRING}, + {L"i", TypeId::INTEGER}, + {L"b", TypeId::BOOLEAN} + }, true); + + string_t sValue; + integer_t iValue; + boolean_t bValue; + + for (int i = 0; i < 8; i++) { + sValue.append(L"*"); + iValue = i + 1; + bValue = iValue % 2 == 0; + writer->writeAttribute(&sValue, typeid (sValue)); + writer->writeAttribute(&iValue, typeid (iValue)); + writer->writeAttribute(&bValue, typeid (bValue)); + } + } +}; + +} +} +} diff -r 3798b6bc9aea -r bc6fe00dd831 nbproject/configurations.xml --- a/nbproject/configurations.xml Sat Jul 28 14:06:53 2018 +0200 +++ b/nbproject/configurations.xml Sat Jul 28 14:16:44 2018 +0200 @@ -7,6 +7,7 @@ ArgumentsCommand.h CLI.h Command.h + DemoCommand.h + + @@ -94,6 +97,8 @@ + + diff -r 3798b6bc9aea -r bc6fe00dd831 relpipe-in-cli.cpp --- a/relpipe-in-cli.cpp Sat Jul 28 14:06:53 2018 +0200 +++ b/relpipe-in-cli.cpp Sat Jul 28 14:16:44 2018 +0200 @@ -11,8 +11,7 @@ #include "CLI.h" #include "Command.h" #include "ArgumentsCommand.h" - -int demo(); +#include "DemoCommand.h" int main(int argc, char** argv) { using namespace relpipe::cli; @@ -34,10 +33,13 @@ } if (action == L"demo") { - resultCode = demo(); + DemoCommand command; + command.process(cin, cout, action, arguments); + resultCode = CLI::EXIT_CODE_SUCCESS; } else if (action == L"generate") { ArgumentsCommand command; command.process(cin, cout, action, arguments); + resultCode = CLI::EXIT_CODE_SUCCESS; } else { fwprintf(stderr, L"Unknown command: %ls\n", action.c_str()); resultCode = CLI::EXIT_CODE_UNKNOWN_COMMAND; @@ -54,51 +56,5 @@ resultCode = CLI::EXIT_CODE_DATA_ERROR; } - return resultCode; - } - -int demo() { - using namespace relpipe::writer; - std::shared_ptr writer(Factory::create(std::cout)); - - - // Various data types passed as strings - writer->startRelation(L"table_from_strings",{ - {L"s", TypeId::STRING}, - {L"i", TypeId::INTEGER}, - {L"b", TypeId::BOOLEAN} - }, true); - - writer->writeAttribute(L"a"); - writer->writeAttribute(L"1"); - writer->writeAttribute(L"true"); - - writer->writeAttribute(L"b"); - writer->writeAttribute(L"2"); - writer->writeAttribute(L"false"); - - - // Various data types passed as raw pointers + typeids - writer->startRelation(L"from_raw_pointers",{ - {L"s", TypeId::STRING}, - {L"i", TypeId::INTEGER}, - {L"b", TypeId::BOOLEAN} - }, true); - - string_t sValue; - integer_t iValue; - boolean_t bValue; - - for (int i = 0; i < 8; i++) { - sValue.append(L"*"); - iValue = i + 1; - bValue = iValue % 2 == 0; - writer->writeAttribute(&sValue, typeid (sValue)); - writer->writeAttribute(&iValue, typeid (iValue)); - writer->writeAttribute(&bValue, typeid (bValue)); - } - - return 0; -}