From c2010e1a650aaef0a367ceda395f8ec6a1d8f06c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 11 Sep 2003 22:20:14 +0000 Subject: [PATCH] Added a function for duplicating KaxChapters. --- src/chapters.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ src/chapters.h | 2 ++ 2 files changed, 95 insertions(+) diff --git a/src/chapters.cpp b/src/chapters.cpp index a46077143..c8bd7afd0 100644 --- a/src/chapters.cpp +++ b/src/chapters.cpp @@ -244,3 +244,96 @@ KaxChapters *parse_chapters(const char *file_name, int64_t min_tc, return NULL; } +#define is_id(c) (EbmlId(*e) == c::ClassInfos.GlobalId) + +static EbmlMaster *copy_chapters_recursive(EbmlMaster *src) { + uint32_t i; + EbmlMaster *dst; + + dst = static_cast(&src->Generic().Create()); + while (dst->ListSize() > 0) { + EbmlElement *e; + e = (*dst)[0]; + dst->Remove(0); + delete e; + } + for (i = 0; i < src->ListSize(); i++) { + EbmlElement *e; + + e = (*src)[i]; + try { + EbmlMaster *m = &dynamic_cast(*e); + dst->PushElement(*copy_chapters_recursive(m)); + } catch (...) { + if (is_id(KaxChapterUID)) { + KaxChapterUID *esrc, *edst; + edst = new KaxChapterUID; + esrc = static_cast(e); + *edst = *esrc; + dst->PushElement(*edst); + + } else if (is_id(KaxChapterTimeStart)) { + KaxChapterTimeStart *esrc, *edst; + edst = new KaxChapterTimeStart; + esrc = static_cast(e); + *edst = *esrc; + dst->PushElement(*edst); + + } else if (is_id(KaxChapterTimeEnd)) { + KaxChapterTimeEnd *esrc, *edst; + edst = new KaxChapterTimeEnd; + esrc = static_cast(e); + *edst = *esrc; + dst->PushElement(*edst); + + } else if (is_id(KaxChapterTrackNumber)) { + KaxChapterTrackNumber *esrc, *edst; + edst = new KaxChapterTrackNumber; + esrc = static_cast(e); + *edst = *esrc; + dst->PushElement(*edst); + + } else if (is_id(KaxChapterString)) { + KaxChapterString *esrc, *edst; + edst = new KaxChapterString; + esrc = static_cast(e); + *static_cast(edst) = UTFstring(*esrc); + dst->PushElement(*edst); + + } else if (is_id(KaxChapterLanguage)) { + KaxChapterLanguage *esrc, *edst; + edst = new KaxChapterLanguage; + esrc = static_cast(e); + *static_cast(edst) = string(*esrc); + dst->PushElement(*edst); + + } else if (is_id(KaxChapterCountry)) { + KaxChapterCountry *esrc, *edst; + edst = new KaxChapterCountry; + esrc = static_cast(e); + *static_cast(edst) = string(*esrc); + dst->PushElement(*edst); + + } + } + } + + return dst; +} + +KaxChapters *copy_chapters(KaxChapters *source) { + KaxChapters *dst; + uint32_t ee; + + if (source == NULL) + return NULL; + + dst = new KaxChapters; + for (ee = 0; ee < source->ListSize(); ee++) { + EbmlMaster *master; + master = copy_chapters_recursive(static_cast((*source)[ee])); + dst->PushElement(*master); + } + + return dst; +} diff --git a/src/chapters.h b/src/chapters.h index c3de092a0..8790a1b03 100644 --- a/src/chapters.h +++ b/src/chapters.h @@ -42,5 +42,7 @@ KaxChapters *parse_xml_chapters(mm_text_io_c *in, int64_t min_tc, void write_chapters_xml(KaxChapters *chapters, FILE *out); void write_chapters_simple(int &chapter_num, KaxChapters *chapters, FILE *out); +KaxChapters *copy_chapters(KaxChapters *source); + #endif // __CHAPTERS_H