author | František Kučera <franta-hg@frantovo.cz> |
Thu, 29 Nov 2018 22:30:12 +0100 | |
branch | v_0 |
changeset 29 | 755978b0935c |
parent 14 | e8de089f95dd |
child 30 | ef99f5a6c9f6 |
permissions | -rw-r--r-- |
29
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
1 |
/** |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
2 |
* Relational pipes |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
3 |
* Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
4 |
* |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
8 |
* (at your option) any later version. |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
9 |
* |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
13 |
* GNU General Public License for more details. |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
14 |
* |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
755978b0935c
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
17 |
*/ |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
#pragma once |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
#include <string> |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include <iostream> |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
12
2d7109286408
remove format.h and use constants.h from lib-protocol
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
23 |
#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
|
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 |
#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
|
26 |
#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
|
27 |
#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
|
28 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
29 |
namespace relpipe { |
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
30 |
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
|
31 |
namespace types { |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
32 |
|
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
36 |
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
|
37 |
private: |
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
38 |
const string_t TRUE = L"true"; |
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
39 |
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
|
40 |
public: |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
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 |
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
|
43 |
} |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
else if (value == 1) return true; |
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
49 |
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
|
50 |
} |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
} |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
|
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
}; |
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
|
8
c87e9c84f7aa
reader only reads + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
58 |
} |
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
59 |
} |
7
489e52138771
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
} |