author | František Kučera <franta-hg@frantovo.cz> |
Sat, 08 Sep 2018 19:43:20 +0200 | |
branch | v_0 |
changeset 20 | befcfabc20fd |
parent 18 | e11f1ad20826 |
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 |
|
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
#include <string> |
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
4 |
#include <functional> |
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
5 |
#include "../include/relpipe/reader/TypeId.h" |
13
543f1613c2da
move non-public headers from include to src
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
6 |
#include "../include/relpipe/reader/typedefs.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 |
|
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
/** |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* This class contains common features that are independent from particular data type (generic/template type) |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
*/ |
2
fc3a84a62dd9
rename writers to readers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
14 |
class DataTypeReaderBase { |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
private: |
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
16 |
const TypeId typeId; |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
const string_t typeCode; |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
public: |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
20 |
DataTypeReaderBase(const TypeId typeId, const string_t typeCode) : |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
typeId(typeId), typeCode(typeCode) { |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
} |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
|
2
fc3a84a62dd9
rename writers to readers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
24 |
virtual ~DataTypeReaderBase() { |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
}; |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
|
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
/** |
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
28 |
* TODO: delete, use handler? |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
29 |
* |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
* @param input input stream, should be at position where the value is to be read; the stream will not be closed afred reading |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
* @return read value in form of the string representation of given data type. |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
* E.g. integer 123 is returned as a character string "123", |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
* boolean true is returned as a character string "true". |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
* See Relational pipes format specification for details. |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
*/ |
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 readString(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
|
37 |
|
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
/** |
18
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
39 |
* The value is read from the input and then passed to the handler. |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
40 |
* |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
41 |
* @param input |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
42 |
* @param handler |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
43 |
*/ |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
44 |
virtual void read(std::istream &input, std::function<void(const void *, const std::type_info&) > handler) = 0; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
45 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
46 |
/** |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
47 |
* TODO: documentation |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
48 |
* |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
49 |
* @param input |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
50 |
* @param handler |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
51 |
*/ |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
52 |
virtual void read(std::istream &input, std::function<void(const string_t&, const void *, const std::type_info&) > handler) = 0; |
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
53 |
|
e11f1ad20826
read using std::function
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
54 |
/** |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
* @param dataType data type code as defined in DDP L0 |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
* @return whether this class supports conversions of this type |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
*/ |
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
58 |
virtual bool supports(const TypeId &dataType) { |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
59 |
return dataType == typeId; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
60 |
} |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
|
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
/** |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
* @param dataType data type name as defined in DDP L0 |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
* @return whether this class supports conversions of this type |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
*/ |
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
66 |
virtual bool supports(const string_t &dataType) { |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
67 |
return dataType == typeCode; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
68 |
} |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
|
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
70 |
TypeId getTypeId() { |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
71 |
return typeId; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
72 |
} |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
73 |
|
14
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
74 |
string_t getTypeCode() { |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
75 |
return typeCode; |
e8de089f95dd
refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
76 |
} |
1
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
}; |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
|
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
79 |
} |
c80d55cdb42d
copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
80 |
} |