f9ec949f662c4b48d5e5d5fe0e05c921e71290b0
[libdcp.git] / src / asset.h
1 /*
2     Copyright (C) 2014 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.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
32 namespace xmlpp {
33         class Node;
34 }
35
36 namespace dcp {
37
38 /** @class Asset
39  *  @brief Parent class for DCP assets, i.e. picture/sound/subtitles and CPLs.
40  *
41  *  Note that this class is not used for ReelAssets; those are just for the metadata
42  *  that gets put into &lt;Reel&gt;s.
43  */
44 class Asset : public Object
45 {
46 public:
47         Asset ();
48         Asset (boost::filesystem::path file);
49         Asset (std::string id);
50
51         virtual std::string pkl_type () const = 0;
52         virtual bool equals (
53                 boost::shared_ptr<const Asset> other,
54                 EqualityOptions opt,
55                 boost::function<void (NoteType, std::string)> note
56                 ) const;
57
58         /** Write details of the asset to a ASSETMAP.
59          *  @param node Parent node.
60          */
61         void write_to_assetmap (xmlpp::Node* node) const;
62
63         /** Write details of the asset to a PKL AssetList node.
64          *  @param node Parent node.
65          */
66         void write_to_pkl (xmlpp::Node* node) const;
67
68         boost::filesystem::path file () const {
69                 return _file;
70         }
71
72         void set_file (boost::filesystem::path file) const {
73                 _file = file;
74                 _hash.clear ();
75         }
76
77         /** @return the hash of this asset's file.  It will be
78          *  computed by this call if necessary.
79          */
80         std::string hash () const;
81
82 protected:
83         /** The disk file that represents this asset, if one exists */
84         mutable boost::filesystem::path _file;
85         /** Hash of _file, or empty if the hash has not yet been computed */
86         mutable std::string _hash;
87 };
88
89 }
90
91 #endif