Blender  V3.3
Classes
main_idmap.c File Reference
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_ghash.h"
#include "BLI_listbase.h"
#include "BLI_mempool.h"
#include "BLI_utildefines.h"
#include "DNA_ID.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_main_idmap.h"

Go to the source code of this file.

Classes

struct  IDNameLib_Key
 
struct  IDNameLib_TypeMap
 
struct  IDNameLib_Map
 

Functions

BKE_main_idmap API

Cache ID (name, library lookups). This doesn't account for adding/removing data-blocks, and should only be used when performing many lookups.

Note
GHash's are initialized on demand, since its likely some types will never have lookups run on them, so its a waste to create and never use.
static struct IDNameLib_TypeMapmain_idmap_from_idcode (struct IDNameLib_Map *id_map, short id_type)
 
struct IDNameLib_MapBKE_main_idmap_create (struct Main *bmain, const bool create_valid_ids_set, struct Main *old_bmain, const int idmap_types)
 
void BKE_main_idmap_insert_id (struct IDNameLib_Map *id_map, ID *id)
 
void BKE_main_idmap_remove_id (struct IDNameLib_Map *id_map, ID *id)
 
struct MainBKE_main_idmap_main_get (struct IDNameLib_Map *id_map)
 
static unsigned int idkey_hash (const void *ptr)
 
static bool idkey_cmp (const void *a, const void *b)
 
IDBKE_main_idmap_lookup_name (struct IDNameLib_Map *id_map, short id_type, const char *name, const Library *lib)
 
IDBKE_main_idmap_lookup_id (struct IDNameLib_Map *id_map, const ID *id)
 
IDBKE_main_idmap_lookup_uuid (struct IDNameLib_Map *id_map, const uint session_uuid)
 
void BKE_main_idmap_destroy (struct IDNameLib_Map *id_map)
 

Detailed Description

Utility functions for faster ID lookups.

Definition in file main_idmap.c.

Function Documentation

◆ BKE_main_idmap_create()

struct IDNameLib_Map* BKE_main_idmap_create ( struct Main bmain,
bool  create_valid_ids_set,
struct Main old_bmain,
int  idmap_types 
)

Generate mapping from ID type/name to ID pointer for given bmain.

Note
When used during undo/redo, there is no guaranty that ID pointers from UI area are not pointing to freed memory (when some IDs have been deleted). To avoid crashes in those cases, one can provide the 'old' (aka current) Main database as reference. BKE_main_idmap_lookup_id will then check that given ID does exist in old_bmain before trying to use it.
Parameters
create_valid_ids_setIf true, generate a reference to prevent freed memory accesses.
old_bmainIf not NULL, its IDs will be added the valid references set.

Definition at line 77 of file main_idmap.c.

References BKE_idtype_idcode_iter_step(), BKE_main_gset_create(), BLI_assert, BLI_ghash_ensure_p(), BLI_ghash_int_new(), IDNameLib_Map::bmain, FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, id, IDNameLib_TypeMap::id_type, IDNameLib_Map::idmap_types, INDEX_ID_MAX, MAIN_ID_SESSION_UUID_UNSET, MAIN_IDMAP_TYPE_UUID, IDNameLib_TypeMap::map, MEM_mallocN, NULL, POINTER_FROM_UINT, ID::session_uuid, and UNUSED_VARS_NDEBUG.

Referenced by blo_lib_link_restore(), blo_make_old_idmap_from_main(), is_yet_read(), library_link_end(), and read_libraries().

◆ BKE_main_idmap_destroy()

void BKE_main_idmap_destroy ( struct IDNameLib_Map id_map)

◆ BKE_main_idmap_insert_id()

void BKE_main_idmap_insert_id ( struct IDNameLib_Map id_map,
ID id 
)

◆ BKE_main_idmap_lookup_id()

ID* BKE_main_idmap_lookup_id ( struct IDNameLib_Map id_map,
const ID id 
)

Definition at line 236 of file main_idmap.c.

References BKE_main_idmap_lookup_name(), BLI_gset_haskey(), GS, id, ID::lib, ID::name, and NULL.

◆ BKE_main_idmap_lookup_name()

ID* BKE_main_idmap_lookup_name ( struct IDNameLib_Map id_map,
short  id_type,
const char *  name,
const Library lib 
)

◆ BKE_main_idmap_lookup_uuid()

ID* BKE_main_idmap_lookup_uuid ( struct IDNameLib_Map id_map,
const uint  session_uuid 
)

Definition at line 250 of file main_idmap.c.

References BLI_ghash_lookup(), MAIN_IDMAP_TYPE_UUID, NULL, and POINTER_FROM_UINT.

Referenced by read_libblock_undo_restore().

◆ BKE_main_idmap_main_get()

struct Main* BKE_main_idmap_main_get ( struct IDNameLib_Map id_map)

Definition at line 182 of file main_idmap.c.

Referenced by is_yet_read(), and restore_pointer_by_name().

◆ BKE_main_idmap_remove_id()

void BKE_main_idmap_remove_id ( struct IDNameLib_Map id_map,
ID id 
)

◆ idkey_cmp()

static bool idkey_cmp ( const void a,
const void b 
)
static

◆ idkey_hash()

static unsigned int idkey_hash ( const void ptr)
static

◆ main_idmap_from_idcode()

static struct IDNameLib_TypeMap* main_idmap_from_idcode ( struct IDNameLib_Map id_map,
short  id_type 
)
static