Add ContentVersion class.
[libdcp.git] / src / types.cc
index d27b2ec186ece6773d0646309040927b2afd0eae..746b6f6a81e234385225cbec68891448dc478132 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.
 
@@ -36,6 +36,7 @@
 #include "exceptions.h"
 #include "compose.hpp"
 #include "dcp_assert.h"
+#include <libxml++/libxml++.h>
 #include <boost/algorithm/string.hpp>
 #include <vector>
 #include <cstdio>
@@ -207,7 +208,7 @@ dcp::string_to_effect (string s)
                return SHADOW;
        }
 
-       boost::throw_exception (DCPReadError ("unknown subtitle effect type"));
+       boost::throw_exception (ReadError ("unknown subtitle effect type"));
 }
 
 string
@@ -236,7 +237,7 @@ dcp::string_to_halign (string s)
                return HALIGN_RIGHT;
        }
 
-       boost::throw_exception (DCPReadError ("unknown subtitle halign type"));
+       boost::throw_exception (ReadError ("unknown subtitle halign type"));
 }
 
 string
@@ -265,7 +266,7 @@ dcp::string_to_valign (string s)
                return VALIGN_BOTTOM;
        }
 
-       boost::throw_exception (DCPReadError ("unknown subtitle valign type"));
+       boost::throw_exception (ReadError ("unknown subtitle valign type"));
 }
 
 string
@@ -298,7 +299,7 @@ dcp::string_to_direction (string s)
                return DIRECTION_BTT;
        }
 
-       boost::throw_exception (DCPReadError ("unknown subtitle direction type"));
+       boost::throw_exception (ReadError ("unknown subtitle direction type"));
 }
 
 /** Convert a content kind to a string which can be used in a
@@ -330,6 +331,10 @@ dcp::content_kind_to_string (ContentKind kind)
                return "psa";
        case ADVERTISEMENT:
                return "advertisement";
+       case EPISODE:
+               return "episode";
+       case PROMO:
+               return "promo";
        }
 
        DCP_ASSERT (false);
@@ -365,6 +370,10 @@ dcp::content_kind_from_string (string kind)
                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);
@@ -426,3 +435,40 @@ dcp::marker_from_string (string s)
 
        DCP_ASSERT (false);
 }
+
+Rating::Rating (cxml::ConstNodePtr node)
+{
+       agency = node->string_child("Agency");
+       label = node->string_child("Label");
+       node->done ();
+}
+
+void
+Rating::as_xml (xmlpp::Element* parent) const
+{
+       parent->add_child("Agency")->add_child_text(agency);
+       parent->add_child("Label")->add_child_text(label);
+}
+
+bool
+dcp::operator== (Rating const & a, Rating const & b)
+{
+       return a.agency == b.agency && a.label == b.label;
+}
+
+ostream &
+dcp::operator<< (ostream& s, Rating const & r)
+{
+       s << r.agency << " " << r.label;
+       return s;
+}
+
+
+void
+ContentVersion::as_xml (xmlpp::Element* parent) const
+{
+       xmlpp::Node* cv = parent->add_child("ContentVersion");
+       cv->add_child("Id")->add_child_text(id);
+       cv->add_child("LabelText")->add_child_text(label_text);
+}
+