summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-05-16 21:37:53 +0200
committerCarl Hetherington <cth@carlh.net>2022-05-16 21:39:25 +0200
commiteaee1cd5601a93037bc2fb0956b99b12fe1f90e6 (patch)
tree7c3a056b48088063c4bf6cdad593886ec84ee41e /src
parent08d79750db92d0ab381fbf657307c7c21fe8110a (diff)
Add overlap() for lists of time periods.
Diffstat (limited to 'src')
-rw-r--r--src/lib/dcpomatic_time_overlap.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/lib/dcpomatic_time_overlap.h b/src/lib/dcpomatic_time_overlap.h
new file mode 100644
index 000000000..dabeb98f3
--- /dev/null
+++ b/src/lib/dcpomatic_time_overlap.h
@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "dcpomatic_time.h"
+#include "dcpomatic_time_coalesce.h"
+
+
+namespace dcpomatic {
+
+
+template <class T>
+std::list<TimePeriod<T>> overlap (std::list<TimePeriod<T>> const & A, std::list<TimePeriod<T>> const& B)
+{
+ std::list<TimePeriod<T>> result;
+
+ for (auto i: A) {
+ for (auto j: B) {
+ if (auto ov = i.overlap(j)) {
+ result.push_back(*ov);
+ }
+ }
+ }
+
+ return coalesce (result);
+}
+
+
+}
+