src/DataTypeReaderCatalog.h
author František Kučera <franta-hg@frantovo.cz>
Mon, 13 Aug 2018 21:30:32 +0200
branchv_0
changeset 10 7fe3975f7e4b
parent 8 c87e9c84f7aa
permissions -rw-r--r--
relpipe-lib-reader: move public header files to: include/relpipe/reader/

#pragma once

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

#include "../include/typedefs.h"
#include "../include/DataTypeReaderBase.h"
#include "../include/RelpipeReaderException.h"

#include "BooleanDataTypeReader.h"
#include "IntegerDataTypeReader.h"
#include "StringDataTypeReader.h"

using namespace std;

namespace relpipe {
namespace reader {

class DataTypeReaderCatalog {
private:
	BooleanDataTypeReader booleanReader;
	IntegerDataTypeReader integerReader;
	StringDataTypeReader stringReader;
	vector<DataTypeReaderBase*> readers = {&booleanReader, &integerReader, &stringReader};
public:

	integer_t toTypeId(const wstring typeCode) {
		for (DataTypeReaderBase* reader : readers) if (reader->supports(typeCode)) return reader->getTypeId();
		throw RelpipeReaderException(L"Unsupported data type: " + typeCode);
	}

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

	wstring readString(istream &input, const integer_t typeId) {
		for (DataTypeReaderBase* reader : readers) if (reader->supports(typeId)) return reader->readString(input);
		throw RelpipeReaderException(L"Unsupported data type: " + typeId);
	}

};

}
}