2 Copyright (C) 2014-2021 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.
44 #include "exceptions.h"
55 * @brief A reference to an asset which is identified by a universally-unique identifier (UUID)
57 * This class is a `pointer' to a thing. It will always know the
58 * UUID of the thing, and it may have a shared_ptr to the C++ object
59 * which represents the thing.
61 * If the Ref does not have a shared_ptr it may be given one by
62 * calling resolve() with a vector of assets. The shared_ptr will be
63 * set up using any object on the vector which has a matching ID.
68 /** Initialise a Ref with an ID but no shared_ptr */
69 explicit Ref (std::string id)
73 /** Initialise a Ref with a shared_ptr to an asset */
74 explicit Ref (std::shared_ptr<Asset> asset)
79 /** Set the ID of this Ref */
80 void set_id (std::string id)
85 /** Look through a list of assets and copy a shared_ptr to any asset
86 * which matches the ID of this one
88 void resolve (std::vector<std::shared_ptr<Asset>> assets);
90 /** @return the ID of the thing that we are pointing to */
91 std::string id () const {
95 /** @return a shared_ptr to the thing; an UnresolvedRefError is thrown
96 * if the shared_ptr is not known
98 std::shared_ptr<Asset> asset () const {
100 throw UnresolvedRefError (_id);
106 /** operator-> to access the shared_ptr; an UnresolvedRefError is thrown
107 * if the shared_ptr is not known
109 Asset * operator->() const {
111 throw UnresolvedRefError (_id);
114 return _asset.get ();
117 /** @return true if a shared_ptr is known for this Ref */
118 bool resolved () const {
119 return static_cast<bool>(_asset);
123 std::string _id; ///< ID; will always be known
124 std::shared_ptr<Asset> _asset; ///< shared_ptr to the thing, may be null.