src/types/BooleanDataTypeWriter.h
branchv_0
changeset 10 40ab091e5dfa
parent 9 0a40752e401d
child 13 e7234dd45166
equal deleted inserted replaced
9:0a40752e401d 10:40ab091e5dfa
       
     1 #pragma once
       
     2 
       
     3 #include <string>
       
     4 #include <iostream>
       
     5 
       
     6 #include "../../include/RelpipeWriterException.h"
       
     7 #include "../DataTypeWriter.h"
       
     8 #include "../format.h"
       
     9 
       
    10 namespace relpipe {
       
    11 namespace writer {
       
    12 namespace types {
       
    13 
       
    14 using namespace relpipe::writer;
       
    15 
       
    16 class BooleanDataTypeWriter : public DataTypeWriter<boolean_t> {
       
    17 private:
       
    18 	const string_t TRUE = L"true";
       
    19 	const string_t FALSE = L"false";
       
    20 public:
       
    21 
       
    22 	BooleanDataTypeWriter() : DataTypeWriter<boolean_t>(DATA_TYPE_ID_BOOLEAN, DATA_TYPE_CODE_BOOLEAN) {
       
    23 	}
       
    24 
       
    25 	void writeValue(std::ostream &output, const boolean_t &value) override {
       
    26 		output.put(value ? 1 : 0);
       
    27 	}
       
    28 
       
    29 	bool toValue(const string_t &stringValue) override {
       
    30 		if (stringValue == TRUE) return true;
       
    31 		else if (stringValue == FALSE) return false;
       
    32 		else throw RelpipeWriterException(L"Unable to convert the string to boolean");
       
    33 	}
       
    34 
       
    35 };
       
    36 
       
    37 }
       
    38 }
       
    39 }