diff --git a/CMakeLists.txt b/CMakeLists.txt index cb825519..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 @@ -148,6 +147,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/EbmlCrc32.h b/ebml/EbmlCrc32.h index 58946f2b..bc4838e3 100644 --- a/ebml/EbmlCrc32.h +++ b/ebml/EbmlCrc32.h @@ -9,10 +9,6 @@ #ifndef LIBEBML_CRC32_H #define LIBEBML_CRC32_H -#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 45efd9be..fe1b48d0 100644 --- a/ebml/EbmlHead.h +++ b/ebml/EbmlHead.h @@ -8,8 +8,9 @@ #ifndef LIBEBML_HEAD_H #define LIBEBML_HEAD_H -#include "EbmlTypes.h" #include "EbmlMaster.h" +#include "EbmlUInteger.h" +#include "EbmlString.h" namespace libebml { @@ -18,6 +19,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/EbmlMaster.h b/ebml/EbmlMaster.h index ab5ad763..a605afc0 100644 --- a/ebml/EbmlMaster.h +++ b/ebml/EbmlMaster.h @@ -8,10 +8,8 @@ #ifndef LIBEBML_MASTER_H #define LIBEBML_MASTER_H -#include #include -#include "EbmlTypes.h" #include "EbmlElement.h" #include "EbmlCrc32.h" @@ -140,11 +138,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/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/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/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 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/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_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 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; +}