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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#pragma once
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#include <string>
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
#include <iostream>
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
23
d505eaedc35e remove format.h and use constants.h from lib-protocol
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
     6
#include <relpipe/protocol/constants.h>
d505eaedc35e remove format.h and use constants.h from lib-protocol
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
     7
20
bef6648e79b1 relpipe-lib-writer: move public header files to: include/relpipe/writer/
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
     8
#include "../../include/relpipe/writer/RelpipeWriterException.h"
10
40ab091e5dfa move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
     9
#include "../DataTypeWriter.h"
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    11
namespace relpipe {
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    12
namespace writer {
10
40ab091e5dfa move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    13
namespace types {
40ab091e5dfa move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    14
23
d505eaedc35e remove format.h and use constants.h from lib-protocol
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    15
using namespace relpipe::protocol;
10
40ab091e5dfa move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    16
using namespace relpipe::writer;
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    18
class BooleanDataTypeWriter : public DataTypeWriter<boolean_t> {
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
private:
13
e7234dd45166 use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    20
    const string_t TRUE = L"true";
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    21
	const string_t FALSE = L"false";
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
public:
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    24
	BooleanDataTypeWriter() : DataTypeWriter<boolean_t>(TypeId::BOOLEAN, DATA_TYPE_CODE_BOOLEAN) {
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
	}
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    27
	void writeValue(std::ostream &output, const boolean_t &value) override {
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
		output.put(value ? 1 : 0);
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
	}
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    31
	bool toValue(const string_t &stringValue) override {
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		if (stringValue == TRUE) return true;
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
		else if (stringValue == FALSE) return false;
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    34
		else throw RelpipeWriterException(L"Unable to convert the string to boolean");
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	}
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
};
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    39
}
10
40ab091e5dfa move *DataTypeWriter.h to separate directory
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    40
}
13
e7234dd45166 use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    41
}