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).
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
@@ -29,8 +29,8 @@ set(INC_SYS
|
||||
)
|
||||
|
||||
set(SRC
|
||||
asset_edit.c
|
||||
asset_ops.c
|
||||
asset_edit.cc
|
||||
asset_ops.cc
|
||||
)
|
||||
|
||||
set(LIB
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user