|
1 #pragma once |
|
2 |
|
3 #include <string> |
|
4 #include <iostream> |
|
5 #include <vector> |
|
6 |
|
7 #include "typedefs.h" |
|
8 #include "TypeId.h" |
|
9 |
|
10 namespace relpipe { |
|
11 namespace writer { |
|
12 |
|
13 class RelationalWriter { |
|
14 public: |
|
15 |
|
16 virtual ~RelationalWriter() = default; |
|
17 |
|
18 /** |
|
19 * @param typeCode string type code as defined in Specification |
|
20 * @return numeric id of given type |
|
21 * @throws RelpipeWriterException on unsupported typeCode |
|
22 */ |
|
23 virtual TypeId toTypeId(const string_t typeCode) = 0; |
|
24 |
|
25 /** |
|
26 * @param typeId numeric type id as defined in Specification |
|
27 * @return string code of given type |
|
28 * @throws RelpipeWriterException on unsupported typeId |
|
29 */ |
|
30 virtual string_t toTypeCode(const TypeId typeId) = 0; |
|
31 |
|
32 /** |
|
33 * @param name name of the relation (table) |
|
34 * @param attributes list of attributes (columns) containing their names and types |
|
35 * @param writeHeader header might be omitted – when appending new records to a stream alreaready containing the header |
|
36 */ |
|
37 virtual void startRelation(string_t name, std::vector<std::pair<string_t, TypeId>> attributes, boolean_t writeHeader) = 0; |
|
38 |
|
39 /** |
|
40 * Writes a single attribute. |
|
41 * @param value string representation of value of given attribute type as defined in Specification |
|
42 */ |
|
43 virtual void writeAttribute(const string_t& value) = 0; |
|
44 |
|
45 // TODO: fluent interface? |
|
46 // TODO: << operator? |
|
47 // TODO: write bitmap + attribute: |
|
48 // virtual void writeBitmap(...) = 0; |
|
49 // virtual void writeAttribute(string_t attribute) = 0; |
|
50 |
|
51 /** |
|
52 * Writes a single attribute. |
|
53 * @param value raw pointer to the value in format of given attribute type as defined in Specification |
|
54 * @param type used as a safety mechanism to avoid wrong pointer interpretation; |
|
55 * should be called in this way: writeAttribute(&value, typeid(value)); |
|
56 * if the type does not match, the RelpipeWriterException is thrown |
|
57 */ |
|
58 virtual void writeAttribute(const void* value, const std::type_info& type) = 0; |
|
59 |
|
60 }; |
|
61 |
|
62 } |
|
63 } |