author | František Kučera <franta-hg@frantovo.cz> |
Wed, 19 Dec 2018 23:10:19 +0100 | |
branch | v_0 |
changeset 33 | c0e445dda2c5 |
parent 30 | 3f18cb7a6963 |
child 41 | 744b61559eb2 |
permissions | -rw-r--r-- |
29
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
1 |
/** |
30
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
2 |
* Relational pipes (library) |
29
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
3 |
* Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
4 |
* |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
30
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
6 |
* it under the terms of the: |
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
7 |
* - GNU Lesser General Public License as published by the Free Software Foundation; |
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
8 |
* either version 3 of the License, or (at your option) any later version; |
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
9 |
* or (at your option) |
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
10 |
* - GNU General Public License as published by the Free Software Foundation; |
3f18cb7a6963
license of protocol, reader and writer: GNU LGPLv3+ or GNU GPLv2+
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
11 |
* either version 2 of the License, or (at your option) any later version. |
29
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
12 |
* |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
13 |
* This program is distributed in the hope that it will be useful, |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
16 |
* GNU General Public License for more details. |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
17 |
* |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
142bdbba520f
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
27
diff
changeset
|
20 |
*/ |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#pragma once |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
#include <iostream> |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
#include <vector> |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
|
13
e7234dd45166
use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
26 |
#include "typedefs.h" |
e7234dd45166
use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
27 |
#include "TypeId.h" |
27
a64afb2d24c9
use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
28 |
#include "AttributeMetadata.h" |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
|
8
03750aff8619
writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
30 |
namespace relpipe { |
03750aff8619
writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
31 |
namespace writer { |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
|
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
33 |
class RelationalWriter { |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
public: |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
|
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
36 |
virtual ~RelationalWriter() = default; |
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
37 |
|
18
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
38 |
/** |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
39 |
* @param typeCode string type code as defined in Specification |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
40 |
* @return numeric id of given type |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
41 |
* @throws RelpipeWriterException on unsupported typeCode |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
42 |
*/ |
15
8fd6c4d44071
use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
43 |
virtual TypeId toTypeId(const string_t typeCode) = 0; |
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
44 |
|
18
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
45 |
/** |
22 | 46 |
* TODO: use custom extensible class instead of std::pair |
47 |
* |
|
18
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
48 |
* @param name name of the relation (table) |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
49 |
* @param attributes list of attributes (columns) containing their names and types |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
50 |
* @param writeHeader header might be omitted – when appending new records to a stream alreaready containing the header |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
51 |
*/ |
27
a64afb2d24c9
use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
52 |
virtual void startRelation(string_t name, std::vector<AttributeMetadata> attributes, boolean_t writeHeader) = 0; |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
|
18
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
54 |
/** |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
55 |
* Writes a single attribute. |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
56 |
* @param value string representation of value of given attribute type as defined in Specification |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
57 |
*/ |
17
f2cccaa9dd38
replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
58 |
virtual void writeAttribute(const string_t& value) = 0; |
f2cccaa9dd38
replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
59 |
|
f2cccaa9dd38
replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
60 |
// TODO: fluent interface? |
f2cccaa9dd38
replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
61 |
// TODO: << operator? |
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
62 |
// TODO: write bitmap + attribute: |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
63 |
// virtual void writeBitmap(...) = 0; |
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
64 |
// virtual void writeAttribute(string_t attribute) = 0; |
17
f2cccaa9dd38
replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
65 |
|
18
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
66 |
/** |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
67 |
* Writes a single attribute. |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
68 |
* @param value raw pointer to the value in format of given attribute type as defined in Specification |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
69 |
* @param type used as a safety mechanism to avoid wrong pointer interpretation; |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
70 |
* should be called in this way: writeAttribute(&value, typeid(value)); |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
71 |
* if the type does not match, the RelpipeWriterException is thrown |
90efe2db1ca8
documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents:
17
diff
changeset
|
72 |
*/ |
16
3613617d3076
writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
73 |
virtual void writeAttribute(const void* value, const std::type_info& type) = 0; |
7
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
74 |
|
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
75 |
}; |
01dd90eeedbb
add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
|
8
03750aff8619
writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
77 |
} |
9
0a40752e401d
shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
78 |
} |