From cafee6f81257fa81ee302b5d3ffa82213a0a6a44 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 13 Jan 2021 13:04:04 +0100 Subject: [PATCH] Replace list with vector in most of the API. --- src/collect.h | 16 ++++---- src/dcp_reader.cc | 1 - src/exceptions.cc | 4 +- src/exceptions.h | 5 ++- src/raw_subtitle.h | 2 +- src/reader.h | 8 ++-- src/ssa_reader.cc | 5 +-- src/ssa_reader.h | 2 +- src/stl_binary_writer.cc | 10 ++--- src/stl_binary_writer.h | 2 +- src/stl_text_reader.cc | 1 - src/subrip_reader.cc | 3 +- src/subrip_reader.h | 1 + src/subtitle.h | 6 +-- src/util.cc | 45 +++++++++++----------- test/dcp_reader_test.cc | 70 +++++++++++++++++----------------- test/dcp_to_stl_binary_test.cc | 20 +++++----- test/ssa_reader_test.cc | 66 ++++++++++++++++---------------- test/stl_binary_reader_test.cc | 1 - test/stl_binary_writer_test.cc | 6 +-- test/stl_text_reader_test.cc | 11 +++--- test/subrip_reader_test.cc | 29 +++++++------- tools/dumpsubs.cc | 1 - 23 files changed, 154 insertions(+), 161 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 T -collect (std::list raw) +collect (std::vector raw) { - raw.sort (); + std::stable_sort (raw.begin(), raw.end()); T out; boost::optional current; - for (std::list::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 #include -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 + Copyright (C) 2014-2021 Carl Hetherington 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 -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 + Copyright (C) 2014-2021 Carl Hetherington 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 #include #include -#include +#include 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 #include -#include +#include 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 + Copyright (C) 2014-2021 Carl Hetherington 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 #include #include +#include struct subrip_reader_convert_line_test; @@ -37,7 +37,7 @@ class Reader public: virtual ~Reader () {} - std::list subtitles () const { + std::vector subtitles () const { return _subs; } @@ -50,7 +50,7 @@ protected: void warn (std::string) const; - std::list _subs; + std::vector _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 +vector 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 subs; + vector 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 parse_line (RawSubtitle base, std::string line, int play_res_x, int play_res_y); + static std::vector 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 #include #include -#include #include #include -#include #include #include +#include -using std::list; using std::set; using std::ofstream; using std::string; @@ -149,7 +147,7 @@ vertical_position (sub::Line const & line) } vector -make_tti_blocks (list const& subtitles, STLBinaryTables const& tables, float frames_per_second) +make_tti_blocks (vector const& subtitles, STLBinaryTables const& tables, float frames_per_second) { static int const tti_size = 128; vector tti; @@ -287,9 +285,9 @@ make_tti_blocks (list 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 subtitles, + vector 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 subtitles, + std::vector 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 #include -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 colours; + vector colours; colours.push_back (Colour (1, 1, 1)); /* XXX: missing 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 +#include 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 #include -#include +#include namespace sub { @@ -90,7 +90,7 @@ public: /** vertical position of the baseline of the text */ VerticalPosition vertical_position; - std::list blocks; + std::vector blocks; bool same_metadata (RawSubtitle) const; }; @@ -120,7 +120,7 @@ public: boost::optional