Merge master
[libdcp.git] / src / asset.h
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.h
21  *  @brief Parent class for assets of DCPs.
22  */
23
24 #ifndef LIBDCP_ASSET_H
25 #define LIBDCP_ASSET_H
26
27 #include <string>
28 #include <list>
29 #include <boost/filesystem.hpp>
30 #include "types.h"
31
32 namespace ASDCP {
33         class WriterInfo;
34 }
35
36 namespace xmlpp {
37         class Element;
38 }
39
40 namespace libdcp
41 {
42
43 /** @brief Parent class for assets of DCPs
44  *
45  *  These are collections of pictures or sound.
46  */
47 class Asset
48 {
49 public:
50         /** Construct an Asset.
51          *  @param directory Directory where our XML or MXF file is.
52          *  @param file_name Name of our file within directory, or empty to make one up based on UUID.
53          */
54         Asset (std::string directory, std::string file_name = "");
55
56         virtual ~Asset() {}
57
58         /** Write details of the asset to a CPL AssetList node.
59          *  @param p Parent node.
60          */
61         virtual void write_to_cpl (xmlpp::Element* p) const = 0;
62
63         /** Write details of the asset to a PKL AssetList node.
64          *  @param p Parent node.
65          */
66         void write_to_pkl (xmlpp::Element* p) const;
67
68         /** Write details of the asset to a ASSETMAP stream.
69          *  @param s Stream.
70          */
71         void write_to_assetmap (std::ostream& s) const;
72
73         std::string uuid () const {
74                 return _uuid;
75         }
76
77         virtual bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const = 0;
78
79 protected:
80         friend class PictureAsset;
81         friend class SoundAsset;
82         
83         std::string digest () const;
84         boost::filesystem::path path () const;
85
86         /** Directory that our MXF or XML file is in */
87         std::string _directory;
88         /** Name of our MXF or XML file */
89         std::string _file_name;
90         /** Our UUID */
91         std::string _uuid;
92
93 private:        
94         /** Digest of our MXF or XML file */
95         mutable std::string _digest;
96 };
97
98 }
99
100 #endif