Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2002-2024 German Aerospace Center (DLR) and others. 4 : // This program and the accompanying materials are made available under the 5 : // terms of the Eclipse Public License 2.0 which is available at 6 : // https://www.eclipse.org/legal/epl-2.0/ 7 : // This Source Code may also be made available under the following Secondary 8 : // Licenses when the conditions for such availability set forth in the Eclipse 9 : // Public License 2.0 are satisfied: GNU General Public License, version 2 10 : // or later which is available at 11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 : /****************************************************************************/ 14 : /// @file IStreamInputSource.h 15 : /// @author Michael Behrisch 16 : /// @author Gilles Filippini 17 : /// @date Sept 2002 18 : /// 19 : // Xerces InputSource reading from arbitrary std::istream 20 : // reimplementation inspired by https://marc.info/?l=xerces-dev&m=86952133511623 21 : /****************************************************************************/ 22 : #pragma once 23 : #include <config.h> 24 : #include <iostream> 25 : #include <xercesc/util/BinInputStream.hpp> 26 : #include <xercesc/sax/InputSource.hpp> 27 : 28 : 29 : // =========================================================================== 30 : // class definitions 31 : // =========================================================================== 32 : /** 33 : * @class IStreamBinInputStream 34 : * @brief Xerces BinInputStream reading from arbitrary std::istream 35 : */ 36 : class IStreamBinInputStream : public XERCES_CPP_NAMESPACE::BinInputStream { 37 : public: 38 269556 : IStreamBinInputStream(std::istream& in) : myIn(in) { } 39 134741 : virtual ~IStreamBinInputStream(void) { } 40 0 : virtual XMLFilePos curPos(void) const { 41 0 : return myIn.tellg(); 42 : } 43 285905 : virtual XMLSize_t readBytes(XMLByte* const buf, const XMLSize_t max) { 44 285905 : myIn.read((char*)buf, max); 45 285905 : return (XMLSize_t)myIn.gcount(); 46 : } 47 0 : virtual const XMLCh* getContentType() const { 48 0 : return nullptr; 49 : } 50 : private: 51 : std::istream& myIn; 52 : }; 53 : 54 : 55 : /** 56 : * @class IStreamInputSource 57 : * @brief Xerces InputSource reading from arbitrary std::istream 58 : */ 59 : class IStreamInputSource : public XERCES_CPP_NAMESPACE::InputSource { 60 : public: 61 134778 : IStreamInputSource(std::istream& in) : 62 134778 : XERCES_CPP_NAMESPACE::InputSource("istream"), myIn(in) { } 63 134319 : virtual ~IStreamInputSource(void) { } 64 134778 : virtual XERCES_CPP_NAMESPACE::BinInputStream* makeStream(void) const { 65 134778 : return new IStreamBinInputStream(myIn); 66 : } 67 : private: 68 : std::istream& myIn; 69 : };