blob: 0297e35c18c85278774aa96d2a5d1abf64a488d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup bke
*/
#pragma once
#include <memory>
#include <string>
#include "BLI_string_ref.hh"
struct AssetMetaData;
struct ID;
namespace blender::bke {
/**
* \brief Abstraction to reference an asset, with necessary data for display & interaction.
*
* #AssetRepresentation is the data-structure to store information about a single asset. It doesn't
* contain the asset itself, but information like the metadata and preview, as well as methods to
* interact with them. Think of it like a view on an asset.
*/
class AssetRepresentation {
friend class AssetLibrary;
struct ExternalAsset {
std::string name;
std::unique_ptr<AssetMetaData> metadata_ = nullptr;
};
/** Indicate if this is a local or external asset, and as such, which of the union members below
* should be used. */
const bool is_local_id_ = false;
union {
ExternalAsset external_asset_;
ID *local_asset_id_ = nullptr; /* Non-owning. */
};
public:
/** Constructs an asset representation for an external ID. The asset will not be editable. */
explicit AssetRepresentation(StringRef name, std::unique_ptr<AssetMetaData> metadata);
/** Constructs an asset representation for an ID stored in the current file. This makes the asset
* local and fully editable. */
explicit AssetRepresentation(ID &id);
AssetRepresentation(AssetRepresentation &&other);
/* Non-copyable type. */
AssetRepresentation(const AssetRepresentation &other) = delete;
~AssetRepresentation();
/* Non-move-assignable type. Move construction is fine, but treat the "identity" (e.g. local vs
* external asset) of an asset representation as immutable. */
AssetRepresentation &operator=(AssetRepresentation &&other) = delete;
/* Non-copyable type. */
AssetRepresentation &operator=(const AssetRepresentation &other) = delete;
StringRefNull get_name() const;
AssetMetaData &get_metadata() const;
/** Returns if this asset is stored inside this current file, and as such fully editable. */
bool is_local_id() const;
};
} // namespace blender::bke
|