[Bf-blender-cvs] [58abb84fe71] node-add-asset-menu: Revert some unnecessary C++ conversions of functions

Hans Goudey noreply at git.blender.org
Wed Oct 5 21:15:41 CEST 2022


Commit: 58abb84fe71ed6ae4bfa1b43e3ae416dbe524ff7
Author: Hans Goudey
Date:   Wed Oct 5 14:15:26 2022 -0500
Branches: node-add-asset-menu
https://developer.blender.org/rB58abb84fe71ed6ae4bfa1b43e3ae416dbe524ff7

Revert some unnecessary C++ conversions of functions

===================================================================

M	source/blender/blenkernel/BKE_asset_library.h
M	source/blender/blenkernel/BKE_asset_library.hh
M	source/blender/blenkernel/intern/asset_catalog.cc
M	source/blender/blenkernel/intern/asset_library.cc
M	source/blender/blenkernel/intern/asset_library_service.cc
M	source/blender/editors/space_file/filelist.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_asset_library.h b/source/blender/blenkernel/BKE_asset_library.h
index e82ebba8d88..824bc24203d 100644
--- a/source/blender/blenkernel/BKE_asset_library.h
+++ b/source/blender/blenkernel/BKE_asset_library.h
@@ -24,6 +24,41 @@ typedef struct AssetLibrary AssetLibrary;
  */
 struct AssetLibrary *BKE_asset_library_load(const char *library_path);
 
+/**
+ * Try to find an appropriate location for an asset library root from a file or directory path.
+ * Does not check if \a input_path exists.
+ *
+ * The design is made to find an appropriate asset library path from a .blend file path, but
+ * technically works with any file or directory as \a input_path.
+ * Design is:
+ * * If \a input_path lies within a known asset library path (i.e. an asset library registered in
+ *   the Preferences), return the asset library path.
+ * * Otherwise, if \a input_path has a parent path, return the parent path (e.g. to use the
+ *   directory a .blend file is in as asset library root).
+ * * If \a input_path is empty or doesn't have a parent path (e.g. because a .blend wasn't saved
+ *   yet), there is no suitable path. The caller has to decide how to handle this case.
+ *
+ * \param r_library_path: The returned asset library path with a trailing slash, or an empty string
+ *                        if no suitable path is found. Assumed to be a buffer of at least
+ *                        #FILE_MAXDIR bytes.
+ *
+ * \return True if the function could find a valid, that is, a non-empty path to return in \a
+ *         r_library_path.
+ */
+bool BKE_asset_library_find_suitable_root_path_from_path(
+    const char *input_path, char r_library_path[768 /* FILE_MAXDIR */]);
+/**
+ * Uses the current location on disk of the file represented by \a bmain as input to
+ * #BKE_asset_library_find_suitable_root_path_from_path(). Refer to it for a design
+ * description.
+ *
+ * \return True if the function could find a valid, that is, a non-empty path to return in \a
+ *         r_library_path. If \a bmain wasn't saved into a file yet, the return value will be
+ *         false.
+ */
+bool BKE_asset_library_find_suitable_root_path_from_main(
+    const struct Main *bmain, char r_library_path[768 /* FILE_MAXDIR */]);
+
 /** Look up the asset's catalog and copy its simple name into #asset_data. */
 void BKE_asset_library_refresh_catalog_simplename(struct AssetLibrary *asset_library,
                                                   struct AssetMetaData *asset_data);
diff --git a/source/blender/blenkernel/BKE_asset_library.hh b/source/blender/blenkernel/BKE_asset_library.hh
index f3a8fdce76f..1044b1d869f 100644
--- a/source/blender/blenkernel/BKE_asset_library.hh
+++ b/source/blender/blenkernel/BKE_asset_library.hh
@@ -64,39 +64,6 @@ Vector<AssetLibraryReference> all_asset_library_refs();
 blender::bke::AssetLibrary *BKE_asset_library_load(const Main *bmain,
                                                    const AssetLibraryReference &library_reference);
 
-/**
- * Try to find an appropriate location for an asset library root from a file or directory path.
- * Does not check if \a input_path exists.
- *
- * The design is made to find an appropriate asset library path from a .blend file path, but
- * technically works with any file or directory as \a input_path.
- * Design is:
- * * If \a input_path lies within a known asset library path (i.e. an asset library registered in
- *   the Preferences), return the asset library path.
- * * Otherwise, if \a input_path has a parent path, return the parent path (e.g. to use the
- *   directory a .blend file is in as asset library root).
- * * If \a input_path is empty or doesn't have a parent path (e.g. because a .blend wasn't saved
- *   yet), there is no suitable path. The caller has to decide how to handle this case.
- *
- * \param r_library_path: The returned asset library path with a trailing slash, or an empty string
- * if no suitable path is found. Assumed to be a buffer of at least #FILE_MAXDIR bytes.
- *
- * \return True if the function could find a valid, that is, a non-empty path to return in \a
- * r_library_path.
- */
-std::string BKE_asset_library_find_suitable_root_path_from_path(blender::StringRefNull input_path);
-
-/**
- * Uses the current location on disk of the file represented by \a bmain as input to
- * #BKE_asset_library_find_suitable_root_path_from_path(). Refer to it for a design
- * description.
- *
- * \return True if the function could find a valid, that is, a non-empty path to return in \a
- *         r_library_path. If \a bmain wasn't saved into a file yet, the return value will be
- *         false.
- */
-std::string BKE_asset_library_find_suitable_root_path_from_main(const Main *bmain);
-
 blender::bke::AssetCatalogService *BKE_asset_library_get_catalog_service(
     const ::AssetLibrary *library);
 blender::bke::AssetCatalogTree *BKE_asset_library_get_catalog_tree(const ::AssetLibrary *library);
diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc
index 4b811c2e724..9feb62840d6 100644
--- a/source/blender/blenkernel/intern/asset_catalog.cc
+++ b/source/blender/blenkernel/intern/asset_catalog.cc
@@ -514,13 +514,14 @@ CatalogFilePath AssetCatalogService::find_suitable_cdf_path_for_writing(
                  "catalog definition file should be put");
 
   /* Ask the asset library API for an appropriate location. */
-  const std::string suitable_root_path = BKE_asset_library_find_suitable_root_path_from_path(
-      blend_file_path);
-  if (!suitable_root_path.empty()) {
+  char suitable_root_path[PATH_MAX];
+  const bool asset_lib_root_found = BKE_asset_library_find_suitable_root_path_from_path(
+      blend_file_path.c_str(), suitable_root_path);
+  if (asset_lib_root_found) {
     char asset_lib_cdf_path[PATH_MAX];
     BLI_path_join(asset_lib_cdf_path,
                   sizeof(asset_lib_cdf_path),
-                  suitable_root_path.c_str(),
+                  suitable_root_path,
                   DEFAULT_CATALOG_FILENAME.c_str(),
                   nullptr);
     return asset_lib_cdf_path;
diff --git a/source/blender/blenkernel/intern/asset_library.cc b/source/blender/blenkernel/intern/asset_library.cc
index b178afc7e68..91318734705 100644
--- a/source/blender/blenkernel/intern/asset_library.cc
+++ b/source/blender/blenkernel/intern/asset_library.cc
@@ -49,22 +49,22 @@ bool BKE_asset_library_has_any_unsaved_catalogs()
   return service->has_any_unsaved_catalogs();
 }
 
-std::string BKE_asset_library_find_suitable_root_path_from_path(
-    const blender::StringRefNull input_path)
+bool BKE_asset_library_find_suitable_root_path_from_path(const char *input_path,
+                                                         char *r_library_path)
 {
   if (bUserAssetLibrary *preferences_lib = BKE_preferences_asset_library_containing_path(
-          &U, input_path.c_str())) {
-    return preferences_lib->path;
+          &U, input_path)) {
+    BLI_strncpy(r_library_path, preferences_lib->path, FILE_MAXDIR);
+    return true;
   }
 
-  char buffer[FILE_MAXDIR];
-  BLI_split_dir_part(input_path.c_str(), buffer, FILE_MAXDIR);
-  return buffer;
+  BLI_split_dir_part(input_path, r_library_path, FILE_MAXDIR);
+  return r_library_path[0] != '\0';
 }
 
-std::string BKE_asset_library_find_suitable_root_path_from_main(const Main *bmain)
+bool BKE_asset_library_find_suitable_root_path_from_main(const Main *bmain, char *r_library_path)
 {
-  return BKE_asset_library_find_suitable_root_path_from_path(bmain->filepath);
+  return BKE_asset_library_find_suitable_root_path_from_path(bmain->filepath, r_library_path);
 }
 
 blender::bke::AssetCatalogService *BKE_asset_library_get_catalog_service(
diff --git a/source/blender/blenkernel/intern/asset_library_service.cc b/source/blender/blenkernel/intern/asset_library_service.cc
index b4aeb6ca1c7..8d8a0d82906 100644
--- a/source/blender/blenkernel/intern/asset_library_service.cc
+++ b/source/blender/blenkernel/intern/asset_library_service.cc
@@ -47,10 +47,15 @@ AssetLibrary *AssetLibraryService::get_asset_library(
 {
   if (library_reference.type == ASSET_LIBRARY_LOCAL) {
     /* For the "Current File" library  we get the asset library root path based on main. */
-    std::string root_path = bmain ? BKE_asset_library_find_suitable_root_path_from_main(bmain) :
-                                    "";
+    char root_path[FILE_MAX];
+    if (bmain) {
+      BKE_asset_library_find_suitable_root_path_from_main(bmain, root_path);
+    }
+    else {
+      root_path[0] = '\0';
+    }
 
-    if (root_path.empty()) {
+    if (root_path[0] == '\0') {
       /* File wasn't saved yet. */
       return get_asset_library_current_file();
     }
diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc
index e0ddba9af84..c2dc8e9196d 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -41,7 +41,7 @@
 #endif
 
 #include "BKE_asset.h"
-#include "BKE_asset_library.hh"
+#include "BKE_asset_library.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_icons.h"
@@ -3604,15 +3604,17 @@ static void filelist_readjob_lib(FileListReadJob *job_params,
   filelist_readjob_do(true, job_params, stop, do_update, progress);
 }
 
-static std::string filelist_asset_library_path(const FileListReadJob *job_params)
+static void filelist_asset_library_path(const FileListReadJob *job_params,
+                                        char r_library_root_path[FILE_MAX])
 {
   if (job_params->filelist->type == FILE_MAIN_ASSET) {
     /* For the "Current File" library (#FILE_MAIN_ASSET) we get the asset library root path based
      * on main. */
-    return BKE_asset_library_find_suitable_root_path_from_main(job_params->current_main);
+    BKE_asset_library_find_suitable_root_path_from_main(job_params->current_main,
+                                                        r_library_root_path);
   }
   else {
-    return job_params->tmp_filelist->filelist.root;
+    BLI_strncpy(r_library_root_path, job_params->tmp_filelist->filelist.root, FILE_MAX);
   }
 }
 
@@ -3633,11 +3635,12 @@ static void file

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list