Fix and simplify Matroska simple tag

Avoid use of raw pointers, fix property interface.
This commit is contained in:
Urs Fleisch
2025-08-22 08:55:51 +02:00
parent 3566b00596
commit d47d28f0f8
7 changed files with 336 additions and 312 deletions

View File

@ -30,23 +30,21 @@ int main(int argc, char *argv[])
const TagLib::Matroska::SimpleTagsList &list = tag->simpleTagsList();
printf("Found %u tag(s):\n", list.size());
for(TagLib::Matroska::SimpleTag *t : list) {
PRINT_PRETTY("Tag Name", t->name().toCString(true));
for(const TagLib::Matroska::SimpleTag &t : list) {
PRINT_PRETTY("Tag Name", t.name().toCString(true));
TagLib::Matroska::SimpleTagString *tString = nullptr;
TagLib::Matroska::SimpleTagBinary *tBinary = nullptr;
if((tString = dynamic_cast<TagLib::Matroska::SimpleTagString*>(t)))
PRINT_PRETTY("Tag Value", tString->value().toCString(true));
else if((tBinary = dynamic_cast<TagLib::Matroska::SimpleTagBinary*>(t)))
if(t.type() == TagLib::Matroska::SimpleTag::StringType)
PRINT_PRETTY("Tag Value", t.toString().toCString(true));
else if(t.type() == TagLib::Matroska::SimpleTag::BinaryType)
PRINT_PRETTY("Tag Value",
TagLib::Utils::formatString("Binary with size %i", tBinary->value().size()).toCString(false)
TagLib::Utils::formatString("Binary with size %i", t.toByteVector().size()).toCString(false)
);
auto targetTypeValue = static_cast<unsigned int>(t->targetTypeValue());
auto targetTypeValue = static_cast<unsigned int>(t.targetTypeValue());
PRINT_PRETTY("Target Type Value",
targetTypeValue == 0 ? "None" : TagLib::Utils::formatString("%i", targetTypeValue).toCString(false)
);
const TagLib::String &language = t->language();
const TagLib::String &language = t.language();
PRINT_PRETTY("Language", !language.isEmpty() ? language.toCString(false) : "Not set");
printf("\n");

View File

@ -22,18 +22,13 @@ int main(int argc, char *argv[])
auto tag = file.tag(true);
tag->clearSimpleTags();
auto simpleTag = new TagLib::Matroska::SimpleTagString();
simpleTag->setName("Test Name 1");
simpleTag->setTargetTypeValue(TagLib::Matroska::SimpleTag::TargetTypeValue::Track);
simpleTag->setValue("Test Value 1");
simpleTag->setLanguage("en");
tag->addSimpleTag(simpleTag);
tag->addSimpleTag(TagLib::Matroska::SimpleTag(
"Test Name 1", TagLib::String("Test Value 1"),
TagLib::Matroska::SimpleTag::TargetTypeValue::Track, "en"));
simpleTag = new TagLib::Matroska::SimpleTagString();
simpleTag->setName("Test Name 2");
simpleTag->setTargetTypeValue(TagLib::Matroska::SimpleTag::TargetTypeValue::Album);
simpleTag->setValue("Test Value 2");
tag->addSimpleTag(simpleTag);
tag->addSimpleTag(TagLib::Matroska::SimpleTag(
"Test Name 2", TagLib::String("Test Value 2"),
TagLib::Matroska::SimpleTag::TargetTypeValue::Album));
tag->setTitle("Test title");
tag->setArtist("Test artist");
tag->setYear(1969);