2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 /** @file src/asset_map.cc
21 * @brief Classes used to parse a AssetMap.
24 #include <boost/algorithm/string.hpp>
25 #include "asset_map.h"
31 using boost::shared_ptr;
32 using namespace libdcp::parse;
34 AssetMap::AssetMap (string file)
36 cxml::Document f ("AssetMap");
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");
47 AssetMapAsset::AssetMapAsset (shared_ptr<const cxml::Node> node)
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");
54 Chunk::Chunk (shared_ptr<const cxml::Node> node)
56 path = node->string_child ("Path");
58 string const prefix = "file://";
60 if (boost::algorithm::starts_with (path, prefix)) {
61 path = path.substr (prefix.length());
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);
69 shared_ptr<AssetMapAsset>
70 AssetMap::asset_from_id (string id) const
72 for (list<shared_ptr<AssetMapAsset> >::const_iterator i = assets.begin (); i != assets.end(); ++i) {
78 return shared_ptr<AssetMapAsset> ();