From e3fb3b9639ddb812b70826e2245d00933b893e08 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 12 Oct 2023 18:41:47 +0200 Subject: [PATCH] Base: add method XMLReader::isStartOfDocument() --- src/Base/Reader.cpp | 5 +++++ src/Base/Reader.h | 15 +++++++++------ tests/src/Base/Reader.cpp | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Base/Reader.cpp b/src/Base/Reader.cpp index 932d64aaa7..c33e5d091c 100644 --- a/src/Base/Reader.cpp +++ b/src/Base/Reader.cpp @@ -253,6 +253,11 @@ bool Base::XMLReader::isEndOfElement() const return (ReadType == EndElement); } +bool Base::XMLReader::isStartOfDocument() const +{ + return (ReadType == StartDocument); +} + bool Base::XMLReader::isEndOfDocument() const { return (ReadType == EndDocument); diff --git a/src/Base/Reader.h b/src/Base/Reader.h index 8ec9d466e8..2f8ed00b93 100644 --- a/src/Base/Reader.h +++ b/src/Base/Reader.h @@ -150,6 +150,9 @@ public: /// return true if the end of an element is reached, false otherwise bool isEndOfElement() const; + /// return true if the on the start of the document, false otherwise + bool isStartOfDocument() const; + /// return true if the end of the document is reached, false otherwise bool isEndOfDocument() const; @@ -241,11 +244,6 @@ public: bool testStatus(ReaderStatus pos) const; /// set the status bits void setStatus(ReaderStatus pos, bool on); - struct FileEntry { - std::string FileName; - Base::Persistence *Object; - }; - std::vector FileList; protected: /// read the next element @@ -287,7 +285,7 @@ protected: void resetErrors() override; //@} - +private: int Level{0}; std::string LocalName; std::string Characters; @@ -316,6 +314,11 @@ protected: bool _valid{false}; bool _verbose{true}; + struct FileEntry { + std::string FileName; + Base::Persistence *Object; + }; + std::vector FileList; std::vector FileNames; std::bitset<32> StatusBits; diff --git a/tests/src/Base/Reader.cpp b/tests/src/Base/Reader.cpp index ca26ba2dbf..04153c68bd 100644 --- a/tests/src/Base/Reader.cpp +++ b/tests/src/Base/Reader.cpp @@ -228,6 +228,7 @@ TEST_F(ReaderTest, readNextStartElement) givenDataAsXMLStream(xmlBody); // start of document + EXPECT_TRUE(Reader()->isStartOfDocument()); Reader()->readElement("document"); EXPECT_STREQ(Reader()->localName(), "document"); @@ -258,6 +259,7 @@ TEST_F(ReaderTest, readNextStartEndElement) givenDataAsXMLStream(xmlBody); // start of document + EXPECT_TRUE(Reader()->isStartOfDocument()); Reader()->readElement("document"); EXPECT_STREQ(Reader()->localName(), "document");