function for removing mandatory elements set to their default value

This commit is contained in:
Moritz Bunkus 2021-03-15 13:00:56 +01:00
parent f17d44b00b
commit 9336c70c9c
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85
2 changed files with 29 additions and 0 deletions

View File

@ -647,6 +647,34 @@ remove_ietf_language_elements(libebml::EbmlMaster &master) {
}
}
void
remove_mandatory_elements_set_to_their_default(libebml::EbmlMaster &master) {
auto idx = 0u;
while (idx < master.ListSize()) {
auto child = master[idx];
if (dynamic_cast<libebml::EbmlMaster *>(child)) {
remove_mandatory_elements_set_to_their_default(*static_cast<libebml::EbmlMaster *>(child));
++idx;
continue;
}
if (!child->IsDefaultValue()) {
++idx;
continue;
}
auto semantic = find_ebml_semantic(KaxSegment::ClassInfos, libebml::EbmlId(*child));
if (!semantic || !semantic->IsMandatory())
++idx;
else {
delete child;
master.Remove(idx);
}
}
}
static bool
must_be_present_in_master_by_id(EbmlId const &id) {

View File

@ -410,6 +410,7 @@ void remove_voids_from_master(libebml::EbmlElement *element);
void move_children(libebml::EbmlMaster &source, libebml::EbmlMaster &destination);
bool remove_master_from_parent_if_empty_or_only_defaults(libebml::EbmlMaster *parent, libebml::EbmlMaster *child, std::unordered_map<libebml::EbmlMaster *, bool> &handled);
void remove_ietf_language_elements(libebml::EbmlMaster &master);
void remove_mandatory_elements_set_to_their_default(libebml::EbmlMaster &master);
const libebml::EbmlCallbacks *find_ebml_callbacks(const libebml::EbmlCallbacks &base, const libebml::EbmlId &id);
const libebml::EbmlCallbacks *find_ebml_callbacks(const libebml::EbmlCallbacks &base, const char *debug_name);