src/StreamInputSource.h
author František Kučera <franta-hg@frantovo.cz>
Tue, 22 Oct 2019 19:53:12 +0200
branchv_0
changeset 15 177321664baf
parent 2 3ab78bf63467
permissions -rw-r--r--
fix license version: GNU GPLv3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info)
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
15
177321664baf fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
2
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <istream>
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <xercesc/sax/InputSource.hpp>
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <xercesc/util/PlatformUtils.hpp>
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <xercesc/util/BinInputStream.hpp>
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
namespace relpipe {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
namespace in {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace xml {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
class StreamInputSource : public xercesc::InputSource {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
private:
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	std::istream& input;
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	class StreamBinInputStream : public xercesc::BinInputStream {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	private:
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		std::istream& input;
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	public:
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
		StreamBinInputStream(std::istream& input) : BinInputStream(), input(input) {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		}
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		XMLFilePos curPos() const override {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
			return input.tellg();
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		}
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		const XMLCh* getContentType() const override {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
			return nullptr;
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		}
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		XMLSize_t readBytes(XMLByte * const toFill, const XMLSize_t maxToRead) override {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
			input.read((char*) toFill, maxToRead);
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
			return input.gcount();
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		}
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	};
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
public:
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
	StreamInputSource(std::istream& input, xercesc::MemoryManager * const manager = xercesc::XMLPlatformUtils::fgMemoryManager) : InputSource(manager), input(input) {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	}
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	virtual ~StreamInputSource() {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	}
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
	xercesc::BinInputStream* makeStream() const override {
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		// TODO: avoid multiple calls, input can be used only once 
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		return new StreamBinInputStream(input);
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
	}
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
};
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
}
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
}
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
}