diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-07-21 11:56:23 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-07-21 11:56:23 +0100 |
| commit | 5ec26979d2547b7444c4e1f00aa76d86d22f4c84 (patch) | |
| tree | b3e3088c950fcbc5c3ca8433da9c5735398509e7 /src | |
| parent | 8df04daf3f2ccb6950afcc4abac7eb3100799774 (diff) | |
Return title number from dvd_titles().
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/copy_from_dvd_job.cc | 10 | ||||
| -rw-r--r-- | src/lib/dvd.cc | 31 | ||||
| -rw-r--r-- | src/lib/dvd.h | 14 |
3 files changed, 42 insertions, 13 deletions
diff --git a/src/lib/copy_from_dvd_job.cc b/src/lib/copy_from_dvd_job.cc index b82169ad1..55259eb1e 100644 --- a/src/lib/copy_from_dvd_job.cc +++ b/src/lib/copy_from_dvd_job.cc @@ -58,7 +58,7 @@ CopyFromDVDJob::run () set_state (FINISHED_ERROR); } - vector<uint64_t> const t = dvd_titles (dvd); + list<DVDTitle> const t = dvd_titles (dvd); if (t.empty ()) { set_error ("no titles found on DVD"); set_state (FINISHED_ERROR); @@ -66,10 +66,10 @@ CopyFromDVDJob::run () int longest_title = 0; uint64_t longest_size = 0; - for (vector<int>::size_type i = 0; i < t.size(); ++i) { - if (longest_size < t[i]) { - longest_size = t[i]; - longest_title = i; + for (list<DVDTitle>::const_iterator i = t.begin(); i != t.end(); ++i) { + if (longest_size < i->size) { + longest_size = i->size; + longest_title = i->number; } } diff --git a/src/lib/dvd.cc b/src/lib/dvd.cc index 629ba1ac8..19b59b588 100644 --- a/src/lib/dvd.cc +++ b/src/lib/dvd.cc @@ -20,6 +20,7 @@ #include <fstream> #include <boost/filesystem.hpp> #include <boost/algorithm/string.hpp> +#include "dvd.h" using namespace std; using namespace boost; @@ -42,13 +43,13 @@ find_dvd () return ""; } -vector<uint64_t> +list<DVDTitle> dvd_titles (string dvd) { filesystem::path video (dvd); video /= "VIDEO_TS"; - vector<uint64_t> sizes; + list<DVDTitle> titles; for (filesystem::directory_iterator i = filesystem::directory_iterator (video); i != filesystem::directory_iterator(); ++i) { #if BOOST_FILESYSTEM_VERSION == 3 @@ -63,16 +64,32 @@ dvd_titles (string dvd) if (p.size() == 4) { int const a = atoi (p[1].c_str ()); int const b = atoi (p[2].c_str ()); - while (a >= int (sizes.size())) { - sizes.push_back (0); + if (b == 0) { + continue; } - if (b > 0) { - sizes[a] += size; + list<DVDTitle>::iterator j = titles.begin (); + while (j != titles.end() && j->number != a) { + ++j; + } + + if (j == titles.end ()) { + titles.push_back (DVDTitle (a, size)); + } else { + j->size += size; } } } } + + titles.sort (); - return sizes; + return titles; +} + + +bool +operator< (DVDTitle const & a, DVDTitle const & b) +{ + return a.number < b.number; } diff --git a/src/lib/dvd.h b/src/lib/dvd.h index 170472121..d3f6043ce 100644 --- a/src/lib/dvd.h +++ b/src/lib/dvd.h @@ -17,5 +17,17 @@ */ -extern std::vector<uint64_t> dvd_titles (std::string); +class DVDTitle +{ +public: + DVDTitle () : number (-1), size (0) {} + DVDTitle (int n, int s) : number (n), size (s) {} + + int number; + uint64_t size; +}; + +extern bool operator< (DVDTitle const &, DVDTitle const &); + +extern std::list<DVDTitle> dvd_titles (std::string); extern std::string find_dvd (); |
