src/StreamRelationalReader.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 25 Aug 2018 19:10:24 +0200
branchv_0
changeset 16 9b8139bb0519
parent 14 e8de089f95dd
child 17 ec750c536705
permissions -rw-r--r--
handler structure

#pragma once

#include <string>
#include <iostream>
#include <vector>

#include <relpipe/protocol/constants.h>

#include "../include/relpipe/reader/typedefs.h"
#include "../include/relpipe/reader/RelationalReader.h"
#include "../include/relpipe/reader/TypeId.h"
#include "../include/relpipe/reader/handlers/RelationalReaderBaseHandler.h"
#include "../include/relpipe/reader/handlers/RelationalReaderStringHandler.h"
#include "../include/relpipe/reader/handlers/RelationalReaderValueHandler.h"
#include "DataTypeReaderBase.h"
#include "types/BooleanDataTypeReader.h"
#include "types/IntegerDataTypeReader.h"
#include "types/StringDataTypeReader.h"

namespace relpipe {
namespace reader {

using namespace relpipe::protocol;

class StreamRelationalReader : public RelationalReader {
private:
	std::istream &input;
	types::BooleanDataTypeReader booleanReader;
	types::IntegerDataTypeReader integerReader;
	types::StringDataTypeReader stringReader;
	std::vector<DataTypeReaderBase*> readers = {&booleanReader, &integerReader, &stringReader};

	/**
	 * count of columns in the current table
	 */
	integer_t columnCount;
	/**
	 * number of column (0 = first) that will be written; after writing, the number is increased and prepared for next one
	 */
	integer_t currentColumn;

	/**
	 * types of columns in the current table
	 */
	std::vector<TypeId> columnTypes;

public:

	StreamRelationalReader(std::istream &input) :
	input(input) {
	}

	string_t toTypeCode(const TypeId typeId) override {
		for (DataTypeReaderBase* reader : readers) if (reader->supports(typeId)) return reader->getTypeCode();
		throw RelpipeReaderException(L"Unsupported data type: " + static_cast<integer_t> (typeId));
	}

};

}
}