X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdcpomatic_time_coalesce.h;h=015326bdd7b73d4f9a5550a8606a1f8439b5167f;hb=0bec279f5e942927665fd6e4f310595823197151;hp=e103e80e67750947a35dfdc403af5183959f875f;hpb=baf84885a777378b9ff5c05ef24d6361560822a6;p=dcpomatic.git diff --git a/src/lib/dcpomatic_time_coalesce.h b/src/lib/dcpomatic_time_coalesce.h index e103e80e6..015326bdd 100644 --- a/src/lib/dcpomatic_time_coalesce.h +++ b/src/lib/dcpomatic_time_coalesce.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2017 Carl Hetherington + Copyright (C) 2017-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,23 +18,28 @@ */ + #include "dcpomatic_time.h" #include + +namespace dcpomatic { + + /** @param periods Set of periods in ascending order of from time */ template -std::list > coalesce (std::list > periods) +std::list> coalesce (std::list> periods) { bool did_something; - std::list > coalesced; + std::list> coalesced; do { coalesced.clear (); did_something = false; - for (typename std::list >::const_iterator i = periods.begin(); i != periods.end(); ++i) { - typename std::list >::const_iterator j = i; + for (auto i = periods.begin(); i != periods.end(); ++i) { + auto j = i; ++j; if (j != periods.end() && (i->overlap(*j) || i->to == j->from)) { - coalesced.push_back (TimePeriod (i->from, j->to)); + coalesced.push_back(TimePeriod(std::min(i->from, j->from), std::max(i->to, j->to))); did_something = true; ++i; } else { @@ -46,3 +51,6 @@ std::list > coalesce (std::list > periods) return periods; } + + +}