src/DataTypeWriterBase.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 01 Dec 2018 15:35:05 +0100
branchv_0
changeset 30 3f18cb7a6963
parent 29 142bdbba520f
child 41 744b61559eb2
permissions -rw-r--r--
license of protocol, reader and writer: GNU LGPLv3+ or GNU 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: 25
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: 25
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: 25
diff changeset
     4
 *
142bdbba520f license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 25
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: 25
diff changeset
    12
 *
142bdbba520f license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 25
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: 25
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: 25
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: 25
diff changeset
    16
 * GNU General Public License for more details.
142bdbba520f license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 25
diff changeset
    17
 *
142bdbba520f license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 25
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: 25
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: 25
diff changeset
    20
 */
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#pragma once
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <string>
25
135ef93a4ac2 imports, namespaces
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    24
#include "../include/relpipe/writer/TypeId.h"
20
bef6648e79b1 relpipe-lib-writer: move public header files to: include/relpipe/writer/
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    25
#include "../include/relpipe/writer/typedefs.h"
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace relpipe {
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace writer {
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
/**
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
 * This class contains common features that are independent from particular data type (generic/template type)
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
 */
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
class DataTypeWriterBase {
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
private:
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    35
	const TypeId typeId;
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	const string_t typeCode;
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
public:
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    39
	DataTypeWriterBase(const TypeId typeId, const string_t typeCode) :
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	typeId(typeId), typeCode(typeCode) {
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	}
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	virtual ~DataTypeWriterBase() {
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	};
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
4
e6db28447957 documentation for readString() and writeString() methods
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    46
	/**
e6db28447957 documentation for readString() and writeString() methods
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    47
	 * @param output output stream, should be at position where the value is to be written; the stream will not be closed not flushed after writing
e6db28447957 documentation for readString() and writeString() methods
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    48
	 * @param stringValue write value as given data type (e.g. integer or boolean); stringValue parameter contains given value in string representation of given data type
e6db28447957 documentation for readString() and writeString() methods
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    49
	 * E.g. integer 123 is passed as a character string "123"
e6db28447957 documentation for readString() and writeString() methods
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    50
	 * boolean true is passed as a character string "true".
e6db28447957 documentation for readString() and writeString() methods
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    51
	 * See Relational pipes format specification for details.
e6db28447957 documentation for readString() and writeString() methods
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    52
	 */
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	virtual void writeString(std::ostream& output, const string_t &stringValue) = 0;
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	/**
16
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    56
	 * @param output output stream, should be at position where the value is to be written; the stream will not be closed not flushed after writing
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    57
	 * @param value raw pointer to the value, must exactly match data type of this writer
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    58
	 * @param type used as a safety mechanism to avoid wrong pointer interpretation;
18
90efe2db1ca8 documentation for RelationalWriter and DataTypeWriterBase
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    59
	 * should be called in this way: writeRaw(output, &value, typeid(value));
16
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    60
	 * if the type does not match, the RelpipeWriterException is thrown
19
98b901d7bb95 ASan: add AddressSanitizer g++ option: -fsanitize=address
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    61
	 * 
98b901d7bb95 ASan: add AddressSanitizer g++ option: -fsanitize=address
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    62
	 * TODO: typeid() / type_info seems working but consider also sizeof() / size_t and teplates
16
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    63
	 */
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    64
	virtual void writeRaw(std::ostream& output, const void * value, const std::type_info& type) = 0;
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    65
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    66
	/**
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
	 * @param dataType data type code as defined in DDP L0
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
	 * @return whether this class supports conversions of this type
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
	 */
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    70
	virtual bool supports(const TypeId &dataType) {
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    71
		return dataType == typeId;
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    72
	}
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
	/**
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
	 * @param dataType data type name as defined in DDP L0
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
	 * @return whether this class supports conversions of this type
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
	 */
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    78
	virtual bool supports(const string_t &dataType) {
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    79
		return dataType == typeCode;
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    80
	}
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    82
	TypeId getTypeId() {
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    83
		return typeId;
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    84
	}
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    86
	string_t getTypeCode() {
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    87
		return typeCode;
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    88
	}
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
};
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
}
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    92
}