2 Copyright (C) 2014 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.cc
26 #include <libxml++/libxml++.h>
27 #include <boost/lexical_cast.hpp>
30 using boost::lexical_cast;
31 using boost::function;
34 /** Create an Asset with a randomly-generated ID */
40 /** Create an Asset from a given file. The ID will
41 * be extracted from the file.
42 * @param file File name.
44 Asset::Asset (boost::filesystem::path file)
50 /** Create an Asset with a specified ID.
51 * @param id ID to use.
53 Asset::Asset (string id)
60 Asset::write_to_pkl (xmlpp::Node* node) const
62 assert (!_file.empty ());
64 xmlpp::Node* asset = node->add_child ("Asset");
65 asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
66 asset->add_child("AnnotationText")->add_child_text (_id);
67 asset->add_child("Hash")->add_child_text (hash ());
68 asset->add_child("Size")->add_child_text (lexical_cast<string> (boost::filesystem::file_size (_file)));
69 asset->add_child("Type")->add_child_text (pkl_type ());
73 Asset::write_to_assetmap (xmlpp::Node* node) const
75 assert (!_file.empty ());
77 xmlpp::Node* asset = node->add_child ("Asset");
78 asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
79 xmlpp::Node* chunk_list = asset->add_child ("ChunkList");
80 xmlpp::Node* chunk = chunk_list->add_child ("Chunk");
81 chunk->add_child("Path")->add_child_text (_file.string ());
82 chunk->add_child("VolumeIndex")->add_child_text ("1");
83 chunk->add_child("Offset")->add_child_text ("0");
84 chunk->add_child("Length")->add_child_text (lexical_cast<string> (boost::filesystem::file_size (_file)));
90 assert (!_file.empty ());
92 if (!_hash.empty ()) {
93 _hash = make_digest (_file, 0);
100 Asset::equals (boost::shared_ptr<const Asset> other, EqualityOptions, function<void (NoteType, string)> note) const
102 if (_hash != other->_hash) {
103 note (ERROR, "Asset hashes differ");