src/DataTypeWriter.h
branchv_0
changeset 16 3613617d3076
parent 15 8fd6c4d44071
child 29 142bdbba520f
equal deleted inserted replaced
15:8fd6c4d44071 16:3613617d3076
     1 #pragma once
     1 #pragma once
       
     2 
       
     3 #include <functional>
       
     4 #include <sstream>
     2 
     5 
     3 #include "DataTypeWriterBase.h"
     6 #include "DataTypeWriterBase.h"
     4 
     7 
     5 namespace relpipe {
     8 namespace relpipe {
     6 namespace writer {
     9 namespace writer {
    14 	virtual ~DataTypeWriter() {
    17 	virtual ~DataTypeWriter() {
    15 	};
    18 	};
    16 
    19 
    17 	virtual void writeValue(std::ostream& output, const T& value) = 0;
    20 	virtual void writeValue(std::ostream& output, const T& value) = 0;
    18 
    21 
       
    22 	void writeRaw(std::ostream& output, const void * value, const std::type_info& type) override {
       
    23 		if (type == typeid (T)) {
       
    24 			const T v = *(static_cast<const T*>(value));
       
    25 			writeValue(output, v);
       
    26 		} else {
       
    27 			wstringstream message;
       
    28 			message << L"Data type in writeRaw() does not match – got: " << type.name() << " but expected: " << typeid (T).name();
       
    29 			throw RelpipeWriterException(message.str());
       
    30 		}
       
    31 	}
       
    32 
    19 	void writeString(std::ostream& output, const string_t &stringValue) override {
    33 	void writeString(std::ostream& output, const string_t &stringValue) override {
    20 		writeValue(output, toValue(stringValue));
    34 		writeValue(output, toValue(stringValue));
    21 	}
    35 	}
    22 
    36 
    23 	virtual T toValue(const string_t &stringValue) = 0;
    37 	virtual T toValue(const string_t &stringValue) = 0;