author | František Kučera <franta-hg@frantovo.cz> |
Mon, 03 Sep 2018 23:40:12 +0200 | |
branch | v_0 |
changeset 18 | e11f1ad20826 |
parent 15 | 09ca53671b28 |
child 29 | 755978b0935c |
permissions | -rw-r--r-- |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
#pragma once |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
|
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
3 |
#include <sstream> |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
4 |
#include <functional> |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
5 |
|
2
fc3a84a62dd9
rename writers to readers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
6 |
#include "DataTypeReaderBase.h" |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
|
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
namespace relpipe { |
4
da021e58c946
rename 'writer' namespace to 'reader'
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
9 |
namespace reader { |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
|
2
fc3a84a62dd9
rename writers to readers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
11 |
template<typename T> class DataTypeReader : public DataTypeReaderBase { |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
public: |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
|
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
14 |
DataTypeReader(const TypeId typeId, const string_t typeCode) : DataTypeReaderBase(typeId, typeCode) { |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
} |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
|
2
fc3a84a62dd9
rename writers to readers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
17 |
virtual ~DataTypeReader() { |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
}; |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
virtual T readValue(std::istream& input) = 0; |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
|
15
09ca53671b28
remove DataTypeReader.cpp (move implementation to DataTypeReader.h)
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
22 |
virtual string_t readString(std::istream &input) { |
09ca53671b28
remove DataTypeReader.cpp (move implementation to DataTypeReader.h)
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
23 |
return toString(readValue(input)); |
09ca53671b28
remove DataTypeReader.cpp (move implementation to DataTypeReader.h)
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
24 |
} |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
|
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
26 |
virtual void read(std::istream &input, std::function<void(const void *, const std::type_info&) > handler) override { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
27 |
T value = readValue(input); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
28 |
handler(&value, typeid (T)); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
29 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
30 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
31 |
virtual void read(std::istream &input, std::function<void(const string_t&, const void *, const std::type_info&) > handler) override { |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
32 |
T value = readValue(input); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
33 |
handler(toString(value), &value, typeid (T)); |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
34 |
} |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
35 |
|
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
virtual string_t toString(const T& value) = 0; |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
|
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
}; |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
|
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
} |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
} |