diff options
author | Julian Eisel <julian@blender.org> | 2021-02-06 04:18:38 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-02-06 21:27:55 +0300 |
commit | ef29ebb31bd4bad47f55f45d6b4a2ab40fe09caf (patch) | |
tree | 67736e49c577a9fdfd5f88501bb5b130bd25d2fc /source | |
parent | 4cca64f4ad32f3c5509e40f931afdab550ff32d2 (diff) |
Code quality: Port recently added asset files to C++
It seems generally preferred to have new files be created with C++.
The only reason I didn't do that when I initially created the files is that I
was unsure about some C-API aspect.
Also includes some minor C++ related cleanup (nullptr instead of NULL, remove
redundant `struct` keyword).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/asset.cc (renamed from source/blender/blenkernel/intern/asset.c) | 16 | ||||
-rw-r--r-- | source/blender/editors/asset/CMakeLists.txt | 4 | ||||
-rw-r--r-- | source/blender/editors/asset/asset_edit.cc (renamed from source/blender/editors/asset/asset_edit.c) | 4 | ||||
-rw-r--r-- | source/blender/editors/asset/asset_ops.cc (renamed from source/blender/editors/asset/asset_ops.c) | 22 |
5 files changed, 24 insertions, 24 deletions
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 0da9598f0ad..3f22612652c 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -78,7 +78,7 @@ set(SRC intern/armature.c intern/armature_deform.c intern/armature_update.c - intern/asset.c + intern/asset.cc intern/attribute.c intern/attribute_access.cc intern/autoexec.c diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.cc index 7ccb0aa2b57..89c3523285d 100644 --- a/source/blender/blenkernel/intern/asset.c +++ b/source/blender/blenkernel/intern/asset.cc @@ -20,6 +20,10 @@ #include <string.h> +#include "DNA_ID.h" +#include "DNA_asset_types.h" +#include "DNA_defaults.h" + #include "BLI_listbase.h" #include "BLI_string.h" #include "BLI_string_utils.h" @@ -29,17 +33,13 @@ #include "BKE_icons.h" #include "BKE_idprop.h" -#include "DNA_ID.h" -#include "DNA_asset_types.h" -#include "DNA_defaults.h" - #include "BLO_read_write.h" #include "MEM_guardedalloc.h" AssetMetaData *BKE_asset_metadata_create(void) { - AssetMetaData *asset_data = MEM_callocN(sizeof(*asset_data), __func__); + AssetMetaData *asset_data = (AssetMetaData *)MEM_callocN(sizeof(*asset_data), __func__); memcpy(asset_data, DNA_struct_default_get(AssetMetaData), sizeof(*asset_data)); return asset_data; } @@ -57,7 +57,7 @@ void BKE_asset_metadata_free(AssetMetaData **asset_data) static AssetTag *asset_metadata_tag_add(AssetMetaData *asset_data, const char *const name) { - AssetTag *tag = MEM_callocN(sizeof(*tag), __func__); + AssetTag *tag = (AssetTag *)MEM_callocN(sizeof(*tag), __func__); BLI_strncpy(tag->name, name, sizeof(tag->name)); BLI_addtail(&asset_data->tags, tag); @@ -81,12 +81,12 @@ AssetTag *BKE_asset_metadata_tag_add(AssetMetaData *asset_data, const char *name struct AssetTagEnsureResult BKE_asset_metadata_tag_ensure(AssetMetaData *asset_data, const char *name) { - struct AssetTagEnsureResult result = {.tag = NULL}; + struct AssetTagEnsureResult result = {nullptr}; if (!name[0]) { return result; } - AssetTag *tag = BLI_findstring(&asset_data->tags, name, offsetof(AssetTag, name)); + AssetTag *tag = (AssetTag *)BLI_findstring(&asset_data->tags, name, offsetof(AssetTag, name)); if (tag) { result.tag = tag; diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt index 6cd94783251..8c5f91561b7 100644 --- a/source/blender/editors/asset/CMakeLists.txt +++ b/source/blender/editors/asset/CMakeLists.txt @@ -29,8 +29,8 @@ set(INC_SYS ) set(SRC - asset_edit.c - asset_ops.c + asset_edit.cc + asset_ops.cc ) set(LIB diff --git a/source/blender/editors/asset/asset_edit.c b/source/blender/editors/asset/asset_edit.cc index 3dca87d3a03..7aee467286f 100644 --- a/source/blender/editors/asset/asset_edit.c +++ b/source/blender/editors/asset/asset_edit.cc @@ -45,7 +45,7 @@ bool ED_asset_mark_id(const bContext *C, ID *id) id->asset_data = BKE_asset_metadata_create(); - UI_icon_render_id(C, NULL, id, ICON_SIZE_PREVIEW, true); + UI_icon_render_id(C, nullptr, id, ICON_SIZE_PREVIEW, true); return true; } @@ -65,5 +65,5 @@ bool ED_asset_clear_id(ID *id) bool ED_asset_can_make_single_from_context(const bContext *C) { /* Context needs a "id" pointer to be set for #ASSET_OT_mark()/#ASSET_OT_clear() to use. */ - return CTX_data_pointer_get_type_silent(C, "id", &RNA_ID).data != NULL; + return CTX_data_pointer_get_type_silent(C, "id", &RNA_ID).data != nullptr; } diff --git a/source/blender/editors/asset/asset_ops.c b/source/blender/editors/asset/asset_ops.cc index 29c3174f051..6c4ef8923a2 100644 --- a/source/blender/editors/asset/asset_ops.c +++ b/source/blender/editors/asset/asset_ops.cc @@ -64,7 +64,8 @@ static ListBase /* CollectionPointerLink */ asset_operation_get_ids_from_context PointerRNA idptr = CTX_data_pointer_get_type(C, "id", &RNA_ID); if (idptr.data) { - CollectionPointerLink *ctx_link = MEM_callocN(sizeof(*ctx_link), __func__); + CollectionPointerLink *ctx_link = (CollectionPointerLink *)MEM_callocN(sizeof(*ctx_link), + __func__); ctx_link->ptr = idptr; BLI_addtail(&list, ctx_link); } @@ -84,7 +85,7 @@ static void asset_mark_for_idptr_list(const bContext *C, LISTBASE_FOREACH (CollectionPointerLink *, ctx_id, ids) { BLI_assert(RNA_struct_is_ID(ctx_id->ptr.type)); - ID *id = ctx_id->ptr.data; + ID *id = (ID *)ctx_id->ptr.data; if (id->asset_data) { r_stats->tot_already_asset++; continue; @@ -138,8 +139,8 @@ static int asset_mark_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - WM_main_add_notifier(NC_ID | NA_EDITED, NULL); - WM_main_add_notifier(NC_ASSET | NA_ADDED, NULL); + WM_main_add_notifier(NC_ID | NA_EDITED, nullptr); + WM_main_add_notifier(NC_ASSET | NA_ADDED, nullptr); return OPERATOR_FINISHED; } @@ -166,14 +167,14 @@ struct AssetClearResultStats { }; static void asset_clear_from_idptr_list(const ListBase /* CollectionPointerLink */ *ids, - struct AssetClearResultStats *r_stats) + AssetClearResultStats *r_stats) { memset(r_stats, 0, sizeof(*r_stats)); LISTBASE_FOREACH (CollectionPointerLink *, ctx_id, ids) { BLI_assert(RNA_struct_is_ID(ctx_id->ptr.type)); - ID *id = ctx_id->ptr.data; + ID *id = (ID *)ctx_id->ptr.data; if (!id->asset_data) { continue; } @@ -185,8 +186,7 @@ static void asset_clear_from_idptr_list(const ListBase /* CollectionPointerLink } } -static bool asset_clear_result_report(const struct AssetClearResultStats *stats, - ReportList *reports) +static bool asset_clear_result_report(const AssetClearResultStats *stats, ReportList *reports) { if (stats->tot_removed < 1) { @@ -210,7 +210,7 @@ static int asset_clear_exec(bContext *C, wmOperator *op) { ListBase ids = asset_operation_get_ids_from_context(C); - struct AssetClearResultStats stats; + AssetClearResultStats stats; asset_clear_from_idptr_list(&ids, &stats); BLI_freelistN(&ids); @@ -218,8 +218,8 @@ static int asset_clear_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - WM_main_add_notifier(NC_ID | NA_EDITED, NULL); - WM_main_add_notifier(NC_ASSET | NA_REMOVED, NULL); + WM_main_add_notifier(NC_ID | NA_EDITED, nullptr); + WM_main_add_notifier(NC_ASSET | NA_REMOVED, nullptr); return OPERATOR_FINISHED; } |