| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
/*************************************************************************** |
| 4 |
* Copyright (c) 2011 Jürgen Riegel <[email protected]> * |
| 5 |
* * |
| 6 |
* This file is part of the FreeCAD CAx development system. * |
| 7 |
* * |
| 8 |
* This library is free software; you can redistribute it and/or * |
| 9 |
* modify it under the terms of the GNU Library General Public * |
| 10 |
* License as published by the Free Software Foundation; either * |
| 11 |
* version 2 of the License, or (at your option) any later version. * |
| 12 |
* * |
| 13 |
* This library is distributed in the hope that it will be useful, * |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 16 |
* GNU Library General Public License for more details. * |
| 17 |
* * |
| 18 |
* You should have received a copy of the GNU Library General Public * |
| 19 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 20 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 21 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 22 |
* * |
| 23 |
***************************************************************************/ |
| 24 |
|
| 25 |
#ifndef BASE_IINPUTSOURCE_H |
| 26 |
#define BASE_IINPUTSOURCE_H |
| 27 |
|
| 28 |
#include <iosfwd> |
| 29 |
#include <memory> |
| 30 |
|
| 31 |
#include <xercesc/util/BinInputStream.hpp> |
| 32 |
#include <xercesc/sax/InputSource.hpp> |
| 33 |
#ifndef FC_GLOBAL_H |
| 34 |
# include <FCGlobal.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
#ifndef XERCES_CPP_NAMESPACE_BEGIN |
| 38 |
# define XERCES_CPP_NAMESPACE_QUALIFIER |
| 39 |
namespace XERCES_CPP_NAMESPACE |
| 40 |
{ |
| 41 |
class BinInputStream; |
| 42 |
} |
| 43 |
#else |
| 44 |
XERCES_CPP_NAMESPACE_BEGIN |
| 45 |
class BinInputStream; |
| 46 |
XERCES_CPP_NAMESPACE_END |
| 47 |
#endif |
| 48 |
|
| 49 |
namespace Base |
| 50 |
{ |
| 51 |
|
| 52 |
|
| 53 |
class BaseExport StdInputStream: public XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream |
| 54 |
{ |
| 55 |
public: |
| 56 |
// clang-format off |
| 57 |
explicit StdInputStream(std::istream& Stream, |
| 58 |
XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* const manager = |
| 59 |
XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager); |
| 60 |
~StdInputStream() override; |
| 61 |
// clang-format on |
| 62 |
|
| 63 |
// ----------------------------------------------------------------------- |
| 64 |
// Implementation of the input stream interface |
| 65 |
// ----------------------------------------------------------------------- |
| 66 |
XMLFilePos curPos() const override; |
| 67 |
XMLSize_t readBytes(XMLByte* const toFill, const XMLSize_t maxToRead) override; |
| 68 |
const XMLCh* getContentType() const override |
| 69 |
{ |
| 70 |
return nullptr; |
| 71 |
} |
| 72 |
|
| 73 |
// ----------------------------------------------------------------------- |
| 74 |
// Unimplemented constructors and operators |
| 75 |
// ----------------------------------------------------------------------- |
| 76 |
StdInputStream(const StdInputStream&) = delete; |
| 77 |
StdInputStream(StdInputStream&&) = delete; |
| 78 |
StdInputStream& operator=(const StdInputStream&) = delete; |
| 79 |
StdInputStream& operator=(StdInputStream&&) = delete; |
| 80 |
|
| 81 |
private: |
| 82 |
// ----------------------------------------------------------------------- |
| 83 |
// Private data members |
| 84 |
// |
| 85 |
// fSource |
| 86 |
// The source file that we represent. The FileHandle type is defined |
| 87 |
// per platform. |
| 88 |
// ----------------------------------------------------------------------- |
| 89 |
std::istream& stream; |
| 90 |
struct TextCodec; |
| 91 |
std::unique_ptr<TextCodec> codec; |
| 92 |
}; |
| 93 |
|
| 94 |
|
| 95 |
class BaseExport StdInputSource: public XERCES_CPP_NAMESPACE_QUALIFIER InputSource |
| 96 |
{ |
| 97 |
public: |
| 98 |
StdInputSource( |
| 99 |
std::istream& Stream, |
| 100 |
const char* filePath, |
| 101 |
XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* const manager |
| 102 |
= XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager |
| 103 |
); |
| 104 |
~StdInputSource() override; |
| 105 |
|
| 106 |
XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream* makeStream() const override; |
| 107 |
|
| 108 |
StdInputSource(const StdInputSource&) = delete; |
| 109 |
StdInputSource(StdInputSource&&) = delete; |
| 110 |
StdInputSource& operator=(const StdInputSource&) = delete; |
| 111 |
StdInputSource& operator=(StdInputSource&&) = delete; |
| 112 |
|
| 113 |
private: |
| 114 |
std::istream& stream; |
| 115 |
}; |
| 116 |
|
| 117 |
} // namespace Base |
| 118 |
|
| 119 |
#endif // BASE_IINPUTSOURCE_H |