src/DemoCommand.h
branchv_0
changeset 42 09cd32a65709
parent 41 0776c8c94dae
child 43 3c8ea5dcf793
equal deleted inserted replaced
41:0776c8c94dae 42:09cd32a65709
     1 /**
       
     2  * Relational pipes
       
     3  * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info)
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation, version 3 of the License.
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    16  */
       
    17 #pragma once
       
    18 
       
    19 #include <cstdlib>
       
    20 #include <iostream>
       
    21 #include <string>
       
    22 #include <vector>
       
    23 #include <algorithm>
       
    24 
       
    25 #include <relpipe/writer/typedefs.h>
       
    26 
       
    27 #include "Command.h"
       
    28 
       
    29 namespace relpipe {
       
    30 namespace in {
       
    31 namespace cli {
       
    32 
       
    33 class DemoCommand : public Command {
       
    34 public:
       
    35 
       
    36 	void process(std::istream& input, std::ostream& output, const relpipe::writer::string_t& command, const std::vector<relpipe::writer::string_t>& arguments) override {
       
    37 		using namespace relpipe::writer;
       
    38 		std::shared_ptr<RelationalWriter> writer(Factory::create(output));
       
    39 
       
    40 
       
    41 		// Various data types passed as strings
       
    42 		writer->startRelation(L"table_from_strings",{
       
    43 			{L"s", TypeId::STRING},
       
    44 			{L"i", TypeId::INTEGER},
       
    45 			{L"b", TypeId::BOOLEAN}
       
    46 		}, true);
       
    47 
       
    48 		writer->writeAttribute(L"a");
       
    49 		writer->writeAttribute(L"1");
       
    50 		writer->writeAttribute(L"true");
       
    51 
       
    52 		writer->writeAttribute(L"b");
       
    53 		writer->writeAttribute(L"2");
       
    54 		writer->writeAttribute(L"false");
       
    55 
       
    56 
       
    57 		// Various data types passed as raw pointers + typeids
       
    58 		writer->startRelation(L"from_raw_pointers",{
       
    59 			{L"s", TypeId::STRING},
       
    60 			{L"i", TypeId::INTEGER},
       
    61 			{L"b", TypeId::BOOLEAN}
       
    62 		}, true);
       
    63 
       
    64 		string_t sValue;
       
    65 		integer_t iValue;
       
    66 		boolean_t bValue;
       
    67 
       
    68 		for (int i = 0; i < 8; i++) {
       
    69 			sValue.append(L"*");
       
    70 			iValue = i + 1;
       
    71 			bValue = iValue % 2 == 0;
       
    72 			writer->writeAttribute(&sValue, typeid (sValue));
       
    73 			writer->writeAttribute(&iValue, typeid (iValue));
       
    74 			writer->writeAttribute(&bValue, typeid (bValue));
       
    75 		}
       
    76 	}
       
    77 };
       
    78 
       
    79 }
       
    80 }
       
    81 }