src/StreamRelationalReader.h
branchv_0
changeset 26 019edca46769
parent 25 fc0d05b72214
child 28 c9e03557c1e1
equal deleted inserted replaced
25:fc0d05b72214 26:019edca46769
     3 #include <string>
     3 #include <string>
     4 #include <iostream>
     4 #include <iostream>
     5 #include <vector>
     5 #include <vector>
     6 
     6 
     7 #include <relpipe/protocol/constants.h>
     7 #include <relpipe/protocol/constants.h>
       
     8 #include <memory>
     8 
     9 
     9 #include "../include/relpipe/reader/typedefs.h"
    10 #include "../include/relpipe/reader/typedefs.h"
    10 #include "../include/relpipe/reader/RelationalReader.h"
    11 #include "../include/relpipe/reader/RelationalReader.h"
    11 #include "../include/relpipe/reader/TypeId.h"
    12 #include "../include/relpipe/reader/TypeId.h"
    12 #include "../include/relpipe/reader/handlers/RelationalReaderBaseHandler.h"
    13 #include "../include/relpipe/reader/handlers/RelationalReaderBaseHandler.h"
    23 
    24 
    24 using namespace relpipe::protocol;
    25 using namespace relpipe::protocol;
    25 
    26 
    26 using StringHandler = relpipe::reader::handlers::RelationalReaderStringHadler;
    27 using StringHandler = relpipe::reader::handlers::RelationalReaderStringHadler;
    27 using ValuesHandler = relpipe::reader::handlers::RelationalReaderValueHadler;
    28 using ValuesHandler = relpipe::reader::handlers::RelationalReaderValueHadler;
       
    29 using AttributeMetadata = relpipe::reader::handlers::AttributeMetadata;
       
    30 using AttributeMetadataPrivate = relpipe::reader::handlers::AttributeMetadataPrivate;
    28 
    31 
    29 class StreamRelationalReader : public RelationalReader {
    32 class StreamRelationalReader : public RelationalReader {
    30 private:
    33 private:
    31 	std::istream &input;
    34 	std::istream &input;
    32 	types::BooleanDataTypeReader booleanReader;
    35 	types::BooleanDataTypeReader booleanReader;
    49 	/**
    52 	/**
    50 	 * types of columns in the current table
    53 	 * types of columns in the current table
    51 	 */
    54 	 */
    52 	std::vector<TypeId> columnTypes;
    55 	std::vector<TypeId> columnTypes;
    53 	std::vector<string_t> columnNames;
    56 	std::vector<string_t> columnNames;
    54 	std::vector<handlers::AttributeMetadata> columns;
    57 	std::vector<AttributeMetadata> columns;
    55 
    58 
    56 	/**
    59 	/**
    57 	 * TODO: remove?
    60 	 * TODO: remove?
    58 	 */
    61 	 */
    59 	string_t readString(std::istream &input, const TypeId typeId) {
    62 	string_t readString(std::istream &input, const TypeId typeId) {
   156 					TypeId typeId = (TypeId) integerReader.readValue(input); // TODO: přetypování OK?
   159 					TypeId typeId = (TypeId) integerReader.readValue(input); // TODO: přetypování OK?
   157 					string_t typeCode = toTypeCode(typeId); // validate typeId TODO: je potřeba?
   160 					string_t typeCode = toTypeCode(typeId); // validate typeId TODO: je potřeba?
   158 					columnTypes.push_back(typeId);
   161 					columnTypes.push_back(typeId);
   159 
   162 
   160 					// put together names, type ids and type codes:
   163 					// put together names, type ids and type codes:
   161 					columns.push_back(handlers::AttributeMetadata(new handlers::AttributeMetadataPrivate({columnNames[i], columnTypes[i], typeCode})));
   164 					columns.push_back(std::shared_ptr<AttributeMetadataPrivate>(new AttributeMetadataPrivate({columnNames[i], columnTypes[i], typeCode})));
   162 				}
   165 				}
   163 
   166 
   164 				for (StringHandler* handler : stringHandlers) handler->startRelation(tableName, columns);
   167 				for (StringHandler* handler : stringHandlers) handler->startRelation(tableName, columns);
   165 				for (ValuesHandler* handler : valuesHandlers) handler->startRelation(tableName, columns);
   168 				for (ValuesHandler* handler : valuesHandlers) handler->startRelation(tableName, columns);
   166 
   169