From b5475c34e547989dff6c89c6af1050998d8a9067 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sat, 13 Jan 2024 18:10:44 +0100 Subject: [PATCH 1/4] move FindAllMissingElements functionality into a test example It's not used by anyone and is not a core functionality of libebml. It can be done externally as the test shows. --- CMakeLists.txt | 4 +++ ebml/EbmlMaster.h | 6 ----- src/EbmlMaster.cpp | 42 ------------------------------ test/test_missing.cxx | 59 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 48 deletions(-) create mode 100644 test/test_missing.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index cb825519..187fdb90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,6 +148,10 @@ if (BUILD_TESTING) target_link_libraries(test_macros PUBLIC ebml) add_test(test_macros test_macros) + add_executable(test_missing test/test_missing.cxx) + target_link_libraries(test_missing PUBLIC ebml) + add_test(test_missing test_missing) + endif(BUILD_TESTING) diff --git a/ebml/EbmlMaster.h b/ebml/EbmlMaster.h index ab5ad763..392959a8 100644 --- a/ebml/EbmlMaster.h +++ b/ebml/EbmlMaster.h @@ -8,7 +8,6 @@ #ifndef LIBEBML_MASTER_H #define LIBEBML_MASTER_H -#include #include #include "EbmlTypes.h" @@ -140,11 +139,6 @@ class EBML_DLL_API EbmlMaster : public EbmlElement { bChecksumUsed = true; } - /*! - \brief drill down all sub-elements, finding any missing elements - */ - std::vector FindAllMissingElements() const; - private: std::vector ElementList; diff --git a/src/EbmlMaster.cpp b/src/EbmlMaster.cpp index 91eaaff3..0726fe8f 100644 --- a/src/EbmlMaster.cpp +++ b/src/EbmlMaster.cpp @@ -186,48 +186,6 @@ bool EbmlMaster::CheckMandatory() const return true; } -std::vector EbmlMaster::FindAllMissingElements() const -{ - assert(MasterContext.GetSize() != 0); - - std::vector missingElements; - - for (auto childElement : ElementList) { - if (!childElement->ValueIsSet()) { - std::string missingValue; - missingValue = "The Child Element \""; - missingValue.append(EBML_NAME(childElement)); - missingValue.append("\" of EbmlMaster \""); - missingValue.append(EBML_NAME(this)); - missingValue.append("\", does not have a value set."); - missingElements.push_back(std::move(missingValue)); - } - - if (childElement->IsMaster()) { - const auto childMaster = static_cast(childElement); - - std::vector childMissingElements = childMaster->FindAllMissingElements(); - std::copy(childMissingElements.begin(), childMissingElements.end(), std::back_inserter(missingElements)); - } - } - unsigned int EltIdx; - for (EltIdx = 0; EltIdx < EBML_CTX_SIZE(MasterContext); EltIdx++) { - if (EBML_CTX_IDX(MasterContext,EltIdx).IsMandatory()) { - if (FindElt(EBML_CTX_IDX_INFO(MasterContext,EltIdx)) == nullptr) { - std::string missingElement; - missingElement = "Missing element \""; - missingElement.append(EBML_INFO_NAME(EBML_CTX_IDX_INFO(MasterContext,EltIdx))); - missingElement.append("\" in EbmlMaster \""); - missingElement.append(EBML_INFO_NAME(*EBML_CTX_MASTER(MasterContext))); - missingElement.append("\""); - missingElements.push_back(std::move(missingElement)); - } - } - } - - return missingElements; -} - EbmlElement *EbmlMaster::FindElt(const EbmlCallbacks & Callbacks) const { auto it = std::find_if(ElementList.begin(), ElementList.end(), [&](const EbmlElement *Element) diff --git a/test/test_missing.cxx b/test/test_missing.cxx new file mode 100644 index 00000000..716b4d93 --- /dev/null +++ b/test/test_missing.cxx @@ -0,0 +1,59 @@ +// Copyright © 2023 Steve Lhomme. +// SPDX-License-Identifier: ISC + +#include + +#include +#include + +using namespace libebml; + +static void FindAllMissingElements(const EbmlMaster *pThis, std::vector & missingElements) +{ + const EbmlSemanticContext & MasterContext = EBML_CONTEXT(pThis); + for (auto childElement : pThis->GetElementList()) { + if (!childElement->ValueIsSet()) { + std::string missingValue; + missingValue = "The Child Element \""; + missingValue.append(EBML_NAME(childElement)); + missingValue.append("\" of EbmlMaster \""); + missingValue.append(EBML_NAME(pThis)); + missingValue.append("\", does not have a value set."); + missingElements.push_back(std::move(missingValue)); + } + + if (childElement->IsMaster()) { + const auto childMaster = static_cast(childElement); + + FindAllMissingElements(childMaster, missingElements); + } + } + unsigned int EltIdx; + for (EltIdx = 0; EltIdx < EBML_CTX_SIZE(MasterContext); EltIdx++) { + if (EBML_CTX_IDX(MasterContext,EltIdx).IsMandatory()) { + if (pThis->FindElt(EBML_CTX_IDX_INFO(MasterContext,EltIdx)) == nullptr) { + std::string missingElement; + missingElement = "Missing element \""; + missingElement.append(EBML_INFO_NAME(EBML_CTX_IDX_INFO(MasterContext,EltIdx))); + missingElement.append("\" in EbmlMaster \""); + missingElement.append(EBML_INFO_NAME(*EBML_CTX_MASTER(MasterContext))); + missingElement.append("\""); + missingElements.push_back(std::move(missingElement)); + } + } + } + +} + +int main(void) +{ + EbmlHead TestHead; + const EbmlSemanticContext & MasterContext = EBML_CONTEXT(&TestHead); + + assert(MasterContext.GetSize() != 0); + + std::vector missingElements; + FindAllMissingElements(&TestHead, missingElements); + + return 0; +} From 06465fdcafd9ad98a34b567be65979fd0d76c4cc Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sat, 13 Jan 2024 18:08:29 +0100 Subject: [PATCH 2/4] move the EbmlSubHead.h content in EbmlHead.h People using the header should also know about versioning. --- CMakeLists.txt | 1 - ebml/EbmlHead.h | 37 +++++++++++++++++++++++++++++ ebml/EbmlSubHead.h | 55 -------------------------------------------- src/EbmlHead.cpp | 1 - test/test_header.cxx | 1 - 5 files changed, 37 insertions(+), 58 deletions(-) delete mode 100644 ebml/EbmlSubHead.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 187fdb90..a2b2ac72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,6 @@ set(libebml_PUBLIC_HEADERS ebml/EbmlSInteger.h ebml/EbmlStream.h ebml/EbmlString.h - ebml/EbmlSubHead.h ebml/EbmlTypes.h ebml/EbmlUInteger.h ebml/EbmlUnicodeString.h diff --git a/ebml/EbmlHead.h b/ebml/EbmlHead.h index 45efd9be..efc53234 100644 --- a/ebml/EbmlHead.h +++ b/ebml/EbmlHead.h @@ -10,6 +10,8 @@ #include "EbmlTypes.h" #include "EbmlMaster.h" +#include "EbmlUInteger.h" +#include "EbmlString.h" namespace libebml { @@ -18,6 +20,41 @@ DECLARE_EBML_MASTER(EbmlHead) EBML_CONCRETE_CLASS(EbmlHead) }; +DECLARE_EBML_UINTEGER_DEF(EVersion) + public: + EBML_CONCRETE_CLASS(EVersion) +}; + +DECLARE_EBML_UINTEGER_DEF(EReadVersion) + public: + EBML_CONCRETE_CLASS(EReadVersion) +}; + +DECLARE_EBML_UINTEGER_DEF(EMaxIdLength) + public: + EBML_CONCRETE_CLASS(EMaxIdLength) +}; + +DECLARE_EBML_UINTEGER_DEF(EMaxSizeLength) + public: + EBML_CONCRETE_CLASS(EMaxSizeLength) +}; + +DECLARE_EBML_STRING_DEF(EDocType) + public: + EBML_CONCRETE_CLASS(EDocType) +}; + +DECLARE_EBML_UINTEGER_DEF(EDocTypeVersion) + public: + EBML_CONCRETE_CLASS(EDocTypeVersion) +}; + +DECLARE_EBML_UINTEGER_DEF(EDocTypeReadVersion) + public: + EBML_CONCRETE_CLASS(EDocTypeReadVersion) +}; + } // namespace libebml #endif // LIBEBML_HEAD_H diff --git a/ebml/EbmlSubHead.h b/ebml/EbmlSubHead.h deleted file mode 100644 index de7e55dd..00000000 --- a/ebml/EbmlSubHead.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright © 2002-2010 Steve Lhomme. -// SPDX-License-Identifier: LGPL-2.1-or-later - -/*! - \file - \author Steve Lhomme -*/ -#ifndef LIBEBML_SUBHEAD_H -#define LIBEBML_SUBHEAD_H - -#include - -#include "EbmlUInteger.h" -#include "EbmlString.h" - -namespace libebml { - -DECLARE_EBML_UINTEGER_DEF(EVersion) - public: - EBML_CONCRETE_CLASS(EVersion) -}; - -DECLARE_EBML_UINTEGER_DEF(EReadVersion) - public: - EBML_CONCRETE_CLASS(EReadVersion) -}; - -DECLARE_EBML_UINTEGER_DEF(EMaxIdLength) - public: - EBML_CONCRETE_CLASS(EMaxIdLength) -}; - -DECLARE_EBML_UINTEGER_DEF(EMaxSizeLength) - public: - EBML_CONCRETE_CLASS(EMaxSizeLength) -}; - -DECLARE_EBML_STRING_DEF(EDocType) - public: - EBML_CONCRETE_CLASS(EDocType) -}; - -DECLARE_EBML_UINTEGER_DEF(EDocTypeVersion) - public: - EBML_CONCRETE_CLASS(EDocTypeVersion) -}; - -DECLARE_EBML_UINTEGER_DEF(EDocTypeReadVersion) - public: - EBML_CONCRETE_CLASS(EDocTypeReadVersion) -}; - -} // namespace libebml - -#endif // LIBEBML_SUBHEAD_H diff --git a/src/EbmlHead.cpp b/src/EbmlHead.cpp index f1b9c82c..4de15383 100644 --- a/src/EbmlHead.cpp +++ b/src/EbmlHead.cpp @@ -6,7 +6,6 @@ \author Steve Lhomme */ #include "ebml/EbmlHead.h" -#include "ebml/EbmlSubHead.h" #include "ebml/EbmlContexts.h" namespace libebml { diff --git a/test/test_header.cxx b/test/test_header.cxx index c8aa33d1..620e355d 100644 --- a/test/test_header.cxx +++ b/test/test_header.cxx @@ -2,7 +2,6 @@ // SPDX-License-Identifier: ISC #include -#include #include #include #include From 060ca7ece16dba09ff5965487538ac784d744fa4 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sat, 13 Jan 2024 18:38:01 +0100 Subject: [PATCH 3/4] don't include EbmlTypes.h before EbmlElement.h It's always implied --- ebml/EbmlCrc32.h | 1 - ebml/EbmlDate.h | 1 - ebml/EbmlFloat.h | 1 - ebml/EbmlHead.h | 1 - ebml/EbmlMaster.h | 1 - ebml/EbmlSInteger.h | 1 - ebml/EbmlStream.h | 1 - ebml/EbmlString.h | 1 - ebml/EbmlUInteger.h | 1 - ebml/EbmlUnicodeString.h | 1 - ebml/EbmlVoid.h | 1 - ebml/SafeReadIOCallback.h | 1 - 12 files changed, 12 deletions(-) diff --git a/ebml/EbmlCrc32.h b/ebml/EbmlCrc32.h index 58946f2b..2dbdbbf2 100644 --- a/ebml/EbmlCrc32.h +++ b/ebml/EbmlCrc32.h @@ -12,7 +12,6 @@ #include #include -#include "EbmlTypes.h" #include "EbmlBinary.h" namespace libebml { diff --git a/ebml/EbmlDate.h b/ebml/EbmlDate.h index e1a6b61e..0d89a478 100644 --- a/ebml/EbmlDate.h +++ b/ebml/EbmlDate.h @@ -8,7 +8,6 @@ #ifndef LIBEBML_DATE_H #define LIBEBML_DATE_H -#include "EbmlTypes.h" #include "EbmlElement.h" namespace libebml { diff --git a/ebml/EbmlFloat.h b/ebml/EbmlFloat.h index a6c2e5d1..71702815 100644 --- a/ebml/EbmlFloat.h +++ b/ebml/EbmlFloat.h @@ -8,7 +8,6 @@ #ifndef LIBEBML_FLOAT_H #define LIBEBML_FLOAT_H -#include "EbmlTypes.h" #include "EbmlElement.h" namespace libebml { diff --git a/ebml/EbmlHead.h b/ebml/EbmlHead.h index efc53234..fe1b48d0 100644 --- a/ebml/EbmlHead.h +++ b/ebml/EbmlHead.h @@ -8,7 +8,6 @@ #ifndef LIBEBML_HEAD_H #define LIBEBML_HEAD_H -#include "EbmlTypes.h" #include "EbmlMaster.h" #include "EbmlUInteger.h" #include "EbmlString.h" diff --git a/ebml/EbmlMaster.h b/ebml/EbmlMaster.h index 392959a8..a605afc0 100644 --- a/ebml/EbmlMaster.h +++ b/ebml/EbmlMaster.h @@ -10,7 +10,6 @@ #include -#include "EbmlTypes.h" #include "EbmlElement.h" #include "EbmlCrc32.h" diff --git a/ebml/EbmlSInteger.h b/ebml/EbmlSInteger.h index 31efeeee..ffbb56a2 100644 --- a/ebml/EbmlSInteger.h +++ b/ebml/EbmlSInteger.h @@ -12,7 +12,6 @@ #include -#include "EbmlTypes.h" #include "EbmlElement.h" namespace libebml { diff --git a/ebml/EbmlStream.h b/ebml/EbmlStream.h index 188ac745..21f20e68 100644 --- a/ebml/EbmlStream.h +++ b/ebml/EbmlStream.h @@ -8,7 +8,6 @@ #ifndef LIBEBML_STREAM_H #define LIBEBML_STREAM_H -#include "EbmlTypes.h" #include "IOCallback.h" #include "EbmlElement.h" diff --git a/ebml/EbmlString.h b/ebml/EbmlString.h index 7514bd0b..18254975 100644 --- a/ebml/EbmlString.h +++ b/ebml/EbmlString.h @@ -10,7 +10,6 @@ #include -#include "EbmlTypes.h" #include "EbmlElement.h" namespace libebml { diff --git a/ebml/EbmlUInteger.h b/ebml/EbmlUInteger.h index 311f54d2..6ec5bc0d 100644 --- a/ebml/EbmlUInteger.h +++ b/ebml/EbmlUInteger.h @@ -10,7 +10,6 @@ #ifndef LIBEBML_UINTEGER_H #define LIBEBML_UINTEGER_H -#include "EbmlTypes.h" #include "EbmlElement.h" namespace libebml { diff --git a/ebml/EbmlUnicodeString.h b/ebml/EbmlUnicodeString.h index 082764de..48641e46 100644 --- a/ebml/EbmlUnicodeString.h +++ b/ebml/EbmlUnicodeString.h @@ -12,7 +12,6 @@ #include -#include "EbmlTypes.h" #include "EbmlElement.h" namespace libebml { diff --git a/ebml/EbmlVoid.h b/ebml/EbmlVoid.h index 0a4fe0d4..30ddc5cf 100644 --- a/ebml/EbmlVoid.h +++ b/ebml/EbmlVoid.h @@ -8,7 +8,6 @@ #ifndef LIBEBML_VOID_H #define LIBEBML_VOID_H -#include "EbmlTypes.h" #include "EbmlBinary.h" namespace libebml { diff --git a/ebml/SafeReadIOCallback.h b/ebml/SafeReadIOCallback.h index 25359460..643d5c3e 100644 --- a/ebml/SafeReadIOCallback.h +++ b/ebml/SafeReadIOCallback.h @@ -9,7 +9,6 @@ #define LIBEBML_SAFEREADIOCALLBACK_H #include "EbmlBinary.h" -#include "EbmlTypes.h" #include "IOCallback.h" #include From 8fdbe450cd4e83b5c6b2783f2c7fec1489be00a1 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sat, 13 Jan 2024 18:48:27 +0100 Subject: [PATCH 4/4] remove unused includes from EbmlCrc32 --- ebml/EbmlCrc32.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/ebml/EbmlCrc32.h b/ebml/EbmlCrc32.h index 2dbdbbf2..bc4838e3 100644 --- a/ebml/EbmlCrc32.h +++ b/ebml/EbmlCrc32.h @@ -9,9 +9,6 @@ #ifndef LIBEBML_CRC32_H #define LIBEBML_CRC32_H -#include -#include - #include "EbmlBinary.h" namespace libebml {