equal
deleted
inserted
replaced
1 #pragma once |
|
2 |
|
3 #include <string> |
|
4 #include <iostream> |
|
5 |
|
6 #include <relpipe/protocol/constants.h> |
|
7 |
|
8 #include "../include/typedefs.h" |
|
9 #include "../include/DataTypeReader.h" |
|
10 |
|
11 namespace relpipe { |
|
12 namespace reader { |
|
13 |
|
14 class BooleanDataTypeReader : public DataTypeReader<boolean_t> { |
|
15 private: |
|
16 const string_t TRUE = L"true"; |
|
17 const string_t FALSE = L"false"; |
|
18 public: |
|
19 |
|
20 BooleanDataTypeReader() : DataTypeReader<boolean_t>(DATA_TYPE_ID_BOOLEAN, DATA_TYPE_CODE_BOOLEAN) { |
|
21 } |
|
22 |
|
23 bool readValue(std::istream &input) override { |
|
24 auto value = input.get(); // TODO: check failbit |
|
25 if (value == 0) return false; |
|
26 else if (value == 1) return true; |
|
27 else throw RelpipeReaderException(L"Unable to convert the octet to boolean"); |
|
28 } |
|
29 |
|
30 string_t toString(const boolean_t &value) override { |
|
31 return value ? TRUE : FALSE; |
|
32 } |
|
33 |
|
34 }; |
|
35 |
|
36 } |
|
37 } |
|