Cleanup: Use ID type enum instead of unsafe integer

Adds type safety and removes need for explicit casts.
This commit is contained in:
Julian Eisel
2023-06-09 12:24:48 +02:00
parent c70a1595ef
commit 0044c93e84
4 changed files with 10 additions and 6 deletions

View File

@@ -10,6 +10,8 @@
#include "BLI_compiler_attrs.h"
#include "DNA_ID_enums.h"
#ifdef __cplusplus
extern "C" {
#endif
@@ -22,7 +24,8 @@ typedef struct AssetRepresentation AssetRepresentation;
const char *AS_asset_representation_name_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
int AS_asset_representation_id_type_get(const AssetRepresentation *asset) ATTR_WARN_UNUSED_RESULT;
ID_Type AS_asset_representation_id_type_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
AssetMetaData *AS_asset_representation_metadata_get(const AssetRepresentation *asset)
ATTR_WARN_UNUSED_RESULT;
struct ID *AS_asset_representation_local_id_get(const AssetRepresentation *asset)

View File

@@ -19,6 +19,7 @@
#include "BLI_string_ref.hh"
#include "DNA_ID_enums.h"
#include "DNA_asset_types.h"
#include "AS_asset_identifier.hh"
@@ -87,7 +88,7 @@ class AssetRepresentation {
std::unique_ptr<AssetWeakReference> make_weak_reference() const;
StringRefNull get_name() const;
int get_id_type() const;
ID_Type get_id_type() const;
AssetMetaData &get_metadata() const;
/**
* Get the import method to use for this asset. A different one may be used if

View File

@@ -89,13 +89,13 @@ StringRefNull AssetRepresentation::get_name() const
return external_asset_.name;
}
int AssetRepresentation::get_id_type() const
ID_Type AssetRepresentation::get_id_type() const
{
if (is_local_id_) {
return GS(local_asset_id_->name);
}
return external_asset_.id_type;
return ID_Type(external_asset_.id_type);
}
AssetMetaData &AssetRepresentation::get_metadata() const
@@ -203,7 +203,7 @@ const char *AS_asset_representation_name_get(const AssetRepresentation *asset_ha
return asset->get_name().c_str();
}
int AS_asset_representation_id_type_get(const AssetRepresentation *asset_handle)
ID_Type AS_asset_representation_id_type_get(const AssetRepresentation *asset_handle)
{
const asset_system::AssetRepresentation *asset =
reinterpret_cast<const asset_system::AssetRepresentation *>(asset_handle);

View File

@@ -43,7 +43,7 @@ ID *ED_asset_handle_get_local_id(const AssetHandle *asset_handle)
ID_Type ED_asset_handle_get_id_type(const AssetHandle *asset_handle)
{
return static_cast<ID_Type>(AS_asset_representation_id_type_get(asset_handle->file_data->asset));
return AS_asset_representation_id_type_get(asset_handle->file_data->asset);
}
int ED_asset_handle_get_preview_icon_id(const AssetHandle *asset)