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

#pragma once

#include <string>
#include <iostream>

#include "../include/typedefs.h"
#include "../include/DataTypeReader.h"
#include "format.h"

namespace relpipe {
namespace reader {

class BooleanDataTypeReader : public DataTypeReader<boolean_t> {
private:
	const string_t TRUE = L"true";
	const string_t FALSE = L"false";
public:

	BooleanDataTypeReader() : DataTypeReader<boolean_t>(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;
	}

};

}
}