src/DataTypeReaderBase.h
author František Kučera <franta-hg@frantovo.cz>
Thu, 29 Nov 2018 22:30:12 +0100
branchv_0
changeset 29 755978b0935c
parent 18 e11f1ad20826
child 30 ef99f5a6c9f6
permissions -rw-r--r--
license: GNU GPLv3+
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     1
/**
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     2
 * Relational pipes
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     3
 * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info)
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     4
 *
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     8
 * (at your option) any later version.
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     9
 *
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    13
 * GNU General Public License for more details.
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    14
 *
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    15
 * You should have received a copy of the GNU General Public License
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    17
 */
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#pragma once
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <string>
18
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    21
#include <functional>
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    22
#include "../include/relpipe/reader/TypeId.h"
13
543f1613c2da move non-public headers from include to src
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    23
#include "../include/relpipe/reader/typedefs.h"
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
namespace relpipe {
4
da021e58c946 rename 'writer' namespace to 'reader'
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    26
namespace reader {
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
/**
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
 * This class contains common features that are independent from particular data type (generic/template type)
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
 */
2
fc3a84a62dd9 rename writers to readers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    31
class DataTypeReaderBase {
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
private:
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    33
	const TypeId typeId;
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	const string_t typeCode;
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
public:
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    37
	DataTypeReaderBase(const TypeId typeId, const string_t typeCode) :
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	typeId(typeId), typeCode(typeCode) {
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	}
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
2
fc3a84a62dd9 rename writers to readers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    41
	virtual ~DataTypeReaderBase() {
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	};
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	/**
18
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    45
	 * TODO: delete, use handler?
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    46
	 * 
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
	 * @param input input stream, should be at position where the value is to be read; the stream will not be closed afred reading
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	 * @return read value in form of the string representation of given data type.
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	 * E.g. integer 123 is returned as a character string "123",
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	 * boolean true is returned as a character string "true".
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	 * See Relational pipes format specification for details.
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	 */
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	virtual string_t readString(std::istream &input) = 0;
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	/**
18
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    56
	 * The value is read from the input and then passed to the handler.
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    57
	 * 
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    58
	 * @param input
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    59
	 * @param handler
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    60
	 */
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    61
	virtual void read(std::istream &input, std::function<void(const void *, const std::type_info&) > handler) = 0;
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    62
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    63
	/**
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    64
	 * TODO: documentation
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    65
	 * 
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    66
	 * @param input
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    67
	 * @param handler
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    68
	 */
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    69
	virtual void read(std::istream &input, std::function<void(const string_t&, const void *, const std::type_info&) > handler) = 0;
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    70
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    71
	/**
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
	 * @param dataType data type code as defined in DDP L0
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
	 * @return whether this class supports conversions of this type
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
	 */
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    75
	virtual bool supports(const TypeId &dataType) {
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    76
		return dataType == typeId;
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    77
	}
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
	/**
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
	 * @param dataType data type name as defined in DDP L0
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
	 * @return whether this class supports conversions of this type
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
	 */
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    83
	virtual bool supports(const string_t &dataType) {
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    84
		return dataType == typeCode;
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    85
	}
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    87
	TypeId getTypeId() {
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    88
		return typeId;
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    89
	}
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    91
	string_t getTypeCode() {
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    92
		return typeCode;
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    93
	}
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
};
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
}
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
}