#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);
}
};
}
}