Blender
V3.3
|
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_main_namemap.h"
#include "BLI_assert.h"
#include "BLI_bitmap.h"
#include "BLI_ghash.h"
#include "BLI_listbase.h"
#include "BLI_map.hh"
#include "BLI_math_base.hh"
#include "BLI_set.hh"
#include "BLI_string_utf8.h"
#include "BLI_string_utils.h"
#include "DNA_ID.h"
#include "MEM_guardedalloc.h"
#include "CLG_log.h"
Go to the source code of this file.
Classes | |
struct | UniqueName_Key |
struct | UniqueName_Value |
struct | UniqueName_TypeMap |
struct | UniqueName_Map |
struct | Uniqueness_Key |
Macros | |
#define | MAX_NUMBER 1000000000 |
#define | MIN_NUMBER 1 |
Functions | |
static bool | id_name_final_build (char *name, char *base_name, size_t base_name_len, int number) |
struct UniqueName_Map * | BKE_main_namemap_create () |
void | BKE_main_namemap_destroy (struct UniqueName_Map **r_name_map) |
static void | main_namemap_populate (UniqueName_Map *name_map, struct Main *bmain, ID *ignore_id) |
static UniqueName_Map * | get_namemap_for (Main *bmain, ID *id, bool ensure_created) |
bool | BKE_main_namemap_get_name (struct Main *bmain, struct ID *id, char *name) |
void | BKE_main_namemap_remove_name (struct Main *bmain, struct ID *id, const char *name) |
static bool | main_namemap_validate_and_fix (Main *bmain, const bool do_fix) |
bool | BKE_main_namemap_validate_and_fix (Main *bmain) |
bool | BKE_main_namemap_validate (Main *bmain) |
Variables | |
static CLG_LogRef | LOG = {"bke.main_namemap"} |
#define MAX_NUMBER 1000000000 |
Definition at line 35 of file main_namemap.cc.
#define MIN_NUMBER 1 |
Definition at line 37 of file main_namemap.cc.
struct UniqueName_Map* BKE_main_namemap_create | ( | void | ) |
void BKE_main_namemap_destroy | ( | struct UniqueName_Map ** | r_name_map | ) |
Definition at line 182 of file main_namemap.cc.
References UniqueName_TypeMap::base_name_to_num_suffix, UniqueName_TypeMap::full_names, blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::size_in_bytes(), and blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::size_in_bytes().
Referenced by BKE_main_free(), library_runtime_reset(), and main_namemap_validate_and_fix().
Ensures the given name is unique within the given ID type.
In case of name collisions, the name will be adjusted to be unique.
Definition at line 248 of file main_namemap.cc.
References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), UniqueName_TypeMap::base_name_to_num_suffix, BLI_assert, BLI_split_name_num(), BLI_strncpy(), blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), UniqueName_Map::find_by_type(), UniqueName_TypeMap::full_names, get_namemap_for(), GS, id, id_name_final_build(), blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_or_add_cb(), UniqueName_Value::mark_used(), MAX_NAME, UniqueName_Value::max_value, MIN_NUMBER, ID::name, UniqueName_Key::name, UniqueName_Value::use_if_unused(), and UniqueName_Value::use_smallest_unused().
Referenced by BKE_id_new_name_validate(), blender::bke::tests::change_lib(), and wm_window_match_keep_current_wm().
Remove a given name from usage.
Call this whenever deleting or renaming an object.
Definition at line 333 of file main_namemap.cc.
References UniqueName_TypeMap::base_name_to_num_suffix, BLI_assert, BLI_split_name_num(), BLI_strncpy(), UniqueName_Map::find_by_type(), UniqueName_TypeMap::full_names, get_namemap_for(), GS, id, blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_ptr(), UniqueName_Value::mark_unused(), MAX_NAME, UniqueName_Value::max_value, MIN_NUMBER, ID::name, UniqueName_Key::name, blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::remove(), and blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::remove().
Referenced by BKE_id_free_ex(), BKE_lib_id_clear_library_data(), BKE_lib_override_library_update(), BKE_libblock_management_main_remove(), BKE_libblock_rename(), BLO_update_defaults_startup_blend(), blender::bke::tests::change_lib(), blender::bke::tests::change_name(), do_versions_rename_id(), id_delete(), and namebutton_fn().
Check that all ID names in given bmain
are unique (per ID type and library), and that existing name maps are consistent with existing relevant IDs.
This is typically called within an assert, or in tests.
Definition at line 497 of file main_namemap.cc.
References main_namemap_validate_and_fix().
Referenced by BKE_lib_override_library_main_resync(), BKE_lib_override_library_main_update(), blender::bke::tests::TEST(), and WM_file_read().
Same as BKE_main_namemap_validate, but also fixes any issue by re-generating all name maps, and ensuring again all ID names are unique.
This is typically only used in do_versions
code to fix broken files.
Definition at line 490 of file main_namemap.cc.
References BLI_assert, is_valid, and main_namemap_validate_and_fix().
Referenced by blo_do_versions_300().
|
static |
Definition at line 232 of file main_namemap.cc.
References BKE_main_namemap_create(), id, ID::lib, main_namemap_populate(), Main::name_map, Library_Runtime::name_map, and Library::runtime.
Referenced by BKE_main_namemap_get_name(), BKE_main_namemap_remove_name(), and main_namemap_validate_and_fix().
|
static |
Helper building final ID name from given base_name and number.
If everything goes well and we do generate a valid final ID name in given name, we return true. In case the final name would overflow the allowed ID name length, or given number is bigger than maximum allowed value, we truncate further the base_name (and given name, which is assumed to have the same 'base_name' part), and return false.
Definition at line 47 of file main_namemap.cc.
References ARRAY_SIZE, BLI_snprintf_rlen(), BLI_str_utf8_invalid_strip(), BLI_strncpy(), MAX_NAME, and MAX_NUMBER.
Referenced by BKE_main_namemap_get_name().
|
static |
Definition at line 198 of file main_namemap.cc.
References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), UniqueName_TypeMap::base_name_to_num_suffix, BLI_assert, BLI_assert_msg, BLI_split_name_num(), BLI_strncpy(), blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::clear(), UniqueName_Map::find_by_type(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, UniqueName_TypeMap::full_names, GS, id, ID::lib, library, blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_or_add_default(), UniqueName_Value::mark_used(), MAX_NAME, MIN_NUMBER, ID::name, UniqueName_Key::name, and UniqueName_Map::type_maps.
Referenced by get_namemap_for().
Definition at line 386 of file main_namemap.cc.
References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), BKE_id_new_name_validate(), BKE_idtype_idcode_iter_step(), BKE_main_namemap_destroy(), BLI_assert, BLI_strncpy(), CLOG_ERROR, CLOG_WARN, blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), UniqueName_Map::find_by_type(), ListBase::first, FOREACH_MAIN_LISTBASE_BEGIN, FOREACH_MAIN_LISTBASE_END, UniqueName_TypeMap::full_names, get_namemap_for(), GS, id_name(), is_valid, Uniqueness_Key::lib, lib, Main::libraries, LISTBASE_FOREACH_MUTABLE, LOG, MAX_ID_NAME, MAX_NAME, Uniqueness_Key::name, UniqueName_Key::name, Main::name_map, and which_libbase().
Referenced by BKE_main_namemap_validate(), and BKE_main_namemap_validate_and_fix().
|
static |
Definition at line 28 of file main_namemap.cc.
Referenced by main_namemap_validate_and_fix().