Blender V5.0
asset_library_service.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <optional>
12#include <utility>
13
14#include "AS_asset_library.hh"
15
16#include "BLI_function_ref.hh"
17#include "BLI_map.hh"
18
19#include <memory>
20
23
24namespace blender::asset_system {
25
26class AllAssetLibrary;
29
44 static std::unique_ptr<AssetLibraryService> instance_;
45
51 using OnDiskLibraryIdentifier = std::pair<eAssetLibraryType, std::string>;
59 std::unique_ptr<RuntimeAssetLibrary> current_file_library_;
61 std::unique_ptr<AllAssetLibrary> all_library_;
62
64 bCallbackFuncStore on_load_callback_store_;
65 static bool atexit_handler_registered_;
66
67 public:
70
72 static AssetLibraryService *get();
73
75 static void destroy();
76
77 static std::string root_path_from_library_ref(const AssetLibraryReference &library_reference);
79 const AssetLibraryReference &library_reference);
81 const AssetWeakReference &asset_reference);
93
95 const AssetLibraryReference &library_reference);
96
122
134 const AssetWeakReference &asset_reference);
138 const AssetWeakReference &asset_reference);
146 std::string resolve_asset_weak_reference_to_full_path(const AssetWeakReference &asset_reference);
162
165 std::optional<ExplodedPath> resolve_asset_weak_reference_to_exploded_path(
166 const AssetWeakReference &asset_reference);
167
169 bool has_any_unsaved_catalogs() const;
170
173 bool include_all_library) const;
174
175 protected:
177 static void allocate_service_instance();
178
180
182
192 StringRefNull root_path,
193 bool load_catalogs = true,
194 bUserAssetLibrary *preferences_library = nullptr);
200};
201
202} // namespace blender::asset_system
eAssetLibraryType
long long int int64_t
void foreach_loaded_asset_library(FunctionRef< void(AssetLibrary &)> fn, bool include_all_library) const
AssetLibrary * get_asset_library_on_disk_builtin(eAssetLibraryType type, StringRefNull root_path)
AssetLibrary * get_asset_library_on_disk_custom_preferences(bUserAssetLibrary *custom_library)
AssetLibrary * get_asset_library(const Main *bmain, const AssetLibraryReference &library_reference)
AssetLibrary * find_loaded_on_disk_asset_library_from_name(StringRef name) const
static bUserAssetLibrary * find_custom_asset_library_from_library_ref(const AssetLibraryReference &library_reference)
OnDiskAssetLibrary * lookup_on_disk_library(eAssetLibraryType type, StringRefNull root_path)
std::optional< ExplodedPath > resolve_asset_weak_reference_to_exploded_path(const AssetWeakReference &asset_reference)
static AssetLibrary * move_runtime_current_file_into_on_disk_library(const Main &bmain)
std::string resolve_asset_weak_reference_to_full_path(const AssetWeakReference &asset_reference)
AssetLibrary * get_asset_library_on_disk_custom(StringRef name, StringRefNull root_path)
static std::string root_path_from_library_ref(const AssetLibraryReference &library_reference)
std::string normalize_asset_weak_reference_relative_asset_identifier(const AssetWeakReference &asset_reference)
static bUserAssetLibrary * find_custom_preferences_asset_library_from_asset_weak_ref(const AssetWeakReference &asset_reference)
std::string resolve_asset_weak_reference_to_library_path(const AssetWeakReference &asset_reference)
AssetLibrary * get_asset_library_on_disk(eAssetLibraryType library_type, StringRef name, StringRefNull root_path, bool load_catalogs=true, bUserAssetLibrary *preferences_library=nullptr)
AssetLibrary * get_asset_library_all(const Main *bmain)
const char * name