diff -r 489e52138771 -r c87e9c84f7aa src/BooleanDataTypeReader.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/BooleanDataTypeReader.h Sun Jul 15 00:15:09 2018 +0200 @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +#include "../include/typedefs.h" +#include "../include/DataTypeReader.h" +#include "../include/DataTypeReader.h" +#include "format.h" + +namespace relpipe { +namespace reader { + +class BooleanDataTypeReader : public DataTypeReader { +private: + const string_t TRUE = L"true"; + const string_t FALSE = L"false"; +public: + + BooleanDataTypeReader() : DataTypeReader(DATA_TYPE_ID_BOOLEAN, DATA_TYPE_CODE_BOOLEAN) { + } + + bool readValue(std::istream &input) override { + auto value = input.get(); // TODO: check failbit + if (value == 0) return false; + else if (value == 1) return true; + else throw RelpipeReaderException(L"Unable to convert the octet to boolean"); + } + + string_t toString(const boolean_t &value) override { + return value ? TRUE : FALSE; + } + +}; + +} +} \ No newline at end of file