diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-01-13 13:04:04 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-01-13 13:04:04 +0100 |
| commit | cafee6f81257fa81ee302b5d3ffa82213a0a6a44 (patch) | |
| tree | 87797f282d0bc1ca62aed44cbf98528ebeb4be86 /src | |
| parent | 18f00cbcdab8eaf3db1cb5a7fba3ed78bea565fa (diff) | |
Replace list with vector in most of the API.
Diffstat (limited to 'src')
| -rw-r--r-- | src/collect.h | 16 | ||||
| -rw-r--r-- | src/dcp_reader.cc | 1 | ||||
| -rw-r--r-- | src/exceptions.cc | 4 | ||||
| -rw-r--r-- | src/exceptions.h | 5 | ||||
| -rw-r--r-- | src/raw_subtitle.h | 2 | ||||
| -rw-r--r-- | src/reader.h | 8 | ||||
| -rw-r--r-- | src/ssa_reader.cc | 5 | ||||
| -rw-r--r-- | src/ssa_reader.h | 2 | ||||
| -rw-r--r-- | src/stl_binary_writer.cc | 10 | ||||
| -rw-r--r-- | src/stl_binary_writer.h | 2 | ||||
| -rw-r--r-- | src/stl_text_reader.cc | 1 | ||||
| -rw-r--r-- | src/subrip_reader.cc | 3 | ||||
| -rw-r--r-- | src/subrip_reader.h | 1 | ||||
| -rw-r--r-- | src/subtitle.h | 6 | ||||
| -rw-r--r-- | src/util.cc | 45 |
15 files changed, 54 insertions, 57 deletions
diff --git a/src/collect.h b/src/collect.h index 34f81aa..5fcf694 100644 --- a/src/collect.h +++ b/src/collect.h @@ -30,29 +30,29 @@ namespace sub { */ template <class T> T -collect (std::list<RawSubtitle> raw) +collect (std::vector<RawSubtitle> raw) { - raw.sort (); + std::stable_sort (raw.begin(), raw.end()); 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)) { + for (auto const& i: raw) { + if (current && current->same_metadata(i)) { /* This RawSubtitle can be added to current... */ - if (!current->lines.empty() && current->lines.back().same_metadata (*i)) { + if (!current->lines.empty() && current->lines.back().same_metadata(i)) { /* ... and indeed to its last line */ - current->lines.back().blocks.push_back (Block (*i)); + current->lines.back().blocks.push_back(Block(i)); } else { /* ... as a new line */ - current->lines.push_back (Line (*i)); + current->lines.push_back(Line(i)); } } else { /* We must start a new Subtitle */ if (current) { out.push_back (current.get ()); } - current = Subtitle (*i); + current = Subtitle (i); } } diff --git a/src/dcp_reader.cc b/src/dcp_reader.cc index 82808b3..5f57746 100644 --- a/src/dcp_reader.cc +++ b/src/dcp_reader.cc @@ -25,7 +25,6 @@ #include <dcp/smpte_subtitle_asset.h> #include <boost/filesystem.hpp> -using std::list; using std::cout; using std::string; using std::exception; diff --git a/src/exceptions.cc b/src/exceptions.cc index d59d32a..bc131b8 100644 --- a/src/exceptions.cc +++ b/src/exceptions.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,8 +21,8 @@ #include "exceptions.h" #include <boost/foreach.hpp> -using std::string; using std::list; +using std::string; using namespace sub; ProgrammingError::ProgrammingError (string file, int line) diff --git a/src/exceptions.h b/src/exceptions.h index 2bb7018..a032252 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,9 +20,10 @@ #ifndef LIBSUB_EXCEPTIONS_H #define LIBSUB_EXCEPTIONS_H +#include <list> #include <stdexcept> #include <string> -#include <list> +#include <vector> namespace sub { diff --git a/src/raw_subtitle.h b/src/raw_subtitle.h index 965ca93..a3ee5ca 100644 --- a/src/raw_subtitle.h +++ b/src/raw_subtitle.h @@ -29,7 +29,7 @@ #include "horizontal_position.h" #include <boost/optional.hpp> #include <string> -#include <list> +#include <vector> namespace sub { diff --git a/src/reader.h b/src/reader.h index 08474f6..aab7384 100644 --- a/src/reader.h +++ b/src/reader.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,9 +21,9 @@ #define LIBSUB_READER_H #include "raw_subtitle.h" -#include <list> #include <map> #include <string> +#include <vector> struct subrip_reader_convert_line_test; @@ -37,7 +37,7 @@ class Reader public: virtual ~Reader () {} - std::list<RawSubtitle> subtitles () const { + std::vector<RawSubtitle> subtitles () const { return _subs; } @@ -50,7 +50,7 @@ protected: void warn (std::string) const; - std::list<RawSubtitle> _subs; + std::vector<RawSubtitle> _subs; }; } diff --git a/src/ssa_reader.cc b/src/ssa_reader.cc index c507ddb..072fff8 100644 --- a/src/ssa_reader.cc +++ b/src/ssa_reader.cc @@ -33,7 +33,6 @@ using std::string; using std::vector; using std::map; using std::cout; -using std::list; using boost::optional; using boost::function; using namespace boost::algorithm; @@ -265,7 +264,7 @@ SSAReader::parse_style (RawSubtitle& sub, string style, int play_res_x, int play * @param line SSA line string (i.e. just the subtitle, possibly with embedded stuff) * @return List of RawSubtitles to represent line with vertical reference TOP_OF_SUBTITLE. */ -list<RawSubtitle> +vector<RawSubtitle> SSAReader::parse_line (RawSubtitle base, string line, int play_res_x, int play_res_y) { enum { @@ -274,7 +273,7 @@ SSAReader::parse_line (RawSubtitle base, string line, int play_res_x, int play_r BACKSLASH } state = TEXT; - list<RawSubtitle> subs; + vector<RawSubtitle> subs; RawSubtitle current = base; string style; diff --git a/src/ssa_reader.h b/src/ssa_reader.h index aba06cc..e9bb061 100644 --- a/src/ssa_reader.h +++ b/src/ssa_reader.h @@ -41,7 +41,7 @@ public: SSAReader (FILE* f); SSAReader (std::string subs); - static std::list<RawSubtitle> parse_line (RawSubtitle base, std::string line, int play_res_x, int play_res_y); + static std::vector<RawSubtitle> parse_line (RawSubtitle base, std::string line, int play_res_x, int play_res_y); static void parse_style (RawSubtitle& sub, std::string style, int play_res_x, int play_res_y); private: diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc index adb9e11..4a16ce0 100644 --- a/src/stl_binary_writer.cc +++ b/src/stl_binary_writer.cc @@ -30,14 +30,12 @@ #include <boost/locale.hpp> #include <boost/algorithm/string.hpp> #include <boost/foreach.hpp> -#include <list> #include <cmath> #include <fstream> -#include <vector> #include <iomanip> #include <set> +#include <vector> -using std::list; using std::set; using std::ofstream; using std::string; @@ -149,7 +147,7 @@ vertical_position (sub::Line const & line) } vector<char*> -make_tti_blocks (list<Subtitle> const& subtitles, STLBinaryTables const& tables, float frames_per_second) +make_tti_blocks (vector<Subtitle> const& subtitles, STLBinaryTables const& tables, float frames_per_second) { static int const tti_size = 128; vector<char*> tti; @@ -287,9 +285,9 @@ make_tti_blocks (list<Subtitle> const& subtitles, STLBinaryTables const& tables, /** @param language ISO 3-character country code for the language of the subtitles */ - void +void sub::write_stl_binary ( - list<Subtitle> subtitles, + vector<Subtitle> subtitles, float frames_per_second, Language language, string original_programme_title, diff --git a/src/stl_binary_writer.h b/src/stl_binary_writer.h index 4986afb..38a102d 100644 --- a/src/stl_binary_writer.h +++ b/src/stl_binary_writer.h @@ -33,7 +33,7 @@ namespace sub { class Subtitle; extern void write_stl_binary ( - std::list<Subtitle> subtitles, + std::vector<Subtitle> subtitles, float frames_per_second, Language language, std::string original_programme_title, diff --git a/src/stl_text_reader.cc b/src/stl_text_reader.cc index c7b1fcf..f08a438 100644 --- a/src/stl_text_reader.cc +++ b/src/stl_text_reader.cc @@ -24,7 +24,6 @@ #include <vector> #include <iostream> -using std::list; using std::ostream; using std::istream; using std::string; diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index 89a5599..ab10f68 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -37,7 +37,6 @@ using std::string; using std::vector; -using std::list; using std::cout; using std::hex; using boost::lexical_cast; @@ -198,7 +197,7 @@ SubripReader::convert_line (string t, RawSubtitle& p) string tag; - list<Colour> colours; + vector<Colour> colours; colours.push_back (Colour (1, 1, 1)); /* XXX: missing <font> support */ diff --git a/src/subrip_reader.h b/src/subrip_reader.h index f45e7c8..8d3fd4c 100644 --- a/src/subrip_reader.h +++ b/src/subrip_reader.h @@ -26,6 +26,7 @@ #include "reader.h" #include <boost/function.hpp> +#include <list> struct subrip_reader_convert_line_test; struct subrip_reader_convert_time_test; diff --git a/src/subtitle.h b/src/subtitle.h index 2b6867d..fba0cf4 100644 --- a/src/subtitle.h +++ b/src/subtitle.h @@ -29,7 +29,7 @@ #include "raw_subtitle.h" #include <boost/optional.hpp> #include <string> -#include <list> +#include <vector> namespace sub { @@ -90,7 +90,7 @@ public: /** vertical position of the baseline of the text */ VerticalPosition vertical_position; - std::list<Block> blocks; + std::vector<Block> blocks; bool same_metadata (RawSubtitle) const; }; @@ -120,7 +120,7 @@ public: boost::optional<Time> fade_up; boost::optional<Time> fade_down; - std::list<Line> lines; + std::vector<Line> lines; bool same_metadata (RawSubtitle) const; }; diff --git a/src/util.cc b/src/util.cc index c347375..eb68752 100644 --- a/src/util.cc +++ b/src/util.cc @@ -32,8 +32,9 @@ using std::getline; using std::ostream; using std::map; using std::list; -using boost::optional; using std::shared_ptr; +using std::vector; +using boost::optional; using namespace sub; /** @param s A string. @@ -100,27 +101,27 @@ sub::remove_unicode_bom (optional<string>& line) void sub::dump (shared_ptr<const Reader> reader, ostream& os) { - map<string, string> metadata = reader->metadata (); - for (map<string, string>::const_iterator i = metadata.begin(); i != metadata.end(); ++i) { - os << i->first << ": " << i->second << "\n"; + auto metadata = reader->metadata (); + for (auto const& i: metadata) { + os << i.first << ": " << i.second << "\n"; } - list<sub::Subtitle> subs = collect<list<sub::Subtitle> > (reader->subtitles ()); + auto subs = collect<vector<sub::Subtitle>> (reader->subtitles()); int n = 0; - for (list<sub::Subtitle>::const_iterator i = subs.begin(); i != subs.end(); ++i) { - os << "Subtitle " << n << " at " << i->from << " -> " << i->to << "\n"; - for (list<sub::Line>::const_iterator j = i->lines.begin(); j != i->lines.end(); ++j) { + for (auto const& i: subs) { + os << "Subtitle " << n << " at " << i.from << " -> " << i.to << "\n"; + for (auto const& j: i.lines) { os << "\t"; - if (j->vertical_position.proportional) { - os << j->vertical_position.proportional.get() << " of screen"; - } else if (j->vertical_position.line && j->vertical_position.lines) { - os << j->vertical_position.line.get() << " lines of " << j->vertical_position.lines.get(); + if (j.vertical_position.proportional) { + os << j.vertical_position.proportional.get() << " of screen"; + } else if (j.vertical_position.line && j.vertical_position.lines) { + os << j.vertical_position.line.get() << " lines of " << j.vertical_position.lines.get(); } - if (j->vertical_position.reference) { + if (j.vertical_position.reference) { os << " from "; - switch (j->vertical_position.reference.get()) { + switch (j.vertical_position.reference.get()) { case TOP_OF_SCREEN: os << "top"; break; @@ -139,22 +140,22 @@ sub::dump (shared_ptr<const Reader> reader, ostream& os) os << "\t"; bool italic = false; bool underline = false; - for (list<sub::Block>::const_iterator k = j->blocks.begin(); k != j->blocks.end(); ++k) { - if (k->italic && !italic) { + for (auto const& k: j.blocks) { + if (k.italic && !italic) { os << "<i>"; - } else if (italic && !k->italic) { + } else if (italic && !k.italic) { os << "</i>"; } - if (k->underline && !underline) { + if (k.underline && !underline) { os << "<u>"; - } else if (underline && !k->underline) { + } else if (underline && !k.underline) { os << "</u>"; } - italic = k->italic; - underline = k->underline; + italic = k.italic; + underline = k.underline; - os << k->text; + os << k.text; } if (italic) { |
