From 9b8d9f1f0b628f176254f9836c3c79fc76abaf3c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 4 Jun 2005 09:32:33 +0000 Subject: [PATCH] Respect infinite sized elements. Use STL's sort algorithm and not my own bubble sort. --- src/info/mkvinfo.cpp | 49 +++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/info/mkvinfo.cpp b/src/info/mkvinfo.cpp index 95400d645..5031e37df 100644 --- a/src/info/mkvinfo.cpp +++ b/src/info/mkvinfo.cpp @@ -30,6 +30,7 @@ #include #endif +#include #include #include @@ -291,10 +292,10 @@ parse_args(vector args, // {{{ is_global, parse_multicomment/chapter_atom, asctime_r, gmtime_r -#define fits_parent(l, p) (l->GetElementPosition() < \ - (p->GetElementPosition() + p->ElementSize())) -#define in_parent(p) (in->getFilePointer() < \ - (p->GetElementPosition() + p->ElementSize())) +#define in_parent(p) \ + (!p->IsFiniteSize() || \ + (in->getFilePointer() < \ + (p->GetElementPosition() + p->HeadSize() + p->GetSize()))) bool is_global(EbmlStream *es, @@ -346,32 +347,34 @@ asctime_r(const struct tm *tm, // }}} +struct master_sorter_t { + int m_index; + int64_t m_pos; + + inline master_sorter_t(int index, int64_t pos): + m_index(index), m_pos(pos) { } + + inline bool operator <(const master_sorter_t &cmp) const { + return m_pos < cmp.m_pos; + } +}; + void sort_master(EbmlMaster &m) { - int i, sp_idx; + int i; vector tmp; - int64_t smallest_pos; - EbmlMaster *m2; + vector sort_me; - while (m.ListSize() > 0) { - sp_idx = 0; - smallest_pos = m[0]->GetElementPosition(); + for (i = 0; m.ListSize() > i; ++i) + sort_me.push_back(master_sorter_t(i, m[i]->GetElementPosition())); + sort(sort_me.begin(), sort_me.end()); - for (i = 1; i < m.ListSize(); i++) - if (m[i]->GetElementPosition() < smallest_pos) { - sp_idx = i; - smallest_pos = m[i]->GetElementPosition(); - } + for (i = 0; sort_me.size() > i; ++i) + tmp.push_back(m[sort_me[i].m_index]); + m.RemoveAll(); - tmp.push_back(m[sp_idx]); - m.Remove(sp_idx); - } - - for (i = 0; i < tmp.size(); i++) { + for (i = 0; tmp.size() > i; ++i) m.PushElement(*tmp[i]); - if ((m2 = dynamic_cast(tmp[i])) != NULL) - sort_master(*m2); - } } void