diff options
author | Martijn Versteegh <blender@aaltjegron.nl> | 2022-11-11 21:44:16 +0300 |
---|---|---|
committer | Martijn Versteegh <blender@aaltjegron.nl> | 2022-11-11 21:44:16 +0300 |
commit | b4757873bf1c2fb5e3f858a085af62359d3c1b3f (patch) | |
tree | 98d4407723ef2816334d06cd79388c0d7b2d708c /source/blender/blenkernel/BKE_asset_representation.hh | |
parent | 62effd6791858221392ff7b92104a22ed44ebf7d (diff) | |
parent | 2c596319a4888aa40bfdf41f9ea5d446179141d0 (diff) |
Merge branch 'master' into refactor-mesh-uv-map-generic
Diffstat (limited to 'source/blender/blenkernel/BKE_asset_representation.hh')
-rw-r--r-- | source/blender/blenkernel/BKE_asset_representation.hh | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_asset_representation.hh b/source/blender/blenkernel/BKE_asset_representation.hh new file mode 100644 index 00000000000..edaa5a203ba --- /dev/null +++ b/source/blender/blenkernel/BKE_asset_representation.hh @@ -0,0 +1,64 @@ +/* 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. + * + * https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Asset_Representation + */ +class AssetRepresentation { + friend struct 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 |