Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-07-19 19:26:10 +0300
committerJulian Eisel <julian@blender.org>2021-07-19 19:28:27 +0300
commit582c5530b6205e0cb98595733d86043a6672cd91 (patch)
treef29f390ac4c39a10cde6d6f54157b94ad8d8d600 /source/blender/editors/asset/asset_list.cc
parentebe32e01e197070bb0215868e9ac7d858864de6c (diff)
Cleanup: Move asset library reference C++ wrapper to own files
Although currently only the asset list code uses the asset library reference wrapper, it can stand on its own and may be used in more places in the future. So I prefer to give it its own source & header file. Also removed unused includes, added proper namespaces as per our C++ style guidelines, and removed an unnecessary TODO comment.
Diffstat (limited to 'source/blender/editors/asset/asset_list.cc')
-rw-r--r--source/blender/editors/asset/asset_list.cc53
1 files changed, 6 insertions, 47 deletions
diff --git a/source/blender/editors/asset/asset_list.cc b/source/blender/editors/asset/asset_list.cc
index dd1c5f360a0..d9c1c6d862e 100644
--- a/source/blender/editors/asset/asset_list.cc
+++ b/source/blender/editors/asset/asset_list.cc
@@ -26,12 +26,8 @@
#include <optional>
#include <string>
-#include "BKE_asset.h"
#include "BKE_context.h"
-#include "BKE_screen.h"
-#include "BLI_function_ref.hh"
-#include "BLI_hash.hh"
#include "BLI_map.hh"
#include "BLI_path_util.h"
#include "BLI_utility_mixins.hh"
@@ -43,7 +39,6 @@
#include "ED_asset.h"
#include "ED_fileselect.h"
-#include "ED_screen.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -51,48 +46,9 @@
/* XXX uses private header of file-space. */
#include "../space_file/filelist.h"
-using namespace blender;
+#include "intern/asset_library_reference.hh"
-/**
- * Wrapper to add logic to the AssetLibraryReference DNA struct.
- */
-class AssetLibraryReferenceWrapper {
- const AssetLibraryReference reference_;
-
- public:
- /* Intentionally not `explicit`, allow implicit conversion for convenience. Might have to be
- * NOLINT */
- AssetLibraryReferenceWrapper(const AssetLibraryReference &reference);
- ~AssetLibraryReferenceWrapper() = default;
-
- friend bool operator==(const AssetLibraryReferenceWrapper &a,
- const AssetLibraryReferenceWrapper &b);
- uint64_t hash() const;
-};
-
-AssetLibraryReferenceWrapper::AssetLibraryReferenceWrapper(const AssetLibraryReference &reference)
- : reference_(reference)
-{
-}
-
-bool operator==(const AssetLibraryReferenceWrapper &a, const AssetLibraryReferenceWrapper &b)
-{
- return (a.reference_.type == b.reference_.type) && (a.reference_.type == ASSET_LIBRARY_CUSTOM) ?
- (a.reference_.custom_library_index == b.reference_.custom_library_index) :
- true;
-}
-
-uint64_t AssetLibraryReferenceWrapper::hash() const
-{
- uint64_t hash1 = DefaultHash<decltype(reference_.type)>{}(reference_.type);
- if (reference_.type != ASSET_LIBRARY_CUSTOM) {
- return hash1;
- }
-
- uint64_t hash2 = DefaultHash<decltype(reference_.custom_library_index)>{}(
- reference_.custom_library_index);
- return hash1 ^ (hash2 * 33); /* Copied from DefaultHash for std::pair. */
-}
+namespace blender::ed::asset {
/* -------------------------------------------------------------------- */
/** \name Asset list API
@@ -469,10 +425,14 @@ AssetListStorage::AssetListMap &AssetListStorage::global_storage()
/** \} */
+} // namespace blender::ed::asset
+
/* -------------------------------------------------------------------- */
/** \name C-API
* \{ */
+using namespace blender::ed::asset;
+
/**
* Invoke asset list reading, potentially in a parallel job. Won't wait until the job is done,
* and may return earlier.
@@ -506,7 +466,6 @@ bool ED_assetlist_storage_has_list_for_library(const AssetLibraryReference *libr
return AssetListStorage::lookup_list(*library_reference) != nullptr;
}
-/* TODO expose AssetList with an iterator? */
void ED_assetlist_iterate(const AssetLibraryReference *library_reference, AssetListIterFn fn)
{
AssetList *list = AssetListStorage::lookup_list(*library_reference);