DemoHandler (not an actual tabular handler) v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 03 Sep 2018 23:44:34 +0200
branchv_0
changeset 3 9a4062b12fc9
parent 2 31ef97e63eb0
child 4 d13b0b5969aa
DemoHandler (not an actual tabular handler)
nbproject/Makefile-Debug.mk
nbproject/Makefile-Release.mk
nbproject/configurations.xml
nbproject/project.xml
relpipe-out-tabular.cpp
--- a/nbproject/Makefile-Debug.mk	Sat Aug 25 12:29:03 2018 +0200
+++ b/nbproject/Makefile-Debug.mk	Mon Sep 03 23:44:34 2018 +0200
@@ -34,7 +34,8 @@
 OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}
 
 # Object Files
-OBJECTFILES=
+OBJECTFILES= \
+	${OBJECTDIR}/relpipe-out-tabular.o
 
 
 # C Compiler Flags
@@ -59,7 +60,12 @@
 
 ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/relpipe-out-tabular.cpp: ${OBJECTFILES}
 	${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
-	${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/relpipe-out-tabular.cpp ${OBJECTFILES} ${LDLIBSOPTIONS}
+	${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/relpipe-out-tabular.cpp ${OBJECTFILES} ${LDLIBSOPTIONS}
+
+${OBJECTDIR}/relpipe-out-tabular.o: relpipe-out-tabular.cpp
+	${MKDIR} -p ${OBJECTDIR}
+	${RM} "$@.d"
+	$(COMPILE.cc) -g `pkg-config --cflags relpipe-lib-cli.cpp` `pkg-config --cflags relpipe-lib-reader.cpp`   -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/relpipe-out-tabular.o relpipe-out-tabular.cpp
 
 # Subprojects
 .build-subprojects:
--- a/nbproject/Makefile-Release.mk	Sat Aug 25 12:29:03 2018 +0200
+++ b/nbproject/Makefile-Release.mk	Mon Sep 03 23:44:34 2018 +0200
@@ -34,7 +34,8 @@
 OBJECTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}
 
 # Object Files
-OBJECTFILES=
+OBJECTFILES= \
+	${OBJECTDIR}/relpipe-out-tabular.o
 
 
 # C Compiler Flags
@@ -59,7 +60,12 @@
 
 ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/relpipe-out-tabular.cpp: ${OBJECTFILES}
 	${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
-	${LINK.c} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/relpipe-out-tabular.cpp ${OBJECTFILES} ${LDLIBSOPTIONS}
+	${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/relpipe-out-tabular.cpp ${OBJECTFILES} ${LDLIBSOPTIONS}
+
+${OBJECTDIR}/relpipe-out-tabular.o: relpipe-out-tabular.cpp
+	${MKDIR} -p ${OBJECTDIR}
+	${RM} "$@.d"
+	$(COMPILE.cc) -O2 `pkg-config --cflags relpipe-lib-cli.cpp` `pkg-config --cflags relpipe-lib-reader.cpp`   -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/relpipe-out-tabular.o relpipe-out-tabular.cpp
 
 # Subprojects
 .build-subprojects:
--- a/nbproject/configurations.xml	Sat Aug 25 12:29:03 2018 +0200
+++ b/nbproject/configurations.xml	Mon Sep 03 23:44:34 2018 +0200
@@ -12,6 +12,7 @@
     <logicalFolder name="SourceFiles"
                    displayName="Source Files"
                    projectFiles="true">
+      <itemPath>relpipe-out-tabular.cpp</itemPath>
     </logicalFolder>
     <logicalFolder name="TestFiles"
                    displayName="Test Files"
@@ -44,6 +45,8 @@
           </linkerLibItems>
         </linkerTool>
       </compileType>
+      <item path="relpipe-out-tabular.cpp" ex="false" tool="1" flavor2="0">
+      </item>
     </conf>
     <conf name="Release" type="1">
       <toolsSet>
@@ -71,6 +74,8 @@
           </linkerLibItems>
         </linkerTool>
       </compileType>
+      <item path="relpipe-out-tabular.cpp" ex="false" tool="1" flavor2="0">
+      </item>
     </conf>
   </confs>
 </configurationDescriptor>
--- a/nbproject/project.xml	Sat Aug 25 12:29:03 2018 +0200
+++ b/nbproject/project.xml	Mon Sep 03 23:44:34 2018 +0200
@@ -5,7 +5,7 @@
         <data xmlns="http://www.netbeans.org/ns/make-project/1">
             <name>relpipe-out-tabular.cpp</name>
             <c-extensions/>
-            <cpp-extensions/>
+            <cpp-extensions>cpp</cpp-extensions>
             <header-extensions/>
             <sourceEncoding>UTF-8</sourceEncoding>
             <make-dep-projects/>
--- /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 <cstdlib>
+#include <memory>
+
+#include <relpipe/cli/CLI.h>
+#include <relpipe/cli/RelpipeCLIException.h>
+#include <relpipe/reader/Factory.h>
+#include <relpipe/reader/RelationalReader.h>
+#include <relpipe/reader/RelpipeReaderException.h>
+
+
+using namespace relpipe::cli;
+using namespace relpipe::reader;
+
+class DemoHandler : public handlers::RelationalReaderStringHadler {
+
+	void startRelation(string_t name, std::vector<std::pair<string_t, TypeId> > 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<wstring> arguments(cli.arguments().size() - 1);
+		// for (int i = 1; i < cli.arguments().size(); i++) {
+		//	arguments[i - 1] = cli.arguments()[i];
+		// }
+
+		std::shared_ptr<RelationalReader> 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;
+}