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
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.
-rw-r--r--source/blender/editors/asset/CMakeLists.txt3
-rw-r--r--source/blender/editors/asset/asset_list.cc53
-rw-r--r--source/blender/editors/asset/intern/asset_library_reference.cc46
-rw-r--r--source/blender/editors/asset/intern/asset_library_reference.hh46
4 files changed, 101 insertions, 47 deletions
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt
index a27975bc37b..fb727e686fc 100644
--- a/source/blender/editors/asset/CMakeLists.txt
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -34,6 +34,9 @@ set(SRC
asset_list.cc
asset_ops.cc
asset_temp_id_consumer.cc
+ intern/asset_library_reference.cc
+
+ intern/asset_library_reference.hh
)
set(LIB
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);
diff --git a/source/blender/editors/asset/intern/asset_library_reference.cc b/source/blender/editors/asset/intern/asset_library_reference.cc
new file mode 100644
index 00000000000..246f304dc20
--- /dev/null
+++ b/source/blender/editors/asset/intern/asset_library_reference.cc
@@ -0,0 +1,46 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "BLI_hash.hh"
+
+#include "asset_library_reference.hh"
+
+namespace blender::ed::asset {
+
+AssetLibraryReferenceWrapper::AssetLibraryReferenceWrapper(const AssetLibraryReference &reference)
+ : AssetLibraryReference(reference)
+{
+}
+
+bool operator==(const AssetLibraryReferenceWrapper &a, const AssetLibraryReferenceWrapper &b)
+{
+ return (a.type == b.type) && (a.type == ASSET_LIBRARY_CUSTOM) ?
+ (a.custom_library_index == b.custom_library_index) :
+ true;
+}
+
+uint64_t AssetLibraryReferenceWrapper::hash() const
+{
+ uint64_t hash1 = DefaultHash<decltype(type)>{}(type);
+ if (type != ASSET_LIBRARY_CUSTOM) {
+ return hash1;
+ }
+
+ uint64_t hash2 = DefaultHash<decltype(custom_library_index)>{}(custom_library_index);
+ return hash1 ^ (hash2 * 33); /* Copied from DefaultHash for std::pair. */
+}
+
+} // namespace blender::ed::asset
diff --git a/source/blender/editors/asset/intern/asset_library_reference.hh b/source/blender/editors/asset/intern/asset_library_reference.hh
new file mode 100644
index 00000000000..7e8cb4a3472
--- /dev/null
+++ b/source/blender/editors/asset/intern/asset_library_reference.hh
@@ -0,0 +1,46 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edasset
+ *
+ * Utility to extend #AssetLibraryReference with C++ functionality (operators, hash function, etc).
+ */
+
+#pragma once
+
+#include <cstdint>
+
+#include "DNA_asset_types.h"
+
+namespace blender::ed::asset {
+
+/**
+ * Wrapper to add logic to the AssetLibraryReference DNA struct.
+ */
+class AssetLibraryReferenceWrapper : public AssetLibraryReference {
+ 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;
+};
+
+} // namespace blender::ed::asset