Blender V4.3
file_indexer.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#include "file_indexer.hh"
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_linklist.h"
16#include "BLI_listbase.h"
17#include "BLI_utildefines.h"
18
20
21static eFileIndexerResult read_index(const char * /*file_name*/,
22 FileIndexerEntries * /*entries*/,
23 int * /*r_read_entries_len*/,
24 void * /*user_data*/)
25{
27}
28
29static void update_index(const char * /*file_name*/,
30 FileIndexerEntries * /*entries*/,
31 void * /*user_data*/)
32{
33}
34
36{
37 FileIndexerType indexer = {nullptr};
38 indexer.read_index = read_index;
39 indexer.update_index = update_index;
40 return indexer;
41}
42
44 BLODataBlockInfo *datablock_info, const int idcode)
45{
46 FileIndexerEntry *entry = static_cast<FileIndexerEntry *>(
47 MEM_mallocN(sizeof(FileIndexerEntry), __func__));
48 entry->idcode = idcode;
49 /* Shallow copy data-block info and mark original as having its asset data ownership stolen. */
50 entry->datablock_info = *datablock_info;
51 datablock_info->free_asset_data = false;
52 return entry;
53}
54
55} // namespace blender::ed::file::indexer
56
58 FileIndexerEntries *indexer_entries,
59 LinkNode * /*BLODataBlockInfo*/ datablock_infos,
60 const int idcode)
61{
62 for (LinkNode *ln = datablock_infos; ln; ln = ln->next) {
63 BLODataBlockInfo *datablock_info = static_cast<BLODataBlockInfo *>(ln->link);
64 FileIndexerEntry *file_indexer_entry =
66 idcode);
67 BLI_linklist_prepend(&indexer_entries->entries, file_indexer_entry);
68 }
69}
70
72{
73 BLI_linklist_free(indexer_entries->entries, [](void *indexer_entry_ptr) {
74 FileIndexerEntry *indexer_entry = static_cast<FileIndexerEntry *>(indexer_entry_ptr);
75 BLO_datablock_info_free(&indexer_entry->datablock_info);
76 MEM_freeN(indexer_entry);
77 });
78
79 indexer_entries->entries = nullptr;
80}
81
eFileIndexerResult
@ FILE_INDEXER_NEEDS_UPDATE
Read Guarded memory(de)allocation.
void ED_file_indexer_entries_clear(FileIndexerEntries *indexer_entries)
void ED_file_indexer_entries_extend_from_datablock_infos(FileIndexerEntries *indexer_entries, LinkNode *datablock_infos, const int idcode)
const FileIndexerType file_indexer_noop
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
static void update_index(const char *, FileIndexerEntries *, void *)
static FileIndexerEntry * file_indexer_entry_create_from_datablock_info(BLODataBlockInfo *datablock_info, const int idcode)
static eFileIndexerResult read_index(const char *, FileIndexerEntries *, int *, void *)
constexpr FileIndexerType default_indexer()
BLODataBlockInfo datablock_info
FileIndexerUpdateIndexFunc update_index
FileIndexerReadIndexFunc read_index
struct LinkNode * next