More licence fixups.
[libdcp.git] / src / asset.h
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /** @file  src/asset.h
21  *  @brief Asset class.
22  */
23
24 #ifndef LIBDCP_ASSET_H
25 #define LIBDCP_ASSET_H
26
27 #include "object.h"
28 #include "types.h"
29 #include <boost/filesystem.hpp>
30 #include <boost/function.hpp>
31 #include <boost/bind.hpp>
32
33 namespace xmlpp {
34         class Node;
35 }
36
37 struct asset_test;
38
39 namespace dcp {
40
41 /** @class Asset
42  *  @brief Parent class for DCP assets, i.e. picture, sound, subtitles, CPLs, fonts.
43  *
44  *  Note that this class is not used for ReelAssets; those are just for the metadata
45  *  that gets put into &lt;Reel&gt;s.
46  */
47 class Asset : public Object
48 {
49 public:
50         Asset ();
51         Asset (boost::filesystem::path file);
52         Asset (std::string id, boost::filesystem::path file);
53
54         virtual bool equals (
55                 boost::shared_ptr<const Asset> other,
56                 EqualityOptions opt,
57                 NoteHandler note
58                 ) const;
59
60         /** Write details of the asset to a ASSETMAP.
61          *  @param node Parent node.
62          */
63         void write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const;
64
65         /** Write details of the asset to a PKL AssetList node.
66          *  @param node Parent node.
67          *  @param standard Standard to use.
68          */
69         void write_to_pkl (xmlpp::Node* node, boost::filesystem::path root, Standard standard) const;
70
71         /** @return the most recent disk file used to read or write this asset; may be empty */
72         boost::filesystem::path file () const {
73                 return _file;
74         }
75
76         void set_file (boost::filesystem::path file) const;
77
78         /** @return the hash of this asset's file */
79         std::string hash (boost::function<void (float)> progress = 0) const;
80
81 protected:
82         friend struct ::asset_test;
83
84         virtual std::string pkl_type (Standard standard) const = 0;
85
86         /** The most recent disk file used to read or write this asset; may be empty */
87         mutable boost::filesystem::path _file;
88         /** Hash of _file, or empty if the hash has not yet been computed */
89         mutable std::string _hash;
90 };
91
92 }
93
94 #endif