From 238ca0cef98d54d9b3d33445aecd0b952a45773f Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 26 Nov 2015 14:26:16 +0100 Subject: [PATCH] added methods to buffer elements --- genericfileelement.h | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/genericfileelement.h b/genericfileelement.h index e4c8720..d267a0e 100644 --- a/genericfileelement.h +++ b/genericfileelement.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -27,7 +28,6 @@ namespace Media { template class GenericFileElement; - /*! * \class Media::FileElementIterator * \brief The FileElementIterator class helps iterating through the childs of a FileElement. @@ -191,6 +191,10 @@ public: void copyHeader(std::ostream &targetStream); void copyWithoutChilds(std::ostream &targetStream); void copyEntirely(std::ostream &targetStream); + void makeBuffer(); + void releaseBuffer(); + void copyBuffer(std::ostream &targetStream); + const std::unique_ptr &buffer(); implementationType *denoteFirstChild(uint32 offset); protected: @@ -202,6 +206,7 @@ protected: implementationType* m_parent; std::unique_ptr m_nextSibling; std::unique_ptr m_firstChild; + std::unique_ptr m_buffer; private: void copyInternal(std::ostream &targetStream, uint64 startOffset, uint64 bytesToCopy); @@ -767,7 +772,7 @@ void GenericFileElement::validateSubsequentElementStructure( parse(); gatheredNotifications.insert(gatheredNotifications.end(), notifications().begin(), notifications().end()); if(firstChild()) { // element is parent - firstChild()->validateSubsequentElementStructure(gatheredNotifications); + firstChild()->validateSubsequentElementStructure(gatheredNotifications, paddingSize); } else if(paddingSize && isPadding()) { // element is padding *paddingSize += totalSize(); } @@ -811,6 +816,32 @@ void GenericFileElement::copyEntirely(std::ostream &targetSt copyInternal(targetStream, startOffset(), totalSize()); } +template +void GenericFileElement::makeBuffer() +{ + m_buffer = std::make_unique(totalSize()); + container().stream().seekg(startOffset()); + container().stream().read(m_buffer.get(), totalSize()); +} + +template +inline void GenericFileElement::releaseBuffer() +{ + m_buffer.release(); +} + +template +inline void GenericFileElement::copyBuffer(std::ostream &targetStream) +{ + targetStream.write(m_buffer.get(), totalSize()); +} + +template +inline const std::unique_ptr &GenericFileElement::buffer() +{ + return m_buffer; +} + /*! * \brief Internally used to perform copies of the atom. *