Use vector for the Ratings list.
[libdcp.git] / src / pkl.cc
index 236313aa67eeb855df33db99caa40235f62347fc..b2fe875be0e056b7cb833d7b03eb24558cf6866e 100644 (file)
 #include "exceptions.h"
 #include "util.h"
 #include "raw_convert.h"
+#include "dcp_assert.h"
 #include <libxml++/libxml++.h>
 #include <boost/foreach.hpp>
+#include <iostream>
 
 using std::string;
 using boost::shared_ptr;
+using boost::optional;
 using namespace dcp;
 
 static string const pkl_interop_ns = "http://www.digicine.com/PROTO-ASDCP-PKL-20040311#";
 static string const pkl_smpte_ns   = "http://www.smpte-ra.org/schemas/429-8/2007/PKL";
 
 PKL::PKL (boost::filesystem::path file)
+       : _file (file)
 {
        cxml::Document pkl ("PackingList");
        pkl.read_file (file);
@@ -106,9 +110,36 @@ PKL::write (boost::filesystem::path file, shared_ptr<const CertificateChain> sig
                asset->add_child("Type")->add_child_text (i->type);
        }
 
+       indent (pkl, 0);
+
        if (signer) {
                signer->sign (pkl, _standard);
        }
 
-       doc.write_to_file (file.string(), "UTF-8");
+       doc.write_to_file_formatted (file.string(), "UTF-8");
+       _file = file;
+}
+
+optional<string>
+PKL::hash (string id) const
+{
+       BOOST_FOREACH (shared_ptr<Asset> i, _asset_list) {
+               if (i->id() == id) {
+                       return i->hash;
+               }
+       }
+
+       return optional<string>();
+}
+
+optional<string>
+PKL::type (string id) const
+{
+       BOOST_FOREACH (shared_ptr<Asset> i, _asset_list) {
+               if (i->id() == id) {
+                       return i->type;
+               }
+       }
+
+       return optional<string>();
 }