src/CSVHandler.h
branchv_0
changeset 0 97967db4b95b
child 1 82f86dc48339
equal deleted inserted replaced
-1:000000000000 0:97967db4b95b
       
     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, either version 3 of the License, or
       
     8  * (at your option) any later version.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    17  */
       
    18 #pragma once
       
    19 
       
    20 #include <memory>
       
    21 #include <string>
       
    22 #include <vector>
       
    23 #include <iostream>
       
    24 #include <sstream>
       
    25 #include <locale>
       
    26 #include <codecvt>
       
    27 
       
    28 #include <relpipe/reader/typedefs.h>
       
    29 #include <relpipe/reader/TypeId.h>
       
    30 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h>
       
    31 #include <relpipe/reader/handlers/AttributeMetadata.h>
       
    32 
       
    33 namespace relpipe {
       
    34 namespace out {
       
    35 namespace csv {
       
    36 
       
    37 using namespace relpipe;
       
    38 using namespace relpipe::reader;
       
    39 using namespace relpipe::reader::handlers;
       
    40 
       
    41 class CSVHandler : public RelationalReaderStringHadler {
       
    42 private:
       
    43 	std::ostream& output;
       
    44 	std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
       
    45 public:
       
    46 
       
    47 	CSVHandler(std::ostream& output) : output(output) {
       
    48 	}
       
    49 
       
    50 	void startRelation(string_t name, std::vector<AttributeMetadata> attributes) override {
       
    51 
       
    52 	}
       
    53 
       
    54 	void attribute(const string_t& value) override {
       
    55 		output << convertor.to_bytes(value).c_str();
       
    56 		output.put(0);
       
    57 	}
       
    58 
       
    59 	void endOfPipe() {
       
    60 		output.flush();
       
    61 	}
       
    62 
       
    63 };
       
    64 
       
    65 }
       
    66 }
       
    67 }