src/types/BooleanDataTypeReader.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 25 Aug 2018 18:16:53 +0200
branchv_0
changeset 14 e8de089f95dd
parent 12 src/BooleanDataTypeReader.h@2d7109286408
child 29 755978b0935c
permissions -rw-r--r--
refactoring, move files, use TypeId instead of integer_t
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#pragma once
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#include <string>
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
#include <iostream>
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
12
2d7109286408 remove format.h and use constants.h from lib-protocol
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
     6
#include <relpipe/protocol/constants.h>
2d7109286408 remove format.h and use constants.h from lib-protocol
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
     7
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
     8
#include "../../include/relpipe/reader/RelpipeReaderException.h"
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
     9
#include "../../include/relpipe/reader/typedefs.h"
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    10
#include "../DataTypeReader.h"
7
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
8
c87e9c84f7aa reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    12
namespace relpipe {
c87e9c84f7aa reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    13
namespace reader {
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    14
namespace types {
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    15
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    16
using namespace relpipe::protocol;
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    17
using namespace relpipe::reader;
7
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
8
c87e9c84f7aa reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    19
class BooleanDataTypeReader : public DataTypeReader<boolean_t> {
7
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
private:
8
c87e9c84f7aa reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    21
	const string_t TRUE = L"true";
c87e9c84f7aa reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    22
	const string_t FALSE = L"false";
7
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
public:
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    25
	BooleanDataTypeReader() : DataTypeReader<boolean_t>(TypeId::BOOLEAN, DATA_TYPE_CODE_BOOLEAN) {
7
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
	}
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
8
c87e9c84f7aa reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    28
	bool readValue(std::istream &input) override {
7
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
		auto value = input.get(); // TODO: check failbit
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
		if (value == 0) return false;
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
		else if (value == 1) return true;
8
c87e9c84f7aa reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    32
		else throw RelpipeReaderException(L"Unable to convert the octet to boolean");
7
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	}
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
8
c87e9c84f7aa reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    35
	string_t toString(const boolean_t &value) override {
7
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
		return value ? TRUE : FALSE;
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	}
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
};
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
8
c87e9c84f7aa reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    41
}
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    42
}
7
489e52138771 add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
}