Rename crypt_chain -> signer_chain.
[libdcp.git] / src / parse / asset_map.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/asset_map.cc
21  *  @brief Classes used to parse a AssetMap.
22  */
23
24 #include <boost/algorithm/string.hpp>
25 #include "asset_map.h"
26 #include "../util.h"
27 #include "../xml.h"
28
29 using std::string;
30 using std::list;
31 using boost::shared_ptr;
32 using namespace libdcp::parse;
33
34 AssetMap::AssetMap (string file)
35 {
36         cxml::Document f ("AssetMap");
37         f.read_file (file);
38
39         id = f.string_child ("Id");
40         creator = f.string_child ("Creator");
41         volume_count = f.number_child<int64_t> ("VolumeCount");
42         issue_date = f.string_child ("IssueDate");
43         issuer = f.string_child ("Issuer");
44         assets = type_grand_children<AssetMapAsset> (f, "AssetList", "Asset");
45 }
46
47 AssetMapAsset::AssetMapAsset (shared_ptr<const cxml::Node> node)
48 {
49         id = node->string_child ("Id");
50         packing_list = node->optional_string_child ("PackingList").get_value_or ("");
51         chunks = type_grand_children<Chunk> (node, "ChunkList", "Chunk");
52 }
53
54 Chunk::Chunk (shared_ptr<const cxml::Node> node)
55 {
56         path = node->string_child ("Path");
57
58         string const prefix = "file://";
59
60         if (boost::algorithm::starts_with (path, prefix)) {
61                 path = path.substr (prefix.length());
62         }
63         
64         volume_index = node->optional_number_child<int64_t> ("VolumeIndex").get_value_or (0);
65         offset = node->optional_number_child<int64_t> ("Offset").get_value_or (0);
66         length = node->optional_number_child<int64_t> ("Length").get_value_or (0);
67 }
68
69 shared_ptr<AssetMapAsset>
70 AssetMap::asset_from_id (string id) const
71 {
72         for (list<shared_ptr<AssetMapAsset> >::const_iterator i = assets.begin (); i != assets.end(); ++i) {
73                 if ((*i)->id == id) {
74                         return *i;
75                 }
76         }
77
78         return shared_ptr<AssetMapAsset> ();
79 }