diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-10-06 13:29:36 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-10-06 13:29:36 +0100 |
| commit | 4ada3e7583dfdc658dbebca3c3603be1e3477c12 (patch) | |
| tree | 0516fdd142b79e7083ed3d455fe45fffce26a9a8 /src/collect.h | |
| parent | 86440b2afe0a2b83a7e810f37b1f65dbddee90e8 (diff) | |
Template-ize collect so that any container can be used.
Add new vertical reference of TOP_OF_SUBTITLE, and use references
with line numbers as well as proportional specifiers.
Add a couple of methods to MetricTime.
Diffstat (limited to 'src/collect.h')
| -rw-r--r-- | src/collect.h | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/collect.h b/src/collect.h index 62e872f..ff43ce0 100644 --- a/src/collect.h +++ b/src/collect.h @@ -22,6 +22,39 @@ namespace sub { -std::list<Subtitle> collect (std::list<RawSubtitle>); +template <class T> +T +collect (std::list<RawSubtitle> raw) +{ + raw.sort (); + + T out; + + boost::optional<Subtitle> current; + for (std::list<RawSubtitle>::const_iterator i = raw.begin (); i != raw.end(); ++i) { + if (current && current->same_metadata (*i)) { + /* This RawSubtitle can be added to current... */ + if (!current->lines.empty() && current->lines.back().same_metadata (*i)) { + /* ... and indeed to its last line */ + current->lines.back().blocks.push_back (Block (*i)); + } else { + /* ... as a new line */ + current->lines.push_back (Line (*i)); + } + } else { + /* We must start a new Subtitle */ + if (current) { + out.push_back (current.get ()); + } + current = Subtitle (*i); + } + } + + if (current) { + out.push_back (current.get ()); + } + + return out; +} } |
