src/types/BooleanDataTypeWriter.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 21 Jul 2018 23:46:29 +0200
branchv_0
changeset 13 e7234dd45166
parent 10 40ab091e5dfa
child 15 8fd6c4d44071
permissions -rw-r--r--
use TypeId enum instead of numeric constants

#pragma once

#include <string>
#include <iostream>

#include "../../include/RelpipeWriterException.h"
#include "../DataTypeWriter.h"
#include "../format.h"

namespace relpipe {
namespace writer {
namespace types {

using namespace relpipe::writer;

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

	BooleanDataTypeWriter() : DataTypeWriter<boolean_t>(DATA_TYPE_ID_BOOLEAN, DATA_TYPE_CODE_BOOLEAN) {
	}

	void writeValue(std::ostream &output, const boolean_t &value) override {
		output.put(value ? 1 : 0);
	}

	bool toValue(const string_t &stringValue) override {
		if (stringValue == TRUE) return true;
		else if (stringValue == FALSE) return false;
		else throw RelpipeWriterException(L"Unable to convert the string to boolean");
	}

};

}
}
}