Blender  V3.3
blender_user_menu.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #include <string.h>
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "BLI_listbase.h"
14 #include "BLI_string.h"
15 
16 #include "DNA_userdef_types.h"
17 
18 #include "BKE_blender_user_menu.h"
19 #include "BKE_idprop.h"
20 
21 /* -------------------------------------------------------------------- */
25 bUserMenu *BKE_blender_user_menu_find(ListBase *lb, char space_type, const char *context)
26 {
27  LISTBASE_FOREACH (bUserMenu *, um, lb) {
28  if ((space_type == um->space_type) && (STREQ(context, um->context))) {
29  return um;
30  }
31  }
32  return NULL;
33 }
34 
35 bUserMenu *BKE_blender_user_menu_ensure(ListBase *lb, char space_type, const char *context)
36 {
37  bUserMenu *um = BKE_blender_user_menu_find(lb, space_type, context);
38  if (um == NULL) {
39  um = MEM_callocN(sizeof(bUserMenu), __func__);
40  um->space_type = space_type;
41  STRNCPY(um->context, context);
42  BLI_addhead(lb, um);
43  }
44  return um;
45 }
46 
49 /* -------------------------------------------------------------------- */
54 {
55  uint size;
56 
57  if (type == USER_MENU_TYPE_SEP) {
58  size = sizeof(bUserMenuItem);
59  }
60  else if (type == USER_MENU_TYPE_OPERATOR) {
61  size = sizeof(bUserMenuItem_Op);
62  }
63  else if (type == USER_MENU_TYPE_MENU) {
64  size = sizeof(bUserMenuItem_Menu);
65  }
66  else if (type == USER_MENU_TYPE_PROP) {
67  size = sizeof(bUserMenuItem_Prop);
68  }
69  else {
70  size = sizeof(bUserMenuItem);
71  BLI_assert(0);
72  }
73 
74  bUserMenuItem *umi = MEM_callocN(size, __func__);
75  umi->type = type;
76  BLI_addtail(lb, umi);
77  return umi;
78 }
79 
81 {
82  if (umi->type == USER_MENU_TYPE_OPERATOR) {
83  bUserMenuItem_Op *umi_op = (bUserMenuItem_Op *)umi;
84  if (umi_op->prop) {
85  IDP_FreeProperty(umi_op->prop);
86  }
87  }
88  MEM_freeN(umi);
89 }
90 
92 {
93  for (bUserMenuItem *umi = lb->first, *umi_next; umi; umi = umi_next) {
94  umi_next = umi->next;
96  }
98 }
99 
void IDP_FreeProperty(struct IDProperty *prop)
Definition: idprop.c:1093
#define BLI_assert(a)
Definition: BLI_assert.h:46
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:60
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:273
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
#define STRNCPY(dst, src)
Definition: BLI_string.h:483
unsigned int uint
Definition: BLI_sys_types.h:67
#define STREQ(a, b)
struct bUserMenuItem_Op bUserMenuItem_Op
@ USER_MENU_TYPE_OPERATOR
@ USER_MENU_TYPE_SEP
@ USER_MENU_TYPE_PROP
@ USER_MENU_TYPE_MENU
struct bUserMenuItem_Prop bUserMenuItem_Prop
struct bUserMenuItem_Menu bUserMenuItem_Menu
struct bUserMenuItem bUserMenuItem
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
bUserMenu * BKE_blender_user_menu_ensure(ListBase *lb, char space_type, const char *context)
void BKE_blender_user_menu_item_free(bUserMenuItem *umi)
bUserMenu * BKE_blender_user_menu_find(ListBase *lb, char space_type, const char *context)
void BKE_blender_user_menu_item_free_list(ListBase *lb)
bUserMenuItem * BKE_blender_user_menu_item_add(ListBase *lb, int type)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
void * first
Definition: DNA_listBase.h:31
struct IDProperty * prop
char context[64]