include/relpipe/writer/RelationalWriter.h
author František Kučera <franta-hg@frantovo.cz>
Tue, 22 Oct 2019 19:47:14 +0200
branchv_0
changeset 41 744b61559eb2
parent 30 3f18cb7a6963
child 59 4fce579bed22
permissions -rw-r--r--
fix license version: GNU LGPLv3 or GPLv2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
41
744b61559eb2 fix license version: GNU LGPLv3 or GPLv2
František Kučera <franta-hg@frantovo.cz>
parents: 30
diff changeset
     8
 *    version 3 of the License or (at your option)
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
     9
 *  - GNU General Public License as published by the Free Software Foundation;
41
744b61559eb2 fix license version: GNU LGPLv3 or GPLv2
František Kučera <franta-hg@frantovo.cz>
parents: 30
diff changeset
    10
 *    version 2 of the License.
29
142bdbba520f license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    11
 *
142bdbba520f license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    12
 * 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
    13
 * 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
    14
 * 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
    15
 * GNU General Public License for more details.
142bdbba520f license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    16
 *
142bdbba520f license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    17
 * 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
    18
 * 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
    19
 */
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#pragma once
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <iostream>
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <vector>
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
13
e7234dd45166 use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    25
#include "typedefs.h"
e7234dd45166 use TypeId enum instead of numeric constants
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    26
#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
    27
#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
    28
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    29
namespace relpipe {
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    30
namespace writer {
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    32
class RelationalWriter {
7
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
public:
01dd90eeedbb add data type and catalog classes from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    35
	virtual ~RelationalWriter() = default;
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    36
18
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    37
	/**
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    38
	 * @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
    39
	 * @return numeric id of given type
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    40
	 * @throws RelpipeWriterException on unsupported typeCode
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    41
	 */
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    42
	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
    43
18
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    44
	/**
22
53f4887dadb4 todo comments
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    45
	 * TODO: use custom extensible class instead of std::pair 
53f4887dadb4 todo comments
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    46
	 * 
18
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    47
	 * @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
    48
	 * @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
    49
	 * @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
    50
	 */
27
a64afb2d24c9 use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
    51
	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
    52
18
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    53
	/**
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    54
	 * Writes a single attribute.
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    55
	 * @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
    56
	 */
17
f2cccaa9dd38 replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    57
	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
    58
f2cccaa9dd38 replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    59
	// TODO: fluent interface?
f2cccaa9dd38 replace writeRecord() with sequence of writeAttribute()
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    60
	// TODO: << operator?
16
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    61
	// TODO: write bitmap + attribute:
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    62
	// virtual void writeBitmap(...) = 0;
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    63
	// 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
    64
18
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    65
	/**
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    66
	 * Writes a single attribute.
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
    67
	 * @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
    68
	 * @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
    69
	 * 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
    70
	 * 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
    71
	 */
16
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    72
	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
    73
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
8
03750aff8619 writer only writes + refactoring
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    76
}
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    77
}