Fix erroneous reports of unresolved assets when checking OV/VF pairs.
[libdcp.git] / src / types.cc
index 0347d02f15cc7f68df9f67f4cf282682f1f3cebf..89b9de5503ef578770cefe9df03bded019698a38 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
@@ -35,6 +35,7 @@
 #include "types.h"
 #include "exceptions.h"
 #include "compose.hpp"
+#include "dcp_assert.h"
 #include <boost/algorithm/string.hpp>
 #include <vector>
 #include <cstdio>
@@ -44,6 +45,22 @@ using namespace std;
 using namespace dcp;
 using namespace boost;
 
+bool dcp::operator== (dcp::Size const & a, dcp::Size const & b)
+{
+       return (a.width == b.width && a.height == b.height);
+}
+
+bool dcp::operator!= (dcp::Size const & a, dcp::Size const & b)
+{
+       return !(a == b);
+}
+
+ostream& dcp::operator<< (ostream& s, dcp::Size const & a)
+{
+       s << a.width << "x" << a.height;
+       return s;
+}
+
 /** Construct a Fraction from a string of the form <numerator> <denominator>
  *  e.g. "1 3".
  */
@@ -283,3 +300,80 @@ dcp::string_to_direction (string s)
 
        boost::throw_exception (DCPReadError ("unknown subtitle direction type"));
 }
+
+/** Convert a content kind to a string which can be used in a
+ *  &lt;ContentKind&gt; node.
+ *  @param kind ContentKind.
+ *  @return string.
+ */
+string
+dcp::content_kind_to_string (ContentKind kind)
+{
+       switch (kind) {
+       case FEATURE:
+               return "feature";
+       case SHORT:
+               return "short";
+       case TRAILER:
+               return "trailer";
+       case TEST:
+               return "test";
+       case TRANSITIONAL:
+               return "transitional";
+       case RATING:
+               return "rating";
+       case TEASER:
+               return "teaser";
+       case POLICY:
+               return "policy";
+       case PUBLIC_SERVICE_ANNOUNCEMENT:
+               return "psa";
+       case ADVERTISEMENT:
+               return "advertisement";
+       case EPISODE:
+               return "episode";
+       case PROMO:
+               return "promo";
+       }
+
+       DCP_ASSERT (false);
+}
+
+/** Convert a string from a &lt;ContentKind&gt; node to a libdcp ContentKind.
+ *  Reasonably tolerant about varying case.
+ *  @param kind Content kind string.
+ *  @return libdcp ContentKind.
+ */
+dcp::ContentKind
+dcp::content_kind_from_string (string kind)
+{
+       transform (kind.begin(), kind.end(), kind.begin(), ::tolower);
+
+       if (kind == "feature") {
+               return FEATURE;
+       } else if (kind == "short") {
+               return SHORT;
+       } else if (kind == "trailer") {
+               return TRAILER;
+       } else if (kind == "test") {
+               return TEST;
+       } else if (kind == "transitional") {
+               return TRANSITIONAL;
+       } else if (kind == "rating") {
+               return RATING;
+       } else if (kind == "teaser") {
+               return TEASER;
+       } else if (kind == "policy") {
+               return POLICY;
+       } else if (kind == "psa") {
+               return PUBLIC_SERVICE_ANNOUNCEMENT;
+       } else if (kind == "advertisement") {
+               return ADVERTISEMENT;
+       } else if (kind == "episode") {
+               return EPISODE;
+       } else if (kind == "promo") {
+               return PROMO;
+       }
+
+       throw BadContentKindError (kind);
+}