Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header cleanup #221

Merged
merged 4 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down
4 changes: 0 additions & 4 deletions ebml/EbmlCrc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
#ifndef LIBEBML_CRC32_H
#define LIBEBML_CRC32_H

#include <array>
#include <cassert>

#include "EbmlTypes.h"
#include "EbmlBinary.h"

namespace libebml {
Expand Down
1 change: 0 additions & 1 deletion ebml/EbmlDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#ifndef LIBEBML_DATE_H
#define LIBEBML_DATE_H

#include "EbmlTypes.h"
#include "EbmlElement.h"

namespace libebml {
Expand Down
1 change: 0 additions & 1 deletion ebml/EbmlFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#ifndef LIBEBML_FLOAT_H
#define LIBEBML_FLOAT_H

#include "EbmlTypes.h"
#include "EbmlElement.h"

namespace libebml {
Expand Down
38 changes: 37 additions & 1 deletion ebml/EbmlHead.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
7 changes: 0 additions & 7 deletions ebml/EbmlMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
#ifndef LIBEBML_MASTER_H
#define LIBEBML_MASTER_H

#include <string>
#include <vector>

#include "EbmlTypes.h"
#include "EbmlElement.h"
#include "EbmlCrc32.h"

Expand Down Expand Up @@ -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<std::string> FindAllMissingElements() const;

private:
std::vector<EbmlElement *> ElementList;

Expand Down
1 change: 0 additions & 1 deletion ebml/EbmlSInteger.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <cassert>

#include "EbmlTypes.h"
#include "EbmlElement.h"

namespace libebml {
Expand Down
1 change: 0 additions & 1 deletion ebml/EbmlStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#ifndef LIBEBML_STREAM_H
#define LIBEBML_STREAM_H

#include "EbmlTypes.h"
#include "IOCallback.h"
#include "EbmlElement.h"

Expand Down
1 change: 0 additions & 1 deletion ebml/EbmlString.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <string>

#include "EbmlTypes.h"
#include "EbmlElement.h"

namespace libebml {
Expand Down
55 changes: 0 additions & 55 deletions ebml/EbmlSubHead.h

This file was deleted.

1 change: 0 additions & 1 deletion ebml/EbmlUInteger.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef LIBEBML_UINTEGER_H
#define LIBEBML_UINTEGER_H

#include "EbmlTypes.h"
#include "EbmlElement.h"

namespace libebml {
Expand Down
1 change: 0 additions & 1 deletion ebml/EbmlUnicodeString.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <string>

#include "EbmlTypes.h"
#include "EbmlElement.h"

namespace libebml {
Expand Down
1 change: 0 additions & 1 deletion ebml/EbmlVoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#ifndef LIBEBML_VOID_H
#define LIBEBML_VOID_H

#include "EbmlTypes.h"
#include "EbmlBinary.h"

namespace libebml {
Expand Down
1 change: 0 additions & 1 deletion ebml/SafeReadIOCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#define LIBEBML_SAFEREADIOCALLBACK_H

#include "EbmlBinary.h"
#include "EbmlTypes.h"
#include "IOCallback.h"

#include <memory>
Expand Down
1 change: 0 additions & 1 deletion src/EbmlHead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
\author Steve Lhomme <robux4 @ users.sf.net>
*/
#include "ebml/EbmlHead.h"
#include "ebml/EbmlSubHead.h"
#include "ebml/EbmlContexts.h"

namespace libebml {
Expand Down
42 changes: 0 additions & 42 deletions src/EbmlMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,48 +186,6 @@ bool EbmlMaster::CheckMandatory() const
return true;
}

std::vector<std::string> EbmlMaster::FindAllMissingElements() const
{
assert(MasterContext.GetSize() != 0);

std::vector<std::string> 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<const EbmlMaster*>(childElement);

std::vector<std::string> 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)
Expand Down
1 change: 0 additions & 1 deletion test/test_header.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: ISC

#include <ebml/EbmlHead.h>
#include <ebml/EbmlSubHead.h>
#include <ebml/EbmlMaster.h>
#include <ebml/EbmlStream.h>
#include <ebml/MemIOCallback.h>
Expand Down
59 changes: 59 additions & 0 deletions test/test_missing.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright © 2023 Steve Lhomme.
// SPDX-License-Identifier: ISC

#include <ebml/EbmlHead.h>

#include <cassert>
#include <string>

using namespace libebml;

static void FindAllMissingElements(const EbmlMaster *pThis, std::vector<std::string> & 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<const EbmlMaster*>(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<std::string> missingElements;
FindAllMissingElements(&TestHead, missingElements);

return 0;
}
Loading