2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
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.
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.
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/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
41 #include "exceptions.h"
44 #include <boost/shared_ptr.hpp>
50 * @brief A reference to an asset which is identified by a universally-unique identifier (UUID).
52 * This class is a `pointer' to a thing. It will always know the
53 * UUID of the thing, and it may have a shared_ptr to the C++ object
54 * which represents the thing.
56 * If the Ref does not have a shared_ptr it may be given one by
57 * calling resolve() with a list of assets. The shared_ptr will be
58 * set up using any object on the list which has a matching ID.
63 /** Initialise a Ref with an ID but no shared_ptr */
64 explicit Ref (std::string id)
68 /** Initialise a Ref with a shared_ptr to an asset */
69 explicit Ref (boost::shared_ptr<Asset> asset)
74 /** Set the ID of this Ref */
75 void set_id (std::string id)
80 void resolve (std::list<boost::shared_ptr<Asset> > assets);
82 /** @return the ID of the thing that we are pointing to */
83 std::string id () const {
87 /** @return a shared_ptr to the thing; an UnresolvedRefError is thrown
88 * if the shared_ptr is not known.
90 boost::shared_ptr<Asset> asset () const {
92 throw UnresolvedRefError (_id);
98 /** operator-> to access the shared_ptr; an UnresolvedRefError is thrown
99 * if the shared_ptr is not known.
101 Asset * operator->() const {
103 throw UnresolvedRefError (_id);
106 return _asset.get ();
109 /** @return true if a shared_ptr is known for this Ref */
110 bool resolved () const {
111 return static_cast<bool>(_asset);
115 std::string _id; ///< ID; will always be known
116 boost::shared_ptr<Asset> _asset; ///< shared_ptr to the thing, may be null.