author | František Kučera <franta-hg@frantovo.cz> |
Mon, 03 Sep 2018 23:41:29 +0200 | |
branch | v_0 |
changeset 26 | 8ae93a43fed2 |
parent 16 | 3613617d3076 |
child 29 | 142bdbba520f |
permissions | -rw-r--r-- |
1 | 1 |
#pragma once |
2 |
||
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
3 |
#include <functional> |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
4 |
#include <sstream> |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
5 |
|
1 | 6 |
#include "DataTypeWriterBase.h" |
7 |
||
8 |
namespace relpipe { |
|
9 |
namespace writer { |
|
10 |
||
11 |
template<typename T> class DataTypeWriter : public DataTypeWriterBase { |
|
12 |
public: |
|
13 |
||
15
8fd6c4d44071
use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
14 |
DataTypeWriter(const TypeId typeId, const string_t typeCode) : DataTypeWriterBase(typeId, typeCode) { |
1 | 15 |
} |
16 |
||
17 |
virtual ~DataTypeWriter() { |
|
18 |
}; |
|
19 |
||
20 |
virtual void writeValue(std::ostream& output, const T& value) = 0; |
|
21 |
||
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
22 |
void writeRaw(std::ostream& output, const void * value, const std::type_info& type) override { |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
23 |
if (type == typeid (T)) { |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
24 |
const T v = *(static_cast<const T*>(value)); |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
25 |
writeValue(output, v); |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
26 |
} else { |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
27 |
wstringstream message; |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
28 |
message << L"Data type in writeRaw() does not match – got: " << type.name() << " but expected: " << typeid (T).name(); |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
29 |
throw RelpipeWriterException(message.str()); |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
30 |
} |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
31 |
} |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
32 |
|
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
33 |
void writeString(std::ostream& output, const string_t &stringValue) override { |
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
34 |
writeValue(output, toValue(stringValue)); |
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
35 |
} |
1 | 36 |
|
37 |
virtual T toValue(const string_t &stringValue) = 0; |
|
38 |
||
39 |
}; |
|
40 |
||
41 |
} |
|
42 |
} |