Blender V5.0
main_namemap.cc File Reference
#include "BKE_idtype.hh"
#include "BKE_lib_id.hh"
#include "BKE_library.hh"
#include "BKE_main.hh"
#include "BKE_main_namemap.hh"
#include "BLI_assert.h"
#include "BLI_bit_span_ops.hh"
#include "BLI_bit_vector.hh"
#include "BLI_listbase.h"
#include "BLI_map.hh"
#include "BLI_math_base.hh"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_string_utils.hh"
#include "DNA_ID.h"
#include "MEM_guardedalloc.h"
#include "CLG_log.h"
#include <fmt/format.h>

Go to the source code of this file.

Classes

struct  UniqueName_Value
struct  UniqueName_TypeMap
struct  UniqueName_Map
struct  Uniqueness_Key

Functions

void BKE_main_namemap_destroy (UniqueName_Map **r_name_map)
void BKE_main_namemap_clear (Main &bmain)
static UniqueName_Mapget_global_namemap_for (Main &bmain, ID *ignore_id, const bool ensure_created)
static UniqueName_Mapget_namemap_for (Main &bmain, Library *lib, ID *ignore_id, const bool ensure_created)
bool BKE_main_global_namemap_contain_name (Main &bmain, const short id_type, StringRef name)
bool BKE_main_namemap_contain_name (Main &bmain, Library *lib, const short id_type, StringRef name)
static bool id_name_final_build (UniqueName_TypeMap &type_map, const StringRefNull base_name, const int number, std::string &r_name_final)
static bool namemap_get_name (Main &bmain, ID &id, std::string &r_name_full, const bool do_unique_in_bmain)
bool BKE_main_namemap_get_unique_name (Main &bmain, ID &id, char *r_name)
bool BKE_main_global_namemap_get_unique_name (Main &bmain, ID &id, char *r_name)
void BKE_main_namemap_remove_id (Main &bmain, ID &id)
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 = {"lib.main_namemap"}
constexpr int MAX_NUMBER = 999999999
constexpr int NO_AVAILABLE_NUMBER = -1

Function Documentation

◆ BKE_main_global_namemap_contain_name()

bool BKE_main_global_namemap_contain_name ( Main & bmain,
short id_type,
blender::StringRef name )

Check if the given name is already in use in the whole Main data-base (local and all linked data).

Returns
true if the name is already in use.

Definition at line 409 of file main_namemap.cc.

References BLI_assert, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), UniqueName_Map::find_by_type(), UniqueName_TypeMap::full_names, get_global_namemap_for(), MAX_ID_NAME, and name.

◆ BKE_main_global_namemap_get_unique_name()

bool BKE_main_global_namemap_get_unique_name ( Main & bmain,
ID & id,
char * r_name )

Ensures the given name is unique within the given ID type, in the whole Main data-base (local and all linked data).

In case of name collisions, the name will be adjusted to be unique.

Returns
true if the name had to be adjusted for uniqueness.

Definition at line 591 of file main_namemap.cc.

References BLI_assert, BLI_strncpy(), MAX_ID_NAME, and namemap_get_name().

Referenced by blender::bke::tests::change_name_global(), and lib_override_library_create_from().

◆ BKE_main_namemap_clear()

void BKE_main_namemap_clear ( Main & bmain)

Destroy all name_maps in given bmain:

  • In bmain itself for local IDs.
  • In the split bmains in the list is any (for linked IDs in some cases, e.g. if called during readfile code).
  • In all of the libraries IDs (for linked IDs).

Definition at line 346 of file main_namemap.cc.

References BKE_main_namemap_destroy(), BLI_assert_msg, and Main::split_mains.

Referenced by BKE_blendfile_override(), BKE_main_merge(), blo_join_main(), blo_split_main(), main_namemap_validate_and_fix(), and swap_old_bmain_data_for_blendfile().

◆ BKE_main_namemap_contain_name()

bool BKE_main_namemap_contain_name ( Main & bmain,
Library * lib,
short id_type,
blender::StringRef name )

◆ BKE_main_namemap_destroy()

◆ BKE_main_namemap_get_unique_name()

bool BKE_main_namemap_get_unique_name ( Main & bmain,
ID & id,
char * r_name )

Same as #BKE_main_global_namemap_get_name, but only make the name unique in the local or related library namemap.

Definition at line 582 of file main_namemap.cc.

References BLI_assert, BLI_strncpy(), MAX_ID_NAME, and namemap_get_name().

Referenced by BKE_id_new_name_validate(), blender::bke::tests::change_lib(), and blender::bke::tests::TEST().

◆ BKE_main_namemap_remove_id()

◆ BKE_main_namemap_validate()

◆ BKE_main_namemap_validate_and_fix()

bool BKE_main_namemap_validate_and_fix ( Main & bmain)

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 764 of file main_namemap.cc.

References BLI_assert, and main_namemap_validate_and_fix().

Referenced by after_liblink_merged_bmain_process(), blo_do_versions_300(), do_versions_after_setup(), and write_file_main_validate_pre().

◆ get_global_namemap_for()

UniqueName_Map * get_global_namemap_for ( Main & bmain,
ID * ignore_id,
const bool ensure_created )
static

◆ get_namemap_for()

UniqueName_Map * get_namemap_for ( Main & bmain,
Library * lib,
ID * ignore_id,
const bool ensure_created )
static

◆ id_name_final_build()

bool id_name_final_build ( UniqueName_TypeMap & type_map,
const StringRefNull base_name,
const int number,
std::string & r_name_final )
static

Helper building final ID name from given base_name and number.

Return true in case of success (a valid final ID name can be generated from given #base_name and #number parameters).

Return false in case either the given number is invalid (NO_AVAILABLE_NUMBER), or the generated final name would be too long. #r_name_final is then set with a new, edited base name:

  • Shortened by one (UTF8) char in case of too long name.
  • Extended by a pseudo-random number in case the base name is short already (should only happen when #number is NO_AVAILABLE_NUMBER).

Definition at line 441 of file main_namemap.cc.

References UniqueName_TypeMap::base_name_to_num_suffix, BLI_assert, BLI_str_utf8_invalid_strip(), BLI_strncpy(), blender::StringRefNull::c_str(), CLOG_ERROR, blender::get_default_hash(), LOG, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup_ptr(), MAX_ID_NAME, MAX_NUMBER, NO_AVAILABLE_NUMBER, and blender::StringRefBase::size().

Referenced by namemap_get_name().

◆ main_namemap_validate_and_fix()

◆ namemap_get_name()

Variable Documentation

◆ LOG

CLG_LogRef LOG = {"lib.main_namemap"}
static

Definition at line 33 of file main_namemap.cc.

◆ MAX_NUMBER

int MAX_NUMBER = 999999999
constexpr

◆ NO_AVAILABLE_NUMBER

int NO_AVAILABLE_NUMBER = -1
constexpr