Blender  V2.93
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_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)
 
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,
const bool  create_valid_ids_set,
struct Main old_bmain,
const 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 101 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(), and blo_make_old_idmap_from_main().

◆ BKE_main_idmap_destroy()

void BKE_main_idmap_destroy ( struct IDNameLib_Map id_map)

◆ BKE_main_idmap_lookup_id()

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

Definition at line 208 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 222 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 151 of file main_idmap.c.

Referenced by restore_pointer_by_name().

◆ idkey_cmp()

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

Definition at line 166 of file main_idmap.c.

References Freestyle::a, IDNameLib_Key::lib, IDNameLib_Key::name, and STREQ.

Referenced by BKE_main_idmap_lookup_name().

◆ 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

Definition at line 76 of file main_idmap.c.

References IDNameLib_TypeMap::id_type, INDEX_ID_MAX, MAIN_IDMAP_TYPE_NAME, and NULL.

Referenced by BKE_main_idmap_lookup_name().