relpipe-in-cli.cpp
branchv_0
changeset 12 bc6fe00dd831
parent 11 3798b6bc9aea
child 13 5e95f0c0a4f9
equal deleted inserted replaced
11:3798b6bc9aea 12:bc6fe00dd831
     9 #include <TypeId.h>
     9 #include <TypeId.h>
    10 
    10 
    11 #include "CLI.h"
    11 #include "CLI.h"
    12 #include "Command.h"
    12 #include "Command.h"
    13 #include "ArgumentsCommand.h"
    13 #include "ArgumentsCommand.h"
    14 
    14 #include "DemoCommand.h"
    15 int demo();
       
    16 
    15 
    17 int main(int argc, char** argv) {
    16 int main(int argc, char** argv) {
    18 	using namespace relpipe::cli;
    17 	using namespace relpipe::cli;
    19 	using namespace relpipe::in::cli;
    18 	using namespace relpipe::in::cli;
    20 	using namespace relpipe::writer;
    19 	using namespace relpipe::writer;
    32 			for (int i = 1; i < cli.arguments().size(); i++) {
    31 			for (int i = 1; i < cli.arguments().size(); i++) {
    33 				arguments[i - 1] = cli.arguments()[i];
    32 				arguments[i - 1] = cli.arguments()[i];
    34 			}
    33 			}
    35 
    34 
    36 			if (action == L"demo") {
    35 			if (action == L"demo") {
    37 				resultCode = demo();
    36 				DemoCommand command;
       
    37 				command.process(cin, cout, action, arguments);
       
    38 				resultCode = CLI::EXIT_CODE_SUCCESS;
    38 			} else if (action == L"generate") {
    39 			} else if (action == L"generate") {
    39 				ArgumentsCommand command;
    40 				ArgumentsCommand command;
    40 				command.process(cin, cout, action, arguments);
    41 				command.process(cin, cout, action, arguments);
       
    42 				resultCode = CLI::EXIT_CODE_SUCCESS;
    41 			} else {
    43 			} else {
    42 				fwprintf(stderr, L"Unknown command: %ls\n", action.c_str());
    44 				fwprintf(stderr, L"Unknown command: %ls\n", action.c_str());
    43 				resultCode = CLI::EXIT_CODE_UNKNOWN_COMMAND;
    45 				resultCode = CLI::EXIT_CODE_UNKNOWN_COMMAND;
    44 			}
    46 			}
    45 
    47 
    52 		fwprintf(stderr, L"Caught exception: %ls\n", e.getMessge().c_str());
    54 		fwprintf(stderr, L"Caught exception: %ls\n", e.getMessge().c_str());
    53 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
    55 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
    54 		resultCode = CLI::EXIT_CODE_DATA_ERROR;
    56 		resultCode = CLI::EXIT_CODE_DATA_ERROR;
    55 	}
    57 	}
    56 
    58 
    57 
       
    58 	return resultCode;
    59 	return resultCode;
    59 
       
    60 }
    60 }
    61 
       
    62 int demo() {
       
    63 	using namespace relpipe::writer;
       
    64 	std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout));
       
    65 
       
    66 
       
    67 	// Various data types passed as strings
       
    68 	writer->startRelation(L"table_from_strings",{
       
    69 		{L"s", TypeId::STRING},
       
    70 		{L"i", TypeId::INTEGER},
       
    71 		{L"b", TypeId::BOOLEAN}
       
    72 	}, true);
       
    73 
       
    74 	writer->writeAttribute(L"a");
       
    75 	writer->writeAttribute(L"1");
       
    76 	writer->writeAttribute(L"true");
       
    77 
       
    78 	writer->writeAttribute(L"b");
       
    79 	writer->writeAttribute(L"2");
       
    80 	writer->writeAttribute(L"false");
       
    81 
       
    82 
       
    83 	// Various data types passed as raw pointers + typeids
       
    84 	writer->startRelation(L"from_raw_pointers",{
       
    85 		{L"s", TypeId::STRING},
       
    86 		{L"i", TypeId::INTEGER},
       
    87 		{L"b", TypeId::BOOLEAN}
       
    88 	}, true);
       
    89 
       
    90 	string_t sValue;
       
    91 	integer_t iValue;
       
    92 	boolean_t bValue;
       
    93 
       
    94 	for (int i = 0; i < 8; i++) {
       
    95 		sValue.append(L"*");
       
    96 		iValue = i + 1;
       
    97 		bValue = iValue % 2 == 0;
       
    98 		writer->writeAttribute(&sValue, typeid (sValue));
       
    99 		writer->writeAttribute(&iValue, typeid (iValue));
       
   100 		writer->writeAttribute(&bValue, typeid (bValue));
       
   101 	}
       
   102 
       
   103 	return 0;
       
   104 }