src/types/BooleanDataTypeWriter.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 25 Aug 2018 17:30:19 +0200
branchv_0
changeset 23 d505eaedc35e
parent 20 bef6648e79b1
child 29 142bdbba520f
permissions -rw-r--r--
remove format.h and use constants.h from lib-protocol

#pragma once

#include <string>
#include <iostream>

#include <relpipe/protocol/constants.h>

#include "../../include/relpipe/writer/RelpipeWriterException.h"
#include "../DataTypeWriter.h"

namespace relpipe {
namespace writer {
namespace types {

using namespace relpipe::protocol;
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>(TypeId::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");
	}

};

}
}
}