Blender V5.3
addon.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
8
9#include <cstddef>
10#include <cstdlib>
11
12#include "RNA_types.hh"
13
14#include "BLI_ghash.hh"
15#include "BLI_listbase.hh"
16#include "BLI_string.hh"
17
18#include "BKE_addon.h" /* own include */
19#include "BKE_idprop.hh"
20
21#include "DNA_listBase.h"
22#include "DNA_userdef_types.h"
23
24#include "MEM_guardedalloc.h"
25
26#include "CLG_log.h"
27
28namespace blender {
29
30static CLG_LogRef LOG = {"addon"};
31
32/* -------------------------------------------------------------------- */
35
37{
38 bAddon *addon = MEM_new<bAddon>("bAddon");
39 return addon;
40}
41
42bAddon *BKE_addon_find(const ListBaseT<bAddon> *addon_list, const char *module)
43{
44 return static_cast<bAddon *>(BLI_findstring(addon_list, module, offsetof(bAddon, module)));
45}
46
47bAddon *BKE_addon_ensure(ListBaseT<bAddon> *addon_list, const char *module)
48{
49 bAddon *addon = BKE_addon_find(addon_list, module);
50 if (addon == nullptr) {
51 addon = BKE_addon_new();
52 STRNCPY(addon->module, module);
53 BLI_addtail(addon_list, addon);
54 }
55 return addon;
56}
57
58bool BKE_addon_remove_safe(ListBaseT<bAddon> *addon_list, const char *module)
59{
60 bAddon *addon = static_cast<bAddon *>(
61 BLI_findstring(addon_list, module, offsetof(bAddon, module)));
62 if (addon) {
63 BLI_remlink(addon_list, addon);
64 BKE_addon_free(addon);
65 return true;
66 }
67 return false;
68}
69
71{
72 if (addon->prop) {
73 IDP_FreeProperty(addon->prop);
74 }
75 MEM_delete(addon);
76}
77
79
80/* -------------------------------------------------------------------- */
83
85
86bAddonPrefType *BKE_addon_pref_type_find(const char *idname, bool quiet)
87{
88 if (idname[0]) {
89 bAddonPrefType *apt;
90
91 apt = static_cast<bAddonPrefType *>(BLI_ghash_lookup(global_addonpreftype_hash, idname));
92 if (apt) {
93 return apt;
94 }
95
96 if (!quiet) {
97 CLOG_WARN(&LOG, "search for unknown addon-pref '%s'", idname);
98 }
99 }
100 else {
101 if (!quiet) {
102 CLOG_WARN(&LOG, "search for empty addon-pref");
103 }
104 }
105
106 return nullptr;
107}
108
109void BKE_addon_pref_type_add(bAddonPrefType *apt)
110{
112}
113
114void BKE_addon_pref_type_remove(const bAddonPrefType *apt)
115{
117}
118
124
130
132
133} // namespace blender
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
These structs are the foundation for all linked lists in the library system.
Read Blender memory allocation and freeing.
#define offsetof(t, d)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
char * STRNCPY(char(&dst)[N], const char *src)
struct bAddon * BKE_addon_ensure(ListBaseT< bAddon > *addon_list, const char *module)
Definition addon.cc:47
GHash * BLI_ghash_str_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:735
void BKE_addon_free(struct bAddon *addon)
Definition addon.cc:70
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
void BKE_addon_pref_type_add(bAddonPrefType *apt)
Definition addon.cc:109
void BKE_addon_pref_type_init()
Definition addon.cc:119
void BKE_addon_pref_type_free()
Definition addon.cc:125
void MEM_delete_void(void *vmemh)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition BLI_ghash.cc:711
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:866
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
bAddonPrefType * BKE_addon_pref_type_find(const char *idname, bool quiet)
Definition addon.cc:86
struct bAddon * BKE_addon_find(const ListBaseT< bAddon > *addon_list, const char *module)
Definition addon.cc:42
struct bAddon * BKE_addon_new()
Definition addon.cc:36
static GHash * global_addonpreftype_hash
Definition addon.cc:84
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
bool BKE_addon_remove_safe(ListBaseT< bAddon > *addon_list, const char *module)
Definition addon.cc:58
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:792
void BKE_addon_pref_type_remove(const bAddonPrefType *apt)
Definition addon.cc:114
static CLG_LogRef LOG
Definition logging.cpp:12
struct IDProperty * prop