src/DataTypeReader.h
author František Kučera <franta-hg@frantovo.cz>
Tue, 22 Oct 2019 19:45:24 +0200
branchv_0
changeset 42 3442e0d6caec
parent 30 ef99f5a6c9f6
permissions -rw-r--r--
fix license version: GNU LGPLv3 or GPLv2
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
/**
30
ef99f5a6c9f6 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
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
30
ef99f5a6c9f6 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:
ef99f5a6c9f6 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;
42
3442e0d6caec 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
ef99f5a6c9f6 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;
42
3442e0d6caec 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
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    11
 *
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    12
 * 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
    13
 * 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
    14
 * 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
    15
 * GNU General Public License for more details.
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    16
 *
755978b0935c license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    17
 * 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
    18
 * 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
    19
 */
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#pragma once
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
18
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    22
#include <sstream>
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    23
#include <functional>
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    24
2
fc3a84a62dd9 rename writers to readers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    25
#include "DataTypeReaderBase.h"
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace relpipe {
4
da021e58c946 rename 'writer' namespace to 'reader'
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    28
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
    29
2
fc3a84a62dd9 rename writers to readers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    30
template<typename T> class DataTypeReader : public DataTypeReaderBase {
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
public:
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
14
e8de089f95dd refactoring, move files, use TypeId instead of integer_t
František Kučera <franta-hg@frantovo.cz>
parents: 13
diff changeset
    33
	DataTypeReader(const TypeId typeId, const string_t typeCode) : DataTypeReaderBase(typeId, typeCode) {
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	}
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
2
fc3a84a62dd9 rename writers to readers
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    36
	virtual ~DataTypeReader() {
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	};
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	virtual T readValue(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
    40
15
09ca53671b28 remove DataTypeReader.cpp (move implementation to DataTypeReader.h)
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    41
	virtual string_t readString(std::istream &input) {
09ca53671b28 remove DataTypeReader.cpp (move implementation to DataTypeReader.h)
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    42
		return toString(readValue(input));
09ca53671b28 remove DataTypeReader.cpp (move implementation to DataTypeReader.h)
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    43
	}
1
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: 15
diff changeset
    45
	virtual void read(std::istream &input, std::function<void(const void *, const std::type_info&) > handler) override {
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    46
		T value = readValue(input);
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    47
		handler(&value, typeid (T));
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    48
	}
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    49
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    50
	virtual void read(std::istream &input, std::function<void(const string_t&, const void *, const std::type_info&) > handler) override {
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    51
		T value = readValue(input);
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    52
		handler(toString(value), &value, typeid (T));
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    53
	}
e11f1ad20826 read using std::function
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    54
1
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	virtual string_t toString(const T& value) = 0;
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
};
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
}
c80d55cdb42d copy of .cpp and .h from relpipe-lib-writer.cpp
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
}