#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_STORAGE_XML_XMLBLOBREADER_H #define NUCLEX_STORAGE_XML_XMLBLOBREADER_H #include "Nuclex/Storage/Config.h" #include "Nuclex/Storage/Xml/XmlReader.h" #include namespace Nuclex { namespace Storage { // ------------------------------------------------------------------------------------------- // class Blob; // ------------------------------------------------------------------------------------------- // }} // namespace Nuclex::Storage namespace Nuclex { namespace Storage { namespace Xml { // ------------------------------------------------------------------------------------------- // /// Reads data from a chunk of XML plaintext class XmlBlobReader : public XmlReader { /// Initializes a new XML reader reading out of a blob /// Blob the XML reader will read out of public: NUCLEX_STORAGE_API XmlBlobReader(const std::shared_ptr &blob); /// Destroys the XML reader public: NUCLEX_STORAGE_API virtual ~XmlBlobReader(); /// Retrieves the currently selected binary data format /// The format in which binary data will be read public: NUCLEX_STORAGE_API XmlBinaryFormat GetBinaryFormat() const { return this->binaryFormat; } /// Selects the binary data format to use for reading binary data /// Format in which binary data will be read public: NUCLEX_STORAGE_API void SetBinaryFormat(XmlBinaryFormat newBinaryFormat) { this->binaryFormat = newBinaryFormat; } /// Reads from XML plaintext up until the next event is encountered /// The type of event encountered when parsing public: NUCLEX_STORAGE_API XmlReadEvent Read(); /// Retrieves the name of the last element that was entered or exited /// The name of the last element entered or exited public: NUCLEX_STORAGE_API const std::string &GetElementName() const; /// Counts the number of attributes in the current element /// The number of attributes present in the current element public: NUCLEX_STORAGE_API std::size_t CountAttributes() const; /// Retrieves the name of the attribute with the specified index /// Index of the attribue whose name will be looked up /// The name of the attribute with the specified index public: NUCLEX_STORAGE_API const std::string &GetAttributeName(std::size_t index) const; /// Try to enter the attribute with the specified name /// Name of the attribute that will be entered /// True if the attribute existed and was entered, otherwise false public: NUCLEX_STORAGE_API bool TryEnterAttribute(const std::string &attributeName); /// Leaves the currently entered attribute again public: NUCLEX_STORAGE_API void LeaveAttribute(); /// Reads a boolean from the stream /// Address of a boolean the value will be read into public: NUCLEX_STORAGE_API void Read(bool &target); /// Reads an unsigned 8 bit integer from the stream /// Address of an 8 bit integer the value will be read into public: NUCLEX_STORAGE_API void Read(std::uint8_t &target); /// Reads a signed 8 bit integer from the stream /// Address of an 8 bit integer the value will be read into public: NUCLEX_STORAGE_API void Read(std::int8_t &target); /// Reads an unsigned 16 bit integer from the stream /// Address of a 16 bit integer the value will be read into public: NUCLEX_STORAGE_API void Read(std::uint16_t &target); /// Reads a signed 16 bit integer from the stream /// Address of a 16 bit integer the value will be read into public: NUCLEX_STORAGE_API void Read(std::int16_t &target); /// Reads an unsigned 32 bit integer from the stream /// Address of a 32 bit integer the value will be read into public: NUCLEX_STORAGE_API void Read(std::uint32_t &target); /// Reads a signed 32 bit integer from the stream /// Address of a 32 bit integer the value will be read into public: NUCLEX_STORAGE_API void Read(std::int32_t &target); /// Reads an unsigned 64 bit integer from the stream /// Address of a 64 bit integer the value will be read into public: NUCLEX_STORAGE_API void Read(std::uint64_t &target); /// Reads a signed 64 bit integer from the stream /// Address of a 64 bit integer the value will be read into public: NUCLEX_STORAGE_API void Read(std::int64_t &target); /// Reads a floating point value from the stream /// Address of a floating point value that will be read into public: NUCLEX_STORAGE_API void Read(float &target); /// Reads a double precision floating point value from the stream /// /// Address of a double precision floating point value that will be read into /// public: NUCLEX_STORAGE_API void Read(double &target); /// Reads a string from the stream /// Address of a string the value will be read into public: NUCLEX_STORAGE_API void Read(std::string &target); /// Reads a unicode string from the stream /// Address of a unicode string the value will be read into public: NUCLEX_STORAGE_API void Read(std::wstring &target); /// Reads a chunk of bytes from the stream /// Buffer the bytes will be read into /// Number of bytes that will be read from the stream public: NUCLEX_STORAGE_API void Read(void *buffer, std::size_t byteCount); // Unhide the overloaded Read() methods in the base class // See http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9 using XmlReader::Read; /// Stores private implementation details private: class Impl; /// The blob being parsed private: std::shared_ptr blob; /// Implementation details private: std::unique_ptr impl; /// Binary data format currently used by the XML reader private: XmlBinaryFormat binaryFormat; /// Value of the attribute the reader has entered private: const std::string *enteredAttribute; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Storage::Xml #endif // NUCLEX_STORAGE_XML_XMLBLOBREADER_H