src/DataTypeWriterBase.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 25 Aug 2018 18:21:09 +0200
branchv_0
changeset 25 135ef93a4ac2
parent 20 bef6648e79b1
child 29 142bdbba520f
permissions -rw-r--r--
imports, namespaces
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#pragma once
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#include <string>
25
135ef93a4ac2 imports, namespaces
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
     4
#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
     5
#include "../include/relpipe/writer/typedefs.h"
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
namespace relpipe {
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
namespace writer {
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
/**
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * 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
    12
 */
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
class DataTypeWriterBase {
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
private:
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    15
	const TypeId typeId;
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
	const string_t typeCode;
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
public:
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    19
	DataTypeWriterBase(const TypeId typeId, const string_t typeCode) :
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	typeId(typeId), typeCode(typeCode) {
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	}
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
	virtual ~DataTypeWriterBase() {
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
	};
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
4
e6db28447957 documentation for readString() and writeString() methods
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    26
	/**
e6db28447957 documentation for readString() and writeString() methods
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    27
	 * @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
    28
	 * @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
    29
	 * 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
    30
	 * 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
    31
	 * 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
    32
	 */
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	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
    34
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	/**
16
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    36
	 * @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
    37
	 * @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
    38
	 * @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
    39
	 * 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
    40
	 * 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
    41
	 * 
98b901d7bb95 ASan: add AddressSanitizer g++ option: -fsanitize=address
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    42
	 * 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
    43
	 */
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    44
	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
    45
3613617d3076 writeAttribute() with raw pointer and type_info
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    46
	/**
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
	 * @param dataType data type code as defined in DDP L0
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	 * @return whether this class supports conversions of this type
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	 */
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    50
	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
    51
		return dataType == typeId;
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    52
	}
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
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
	 * @param dataType data type name as defined in DDP L0
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
	 * @return whether this class supports conversions of this type
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
	 */
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    58
	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
    59
		return dataType == typeCode;
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    60
	}
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
15
8fd6c4d44071 use more TypeId enum
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    62
	TypeId getTypeId() {
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    63
		return typeId;
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    64
	}
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    66
	string_t getTypeCode() {
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    67
		return typeCode;
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    68
	}
1
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
};
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
6e3494943c91 base classes
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
}
9
0a40752e401d shared library with pure abstract class (interface)
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    72
}