move demo code to DemoCommand.h v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 28 Jul 2018 14:16:44 +0200
branchv_0
changeset 12 bc6fe00dd831
parent 11 3798b6bc9aea
child 13 5e95f0c0a4f9
move demo code to DemoCommand.h
DemoCommand.h
nbproject/configurations.xml
relpipe-in-cli.cpp
--- /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 <cstdlib>
+#include <iostream>
+#include <string>
+#include <vector>
+#include <algorithm>
+
+#include <typedefs.h>
+
+#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<relpipe::writer::string_t>& arguments) override {
+		using namespace relpipe::writer;
+		std::shared_ptr<RelationalWriter> 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));
+		}
+	}
+};
+
+}
+}
+}
--- 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 @@
       <itemPath>ArgumentsCommand.h</itemPath>
       <itemPath>CLI.h</itemPath>
       <itemPath>Command.h</itemPath>
+      <itemPath>DemoCommand.h</itemPath>
     </logicalFolder>
     <logicalFolder name="ResourceFiles"
                    displayName="Resource Files"
@@ -59,6 +60,8 @@
       </item>
       <item path="Command.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="DemoCommand.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="relpipe-in-cli.cpp" ex="false" tool="1" flavor2="0">
       </item>
     </conf>
@@ -94,6 +97,8 @@
       </item>
       <item path="Command.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="DemoCommand.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="relpipe-in-cli.cpp" ex="false" tool="1" flavor2="0">
       </item>
     </conf>
--- 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<RelationalWriter> 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;
-}