#pragma once
#include <functional>
#include <sstream>
#include "DataTypeWriterBase.h"
namespace relpipe {
namespace writer {
template<typename T> class DataTypeWriter : public DataTypeWriterBase {
public:
DataTypeWriter(const TypeId typeId, const string_t typeCode) : DataTypeWriterBase(typeId, typeCode) {
}
virtual ~DataTypeWriter() {
};
virtual void writeValue(std::ostream& output, const T& value) = 0;
void writeRaw(std::ostream& output, const void * value, const std::type_info& type) override {
if (type == typeid (T)) {
const T v = *(static_cast<const T*>(value));
writeValue(output, v);
} else {
wstringstream message;
message << L"Data type in writeRaw() does not match – got: " << type.name() << " but expected: " << typeid (T).name();
throw RelpipeWriterException(message.str());
}
}
void writeString(std::ostream& output, const string_t &stringValue) override {
writeValue(output, toValue(stringValue));
}
virtual T toValue(const string_t &stringValue) = 0;
};
}
}