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