# HG changeset patch # User František Kučera # Date 1543940350 -3600 # Node ID 12ffbdbb35743b1a2048351beb0fc81ee3fd508a # Parent 0161ea43ce2a879098be16f873dc46b1d717fdbd NullByteHandler: produces \0-separated values diff -r 0161ea43ce2a -r 12ffbdbb3574 nbproject/configurations.xml --- a/nbproject/configurations.xml Tue Dec 04 15:20:03 2018 +0100 +++ b/nbproject/configurations.xml Tue Dec 04 17:19:10 2018 +0100 @@ -80,7 +80,6 @@ ../relpipe-lib-reader.cpp/include - ../relpipe-lib-writer.cpp/include ../relpipe-lib-cli.cpp/include build/Debug/src diff -r 0161ea43ce2a -r 12ffbdbb3574 nbproject/project.xml --- a/nbproject/project.xml Tue Dec 04 15:20:03 2018 +0100 +++ b/nbproject/project.xml Tue Dec 04 17:19:10 2018 +0100 @@ -45,7 +45,7 @@ relpipe-out-nullbyte.cpp cpp - + h UTF-8 . diff -r 0161ea43ce2a -r 12ffbdbb3574 src/CMakeLists.txt --- a/src/CMakeLists.txt Tue Dec 04 15:20:03 2018 +0100 +++ b/src/CMakeLists.txt Tue Dec 04 17:19:10 2018 +0100 @@ -18,7 +18,7 @@ # Relpipe libraries: INCLUDE(FindPkgConfig) -pkg_check_modules (RELPIPE_LIBS relpipe-lib-reader.cpp relpipe-lib-writer.cpp relpipe-lib-cli.cpp) +pkg_check_modules (RELPIPE_LIBS relpipe-lib-reader.cpp relpipe-lib-cli.cpp) include_directories(${RELPIPE_LIBS_INCLUDE_DIRS}) link_directories(${RELPIPE_LIBS_LIBRARY_DIRS}) @@ -30,6 +30,7 @@ # Executable output: add_executable( ${EXECUTABLE_FILE} + NullByteHandler.h relpipe-out-nullbyte.cpp ) diff -r 0161ea43ce2a -r 12ffbdbb3574 src/NullByteHandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/NullByteHandler.h Tue Dec 04 17:19:10 2018 +0100 @@ -0,0 +1,67 @@ +/** + * Relational pipes + * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace relpipe { +namespace out { +namespace nullbyte { + +using namespace relpipe; +using namespace relpipe::reader; +using namespace relpipe::reader::handlers; + +class NullByteHandler : public RelationalReaderStringHadler { +private: + std::ostream& output; + std::wstring_convert> convertor; // TODO: support also other encodings. +public: + + NullByteHandler(std::ostream& output) : output(output) { + } + + void startRelation(string_t name, std::vector attributes) override { + + } + + void attribute(const string_t& value) override { + output << convertor.to_bytes(value).c_str(); + output.put(0); + } + + void endOfPipe() { + output.flush(); + } + +}; + +} +} +} diff -r 0161ea43ce2a -r 12ffbdbb3574 src/relpipe-out-nullbyte.cpp --- a/src/relpipe-out-nullbyte.cpp Tue Dec 04 15:20:03 2018 +0100 +++ b/src/relpipe-out-nullbyte.cpp Tue Dec 04 17:19:10 2018 +0100 @@ -26,13 +26,11 @@ #include #include -#include -#include -#include -#include +#include "NullByteHandler.h" using namespace relpipe::cli; using namespace relpipe::reader; +using namespace relpipe::out::nullbyte; int main(int argc, char**argv) { CLI cli(argc, argv); @@ -41,8 +39,8 @@ try { std::shared_ptr reader(Factory::create(std::cin)); - //TabularPrefetchingHandler handler(std::cout); - //reader->addHandler(&handler); + NullByteHandler handler(std::cout); + reader->addHandler(&handler); reader->process(); resultCode = CLI::EXIT_CODE_SUCCESS;