diff --git a/ebml/EbmlBinary.h b/ebml/EbmlBinary.h index 74a49a61..ed67face 100644 --- a/ebml/EbmlBinary.h +++ b/ebml/EbmlBinary.h @@ -32,9 +32,9 @@ class EBML_DLL_API EbmlBinary : public EbmlElement { bool ValidateSize() const override {return IsFiniteSize() && GetSize() < 0x7FFFFFFF;} // we don't mind about what's inside - filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; + filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) override; filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) override; - filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override; + filepos_t UpdateSize(ShouldWrite writeFilter = WriteSkipDefault, bool bForceRender = false) override; void SetBuffer(const binary *Buffer, const std::uint32_t BufferSize) { Data = const_cast(Buffer); diff --git a/ebml/EbmlCrc32.h b/ebml/EbmlCrc32.h index e367ab52..12af3314 100644 --- a/ebml/EbmlCrc32.h +++ b/ebml/EbmlCrc32.h @@ -20,9 +20,9 @@ namespace libebml { DECLARE_EBML_BINARY(EbmlCrc32) public: bool ValidateSize() const override {return IsFiniteSize() && (GetSize() == 4);} - filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; + filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) override; filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) override; -// filepos_t UpdateSize(bool bWithDefault = false); +// filepos_t UpdateSize(ShouldWrite writeFilter = WriteSkipDefault); bool IsDefaultValue() const override { return false; diff --git a/ebml/EbmlDate.h b/ebml/EbmlDate.h index efcf02f7..f341770f 100644 --- a/ebml/EbmlDate.h +++ b/ebml/EbmlDate.h @@ -40,7 +40,7 @@ class EBML_DLL_API EbmlDate : public EbmlElement { /*! \note no Default date handled */ - filepos_t UpdateSize(bool /* bWithDefault = false */, bool /* bForceRender = false */) override { + filepos_t UpdateSize(ShouldWrite /* writeFilter */, bool /* bForceRender = false */) override { if(!ValueIsSet()) SetSize_(0); else @@ -57,7 +57,7 @@ class EBML_DLL_API EbmlDate : public EbmlElement { } private: - filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; + filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) override; std::int64_t myDate{0}; ///< internal format of the date diff --git a/ebml/EbmlElement.h b/ebml/EbmlElement.h index bacaf7f1..af822a4b 100644 --- a/ebml/EbmlElement.h +++ b/ebml/EbmlElement.h @@ -280,6 +280,21 @@ class EBML_DLL_API EbmlSemanticContext { */ class EBML_DLL_API EbmlElement { public: + // callback to tell if the element should be written or not + // \return true if the element should be written + using ShouldWrite = bool (*)(const EbmlElement &); + + // write only elements that don't have their default value set + static bool WriteSkipDefault(const EbmlElement &elt) { + if (elt.IsDefaultValue()) + return false; + return true; + } + + static bool WriteAll(const EbmlElement &elt) { + return true; + } + explicit EbmlElement(std::uint64_t aDefaultSize, bool bValueSet = false); virtual ~EbmlElement() = default; EbmlElement& operator=(const EbmlElement&) = delete; @@ -319,11 +334,11 @@ class EBML_DLL_API EbmlElement { return ElementPosition; } - std::uint64_t ElementSize(bool bWithDefault = false) const; /// return the size of the header+data, before writing + std::uint64_t ElementSize(ShouldWrite writeFilter = WriteSkipDefault) const; /// return the size of the header+data, before writing - filepos_t Render(IOCallback & output, bool bWithDefault = false, bool bKeepPosition = false, bool bForceRender = false); + filepos_t Render(IOCallback & output, ShouldWrite writeFilter = WriteSkipDefault, bool bKeepPosition = false, bool bForceRender = false); - virtual filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) = 0; /// update the Size of the Data stored + virtual filepos_t UpdateSize(ShouldWrite writeFilter = WriteSkipDefault, bool bForceRender = false) = 0; /// update the Size of the Data stored virtual filepos_t GetSize() const {return Size;} /// return the size of the data stored in the element, on reading virtual filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) = 0; @@ -354,7 +369,7 @@ class EBML_DLL_API EbmlElement { /*! \brief void the content of the element (replace by EbmlVoid) */ - std::uint64_t VoidMe(IOCallback & output, bool bWithDefault = false) const; + std::uint64_t VoidMe(IOCallback & output, ShouldWrite writeFilter = WriteSkipDefault) const; bool DefaultISset() const {return DefaultIsSet;} void ForceNoDefault() {SetDefaultIsSet(false);} @@ -380,13 +395,13 @@ class EBML_DLL_API EbmlElement { */ static EbmlElement *CreateElementUsingContext(const EbmlId & aID, const EbmlSemanticContext & Context, int & LowLevel, bool IsGlobalContext, bool bAllowDummy = false, unsigned int MaxLowerLevel = 1); - filepos_t RenderHead(IOCallback & output, bool bForceRender, bool bWithDefault = false, bool bKeepPosition = false); + filepos_t RenderHead(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault, bool bKeepPosition = false); filepos_t MakeRenderHead(IOCallback & output, bool bKeepPosition); /*! \brief prepare the data before writing them (in case it's not already done by default) */ - virtual filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) = 0; + virtual filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) = 0; /*! \brief special constructor for cloning @@ -413,4 +428,6 @@ class EBML_DLL_API EbmlElement { } // namespace libebml +#define EBML_WRITE_FILTER 1 + #endif // LIBEBML_ELEMENT_H diff --git a/ebml/EbmlFloat.h b/ebml/EbmlFloat.h index 6e3013e0..97dc6eb7 100644 --- a/ebml/EbmlFloat.h +++ b/ebml/EbmlFloat.h @@ -32,9 +32,9 @@ class EBML_DLL_API EbmlFloat : public EbmlElement { return (GetSize() == 4 || GetSize() == 8); } - filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; + filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) override; filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) override; - filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override; + filepos_t UpdateSize(ShouldWrite writeFilter = WriteSkipDefault, bool bForceRender = false) override; void SetPrecision(const EbmlFloat::Precision prec = FLOAT_32) { diff --git a/ebml/EbmlMaster.h b/ebml/EbmlMaster.h index 0b29093e..ce4d5029 100644 --- a/ebml/EbmlMaster.h +++ b/ebml/EbmlMaster.h @@ -39,9 +39,9 @@ class EBML_DLL_API EbmlMaster : public EbmlElement { */ ~EbmlMaster() override; - filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; + filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) override; filepos_t ReadData(IOCallback & input, ScopeMode ReadFully) override; - filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override; + filepos_t UpdateSize(ShouldWrite writeFilter = WriteSkipDefault, bool bForceRender = false) override; /*! \brief Set wether the size is finite (size is known in advance when writing, or infinite size is not known on writing) @@ -134,7 +134,7 @@ class EBML_DLL_API EbmlMaster : public EbmlElement { /*! \brief facility for Master elements to write only the head and force the size later */ - filepos_t WriteHead(IOCallback & output, int SizeLength, bool bWithDefault = false); + filepos_t WriteHead(IOCallback & output, int SizeLength, ShouldWrite writeFilter = WriteSkipDefault); void EnableChecksum(bool bIsEnabled = true) { bChecksumUsed = bIsEnabled; } bool HasChecksum() const {return bChecksumUsed;} diff --git a/ebml/EbmlSInteger.h b/ebml/EbmlSInteger.h index b3b76ff7..9695bd44 100644 --- a/ebml/EbmlSInteger.h +++ b/ebml/EbmlSInteger.h @@ -36,9 +36,9 @@ class EBML_DLL_API EbmlSInteger : public EbmlElement { void SetDefaultSize(std::uint64_t nDefaultSize = DEFAULT_INT_SIZE) override {EbmlElement::SetDefaultSize(nDefaultSize); SetSize_(nDefaultSize);} bool ValidateSize() const override {return IsFiniteSize() && (GetSize() <= 8);} - filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; + filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) override; filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) override; - filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override; + filepos_t UpdateSize(ShouldWrite writeFilter = WriteSkipDefault, bool bForceRender = false) override; bool IsSmallerThan(const EbmlElement *Cmp) const override; diff --git a/ebml/EbmlString.h b/ebml/EbmlString.h index 78c0518e..d8316933 100644 --- a/ebml/EbmlString.h +++ b/ebml/EbmlString.h @@ -25,9 +25,9 @@ class EBML_DLL_API EbmlString : public EbmlElement { explicit EbmlString(const std::string & aDefaultValue); bool ValidateSize() const override {return IsFiniteSize() && GetSize() < 0x7FFFFFFF;} // any size is possible - filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; + filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) override; filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) override; - filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override; + filepos_t UpdateSize(ShouldWrite writeFilter = WriteSkipDefault, bool bForceRender = false) override; EbmlString & operator=(const std::string &); using EbmlElement::operator const EbmlId &; diff --git a/ebml/EbmlUInteger.h b/ebml/EbmlUInteger.h index bdab3da4..fc4e82ff 100644 --- a/ebml/EbmlUInteger.h +++ b/ebml/EbmlUInteger.h @@ -34,9 +34,9 @@ class EBML_DLL_API EbmlUInteger : public EbmlElement { void SetDefaultSize(std::uint64_t nDefaultSize = DEFAULT_UINT_SIZE) override {EbmlElement::SetDefaultSize(nDefaultSize); SetSize_(nDefaultSize);} bool ValidateSize() const override {return IsFiniteSize() && (GetSize() <= 8);} - filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; + filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) override; filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) override; - filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override; + filepos_t UpdateSize(ShouldWrite writeFilter = WriteSkipDefault, bool bForceRender = false) override; bool IsSmallerThan(const EbmlElement *Cmp) const override; diff --git a/ebml/EbmlUnicodeString.h b/ebml/EbmlUnicodeString.h index 8e601c2d..85a6340a 100644 --- a/ebml/EbmlUnicodeString.h +++ b/ebml/EbmlUnicodeString.h @@ -71,9 +71,9 @@ class EBML_DLL_API EbmlUnicodeString : public EbmlElement { explicit EbmlUnicodeString(const UTFstring & DefaultValue); bool ValidateSize() const override {return IsFiniteSize();} // any size is possible - filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; + filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) override; filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) override; - filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override; + filepos_t UpdateSize(ShouldWrite writeFilter = WriteSkipDefault, bool bForceRender = false) override; EbmlUnicodeString & operator=(const UTFstring &); ///< platform dependant code using EbmlElement::operator const EbmlId &; diff --git a/ebml/EbmlVoid.h b/ebml/EbmlVoid.h index 888a6a90..0a4fe0d4 100644 --- a/ebml/EbmlVoid.h +++ b/ebml/EbmlVoid.h @@ -23,17 +23,17 @@ DECLARE_EBML_BINARY(EbmlVoid) /*! \note overwrite to write fake data */ - filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; + filepos_t RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter = WriteSkipDefault) override; /*! \brief Replace the void element content (written) with this one */ - std::uint64_t ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output, bool ComeBackAfterward = true, bool bWithDefault = false); + std::uint64_t ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output, bool ComeBackAfterward = true, ShouldWrite writeFilter = WriteSkipDefault); /*! \brief Void the content of an element */ - std::uint64_t Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward = true, bool bWithDefault = false); + std::uint64_t Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward = true, ShouldWrite writeFilter = WriteSkipDefault); EBML_CONCRETE_CLASS(EbmlVoid) }; diff --git a/src/EbmlBinary.cpp b/src/EbmlBinary.cpp index 39134330..68c0b889 100644 --- a/src/EbmlBinary.cpp +++ b/src/EbmlBinary.cpp @@ -50,7 +50,7 @@ EbmlBinary::~EbmlBinary() { EbmlBinary::operator const binary &() const {return *Data;} -filepos_t EbmlBinary::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) +filepos_t EbmlBinary::RenderData(IOCallback & output, bool /* bForceRender */, ShouldWrite /* writeFilter */) { output.writeFully(Data,GetSize()); @@ -60,7 +60,7 @@ filepos_t EbmlBinary::RenderData(IOCallback & output, bool /* bForceRender */, b /*! \note no Default binary value handled */ -std::uint64_t EbmlBinary::UpdateSize(bool /* bWithDefault */, bool /* bForceRender */) +std::uint64_t EbmlBinary::UpdateSize(ShouldWrite /* writeFilter */, bool /* bForceRender */) { return GetSize(); } diff --git a/src/EbmlCrc32.cpp b/src/EbmlCrc32.cpp index 85808289..fa0ec5fa 100644 --- a/src/EbmlCrc32.cpp +++ b/src/EbmlCrc32.cpp @@ -159,7 +159,7 @@ void EbmlCrc32::AddElementCRC32(EbmlElement &ElementToCRC) { // Use a special IOCallback class that Render's to memory instead of to disk MemIOCallback memoryBuffer; - ElementToCRC.Render(memoryBuffer, true, true); + ElementToCRC.Render(memoryBuffer, WriteAll, true); const std::uint64_t memSize = memoryBuffer.GetDataBufferSize(); if (memSize > std::numeric_limits::max()) @@ -181,7 +181,7 @@ bool EbmlCrc32::CheckElementCRC32(EbmlElement &ElementToCRC) const return CheckCRC(m_crc_final, memoryBuffer.GetDataBuffer(), static_cast(memSize)); } -filepos_t EbmlCrc32::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) +filepos_t EbmlCrc32::RenderData(IOCallback & output, bool /* bForceRender */, ShouldWrite /* writeFilter */) { filepos_t Result = 4; diff --git a/src/EbmlDate.cpp b/src/EbmlDate.cpp index afffec79..46715ada 100644 --- a/src/EbmlDate.cpp +++ b/src/EbmlDate.cpp @@ -31,7 +31,7 @@ filepos_t EbmlDate::ReadData(IOCallback & input, ScopeMode ReadFully) return GetSize(); } -filepos_t EbmlDate::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) +filepos_t EbmlDate::RenderData(IOCallback & output, bool /* bForceRender */, ShouldWrite /* writeFilter */) { assert(GetSize() == 8 || GetSize() == 0); if (GetSize() == 8) { diff --git a/src/EbmlElement.cpp b/src/EbmlElement.cpp index e457778b..20f835c4 100644 --- a/src/EbmlElement.cpp +++ b/src/EbmlElement.cpp @@ -474,18 +474,18 @@ EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const Eb /*! \todo verify that the size written is the same as the data written */ -filepos_t EbmlElement::Render(IOCallback & output, bool bWithDefault, bool bKeepPosition, bool bForceRender) +filepos_t EbmlElement::Render(IOCallback & output, ShouldWrite writeFilter, bool bKeepPosition, bool bForceRender) { - assert(bValueIsSet || (bWithDefault && DefaultISset())); // an element is been rendered without a value set !!! + assert(bValueIsSet || writeFilter(*this)); // an element is been rendered without a value set !!! // it may be a mandatory element without a default value - if (!bWithDefault && IsDefaultValue()) { + if (!writeFilter(*this)) { return 0; } #if !defined(NDEBUG) - std::uint64_t SupposedSize = UpdateSize(bWithDefault, bForceRender); + std::uint64_t SupposedSize = UpdateSize(writeFilter, bForceRender); #endif // !NDEBUG - filepos_t result = RenderHead(output, bForceRender, bWithDefault, bKeepPosition); - const std::uint64_t WrittenSize = RenderData(output, bForceRender, bWithDefault); + filepos_t result = RenderHead(output, bForceRender, writeFilter, bKeepPosition); + const std::uint64_t WrittenSize = RenderData(output, bForceRender, writeFilter); #if !defined(NDEBUG) if (static_cast(SupposedSize) != (0-1)) assert(WrittenSize == SupposedSize); @@ -499,12 +499,12 @@ filepos_t EbmlElement::Render(IOCallback & output, bool bWithDefault, bool bKeep \todo handle exceptions on errors \todo handle CodeSize bigger than 5 bytes */ -filepos_t EbmlElement::RenderHead(IOCallback & output, bool bForceRender, bool bWithDefault, bool bKeepPosition) +filepos_t EbmlElement::RenderHead(IOCallback & output, bool bForceRender, ShouldWrite writeFilter, bool bKeepPosition) { if (EBML_ID_LENGTH((const EbmlId&)*this) <= 0 || EBML_ID_LENGTH((const EbmlId&)*this) > 4) return 0; - UpdateSize(bWithDefault, bForceRender); + UpdateSize(writeFilter, bForceRender); return MakeRenderHead(output, bKeepPosition); } @@ -530,9 +530,9 @@ filepos_t EbmlElement::MakeRenderHead(IOCallback & output, bool bKeepPosition) return FinalHeadSize; } -std::uint64_t EbmlElement::ElementSize(bool bWithDefault) const +std::uint64_t EbmlElement::ElementSize(ShouldWrite writeFilter) const { - if (!bWithDefault && IsDefaultValue()) + if (!writeFilter(*this)) return 0; // won't be saved return Size + EBML_ID_LENGTH((const EbmlId&)*this) + CodedSizeLength(Size, SizeLength, bSizeIsFinite); } @@ -601,21 +601,21 @@ filepos_t EbmlElement::OverwriteData(IOCallback & output, bool bKeepPosition) auto CurrentPosition = output.getFilePointer(); output.setFilePointer(GetElementPosition() + HeaderSize); - auto Result = RenderData(output, true, bKeepPosition); + auto Result = RenderData(output, true, bKeepPosition ? WriteAll : WriteSkipDefault); output.setFilePointer(CurrentPosition); assert(Result == DataSize); return Result; } -std::uint64_t EbmlElement::VoidMe(IOCallback & output, bool bWithDefault) const +std::uint64_t EbmlElement::VoidMe(IOCallback & output, ShouldWrite writeFilter) const { if (ElementPosition == 0) { return 0; // the element has not been written } EbmlVoid Dummy; - return Dummy.Overwrite(*this, output, true, bWithDefault); + return Dummy.Overwrite(*this, output, true, writeFilter); } } // namespace libebml diff --git a/src/EbmlFloat.cpp b/src/EbmlFloat.cpp index f8888045..ef875fd7 100644 --- a/src/EbmlFloat.cpp +++ b/src/EbmlFloat.cpp @@ -51,7 +51,7 @@ EbmlFloat & EbmlFloat::SetValue(double NewValue) { \todo handle exception on errors \todo handle 10 bits precision */ -filepos_t EbmlFloat::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) +filepos_t EbmlFloat::RenderData(IOCallback & output, bool /* bForceRender */, ShouldWrite /* writeFilter */) { assert(GetSize() == 4 || GetSize() == 8); @@ -74,9 +74,9 @@ filepos_t EbmlFloat::RenderData(IOCallback & output, bool /* bForceRender */, bo return GetSize(); } -std::uint64_t EbmlFloat::UpdateSize(bool bWithDefault, bool /* bForceRender */) +std::uint64_t EbmlFloat::UpdateSize(ShouldWrite writeFilter, bool /* bForceRender */) { - if (!bWithDefault && IsDefaultValue()) + if (!writeFilter(*this)) return 0; return GetSize(); } diff --git a/src/EbmlMaster.cpp b/src/EbmlMaster.cpp index 07974268..f7c0fc94 100644 --- a/src/EbmlMaster.cpp +++ b/src/EbmlMaster.cpp @@ -48,7 +48,7 @@ EbmlMaster::~EbmlMaster() \todo handle exception on errors \todo write all the Mandatory elements in the Context, otherwise assert */ -filepos_t EbmlMaster::RenderData(IOCallback & output, bool bForceRender, bool bWithDefault) +filepos_t EbmlMaster::RenderData(IOCallback & output, bool bForceRender, ShouldWrite writeFilter) { filepos_t Result = 0; @@ -58,16 +58,16 @@ filepos_t EbmlMaster::RenderData(IOCallback & output, bool bForceRender, bool bW if (!bChecksumUsed) { // old school for (auto Element : ElementList) { - if (!bWithDefault && Element->IsDefaultValue()) + if (!writeFilter(*Element)) continue; - Result += Element->Render(output, bWithDefault, false ,bForceRender); + Result += Element->Render(output, writeFilter, false ,bForceRender); } } else { // new school MemIOCallback TmpBuf(GetSize() - 6); for (auto Element : ElementList) { - if (!bWithDefault && Element->IsDefaultValue()) + if (!writeFilter(*Element)) continue; - Element->Render(TmpBuf, bWithDefault, false ,bForceRender); + Element->Render(TmpBuf, writeFilter, false ,bForceRender); } std::uint64_t memSize = TmpBuf.GetDataBufferSize(); binary *memStart = TmpBuf.GetDataBuffer(); @@ -77,7 +77,7 @@ filepos_t EbmlMaster::RenderData(IOCallback & output, bool bForceRender, bool bW memStart += fillSize; memSize -= fillSize; } - Result += Checksum.Render(output, true, false ,bForceRender); + Result += Checksum.Render(output, writeFilter, false ,bForceRender); output.writeFully(TmpBuf.GetDataBuffer(), TmpBuf.GetDataBufferSize()); Result += TmpBuf.GetDataBufferSize(); } @@ -94,7 +94,7 @@ bool EbmlMaster::PushElement(EbmlElement & element) return true; } -std::uint64_t EbmlMaster::UpdateSize(bool bWithDefault, bool bForceRender) +std::uint64_t EbmlMaster::UpdateSize(ShouldWrite writeFilter, bool bForceRender) { SetSize_(0); @@ -106,10 +106,10 @@ std::uint64_t EbmlMaster::UpdateSize(bool bWithDefault, bool bForceRender) } for (auto Element : ElementList) { - if (!bWithDefault && Element->IsDefaultValue()) + if (!writeFilter(*Element)) continue; - Element->UpdateSize(bWithDefault, bForceRender); - const std::uint64_t SizeToAdd = Element->ElementSize(bWithDefault); + Element->UpdateSize(writeFilter, bForceRender); + const std::uint64_t SizeToAdd = Element->ElementSize(writeFilter); #if !defined(NDEBUG) if (static_cast(SizeToAdd) == (0-1)) return (0-1); @@ -123,10 +123,10 @@ std::uint64_t EbmlMaster::UpdateSize(bool bWithDefault, bool bForceRender) return GetSize(); } -filepos_t EbmlMaster::WriteHead(IOCallback & output, int nSizeLength, bool bWithDefault) +filepos_t EbmlMaster::WriteHead(IOCallback & output, int nSizeLength, ShouldWrite writeFilter) { SetSizeLength(nSizeLength); - return RenderHead(output, false, bWithDefault); + return RenderHead(output, false, writeFilter); } /*! @@ -479,7 +479,7 @@ bool EbmlMaster::VerifyChecksum() const /// \todo find another way when not all default values are saved or (unknown from the reader !!!) MemIOCallback TmpBuf(GetSize() - 6); for (auto Element : ElementList) { - Element->Render(TmpBuf, true, false, true); + Element->Render(TmpBuf, WriteAll, false, true); } std::uint64_t memSize = TmpBuf.GetDataBufferSize(); binary *memStart = TmpBuf.GetDataBuffer(); diff --git a/src/EbmlSInteger.cpp b/src/EbmlSInteger.cpp index e6757207..c570efe4 100644 --- a/src/EbmlSInteger.cpp +++ b/src/EbmlSInteger.cpp @@ -55,7 +55,7 @@ EbmlSInteger & EbmlSInteger::SetValue(std::int64_t NewValue) { /*! \todo handle exception on errors */ -filepos_t EbmlSInteger::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) +filepos_t EbmlSInteger::RenderData(IOCallback & output, bool /* bForceRender */, ShouldWrite /* writeFilter */) { std::array FinalData; // we don't handle more than 64 bits integers unsigned int i; @@ -74,9 +74,9 @@ filepos_t EbmlSInteger::RenderData(IOCallback & output, bool /* bForceRender */, return GetSize(); } -std::uint64_t EbmlSInteger::UpdateSize(bool bWithDefault, bool /* bForceRender */) +std::uint64_t EbmlSInteger::UpdateSize(ShouldWrite writeFilter, bool /* bForceRender */) { - if (!bWithDefault && IsDefaultValue()) + if (!writeFilter(*this)) return 0; if (Value <= 0x7F && Value >= (-0x80)) { diff --git a/src/EbmlString.cpp b/src/EbmlString.cpp index e29bf9d4..9684b551 100644 --- a/src/EbmlString.cpp +++ b/src/EbmlString.cpp @@ -53,7 +53,7 @@ const std::string & EbmlString::DefaultVal() const /*! \todo handle exception on errors */ -filepos_t EbmlString::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) +filepos_t EbmlString::RenderData(IOCallback & output, bool /* bForceRender */, ShouldWrite /* writeFilter */) { filepos_t Result; output.writeFully(Value.c_str(), Value.length()); @@ -95,9 +95,9 @@ std::string EbmlString::GetValue() const { return Value; } -std::uint64_t EbmlString::UpdateSize(bool bWithDefault, bool /* bForceRender */) +std::uint64_t EbmlString::UpdateSize(ShouldWrite writeFilter, bool /* bForceRender */) { - if (!bWithDefault && IsDefaultValue()) + if (!writeFilter(*this)) return 0; if (Value.length() < GetDefaultSize()) { diff --git a/src/EbmlUInteger.cpp b/src/EbmlUInteger.cpp index 1d5ad951..051846b3 100644 --- a/src/EbmlUInteger.cpp +++ b/src/EbmlUInteger.cpp @@ -50,7 +50,7 @@ EbmlUInteger & EbmlUInteger::SetValue(std::uint64_t NewValue) { /*! \todo handle exception on errors */ -filepos_t EbmlUInteger::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) +filepos_t EbmlUInteger::RenderData(IOCallback & output, bool /* bForceRender */, ShouldWrite /* writeFilter */) { std::array FinalData; // we don't handle more than 64 bits integers @@ -68,9 +68,9 @@ filepos_t EbmlUInteger::RenderData(IOCallback & output, bool /* bForceRender */, return GetSize(); } -std::uint64_t EbmlUInteger::UpdateSize(bool bWithDefault, bool /* bForceRender */) +std::uint64_t EbmlUInteger::UpdateSize(ShouldWrite writeFilter, bool /* bForceRender */) { - if (!bWithDefault && IsDefaultValue()) + if (!writeFilter(*this)) return 0; if (Value <= 0xFF) { diff --git a/src/EbmlUnicodeString.cpp b/src/EbmlUnicodeString.cpp index c3c3461c..4282417c 100644 --- a/src/EbmlUnicodeString.cpp +++ b/src/EbmlUnicodeString.cpp @@ -192,7 +192,7 @@ const UTFstring & EbmlUnicodeString::DefaultVal() const \note limited to UCS-2 \todo handle exception on errors */ -filepos_t EbmlUnicodeString::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) +filepos_t EbmlUnicodeString::RenderData(IOCallback & output, bool /* bForceRender */, ShouldWrite /* writeFilter */) { std::size_t Result = Value.GetUTF8().length(); @@ -245,9 +245,9 @@ std::string EbmlUnicodeString::GetValueUTF8() const { /*! \note limited to UCS-2 */ -std::uint64_t EbmlUnicodeString::UpdateSize(bool bWithDefault, bool /* bForceRender */) +std::uint64_t EbmlUnicodeString::UpdateSize(ShouldWrite writeFilter, bool /* bForceRender */) { - if (!bWithDefault && IsDefaultValue()) + if (!writeFilter(*this)) return 0; SetSize_(Value.GetUTF8().length()); diff --git a/src/EbmlVoid.cpp b/src/EbmlVoid.cpp index e60dc289..f251ce61 100644 --- a/src/EbmlVoid.cpp +++ b/src/EbmlVoid.cpp @@ -17,7 +17,7 @@ EbmlVoid::EbmlVoid() SetValueIsSet(); } -filepos_t EbmlVoid::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) +filepos_t EbmlVoid::RenderData(IOCallback & output, bool /* bForceRender */, ShouldWrite /* writeFilter */) { // write dummy data by 4KB chunks static binary DummyBuf[4*1024]; @@ -31,9 +31,9 @@ filepos_t EbmlVoid::RenderData(IOCallback & output, bool /* bForceRender */, boo return GetSize(); } -std::uint64_t EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output, bool ComeBackAfterward, bool bWithDefault) +std::uint64_t EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output, bool ComeBackAfterward, ShouldWrite writeFilter) { - EltToReplaceWith.UpdateSize(bWithDefault); + EltToReplaceWith.UpdateSize(writeFilter); if (HeadSize() + GetSize() < EltToReplaceWith.GetSize() + EltToReplaceWith.HeadSize()) { // the element can't be written here ! return INVALID_FILEPOS_T; @@ -46,7 +46,7 @@ std::uint64_t EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & const std::uint64_t CurrentPosition = output.getFilePointer(); output.setFilePointer(GetElementPosition()); - EltToReplaceWith.Render(output, bWithDefault); + EltToReplaceWith.Render(output, writeFilter); if (HeadSize() + GetSize() - EltToReplaceWith.GetSize() - EltToReplaceWith.HeadSize() > 1) { // fill the rest with another void element @@ -58,7 +58,7 @@ std::uint64_t EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & if (HeadBefore != HeadAfter) { aTmp.SetSizeLength(CodedSizeLength(aTmp.GetSize(), aTmp.GetSizeLength(), aTmp.IsFiniteSize()) - (HeadAfter - HeadBefore)); } - aTmp.RenderHead(output, false, bWithDefault); // the rest of the data is not rewritten + aTmp.RenderHead(output, false, writeFilter); // the rest of the data is not rewritten } if (ComeBackAfterward) { @@ -68,7 +68,7 @@ std::uint64_t EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & return GetSize() + HeadSize(); } -std::uint64_t EbmlVoid::Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward, bool bWithDefault) +std::uint64_t EbmlVoid::Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward, ShouldWrite writeFilter) { // EltToVoid.UpdateSize(bWithDefault); if (EltToVoid.GetElementPosition() == 0) { @@ -96,7 +96,7 @@ std::uint64_t EbmlVoid::Overwrite(const EbmlElement & EltToVoid, IOCallback & ou } if (GetSize() != 0) { - RenderHead(output, false, bWithDefault); // the rest of the data is not rewritten + RenderHead(output, false, writeFilter); // the rest of the data is not rewritten } if (ComeBackAfterward) {