Blender V2.61 - r43446
Classes | Defines | Typedefs | Functions | Variables

idprop.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "BKE_idprop.h"
#include "BKE_library.h"
#include "BLI_blenlib.h"
#include "MEM_guardedalloc.h"

Go to the source code of this file.

Classes

struct  IDPIter

Defines

#define GETPROP(prop, i)   (((IDProperty*)(prop)->data.pointer)+(i))
#define SWITCH_LONGINT(a)

Typedefs

typedef struct IDPIter IDPIter

Functions

IDPropertyIDP_NewIDPArray (const char *name)
IDPropertyIDP_CopyIDPArray (IDProperty *array)
void IDP_FreeIDPArray (IDProperty *prop)
void IDP_SetIndexArray (IDProperty *prop, int index, IDProperty *item)
IDPropertyIDP_GetIndexArray (IDProperty *prop, int index)
IDPropertyIDP_AppendArray (IDProperty *prop, IDProperty *item)
void IDP_ResizeIDPArray (IDProperty *prop, int newlen)
static void idp_resize_group_array (IDProperty *prop, int newlen, void *newarr)
void IDP_ResizeArray (IDProperty *prop, int newlen)
void IDP_FreeArray (IDProperty *prop)
static IDPropertyidp_generic_copy (IDProperty *prop)
static IDPropertyIDP_CopyArray (IDProperty *prop)
IDPropertyIDP_NewString (const char *st, const char *name, int maxlen)
static IDPropertyIDP_CopyString (IDProperty *prop)
void IDP_AssignString (IDProperty *prop, const char *st, int maxlen)
void IDP_ConcatStringC (IDProperty *prop, const char *st)
void IDP_ConcatString (IDProperty *str1, IDProperty *append)
void IDP_FreeString (IDProperty *prop)
void IDP_LinkID (IDProperty *prop, ID *id)
void IDP_UnlinkID (IDProperty *prop)
static IDPropertyIDP_CopyGroup (IDProperty *prop)
void IDP_SyncGroupValues (IDProperty *dest, IDProperty *src)
void IDP_ReplaceGroupInGroup (IDProperty *dest, IDProperty *src)
void IDP_ReplaceInGroup (IDProperty *group, IDProperty *prop)
int IDP_AddToGroup (IDProperty *group, IDProperty *prop)
int IDP_InsertToGroup (IDProperty *group, IDProperty *previous, IDProperty *pnew)
void IDP_RemFromGroup (IDProperty *group, IDProperty *prop)
IDPropertyIDP_GetPropertyFromGroup (IDProperty *prop, const char *name)
IDPropertyIDP_GetPropertyTypeFromGroup (IDProperty *prop, const char *name, const char type)
void * IDP_GetGroupIterator (IDProperty *prop)
IDPropertyIDP_GroupIterNext (void *vself)
void IDP_FreeIterBeforeEnd (void *vself)
static void IDP_FreeGroup (IDProperty *prop)
IDPropertyIDP_CopyProperty (IDProperty *prop)
IDPropertyIDP_GetProperties (ID *id, int create_if_needed)
int IDP_EqualsProperties (IDProperty *prop1, IDProperty *prop2)
IDPropertyIDP_New (const int type, const IDPropertyTemplate *val, const char *name)
void IDP_FreeProperty (IDProperty *prop)
void IDP_UnlinkProperty (IDProperty *prop)

Variables

static char idp_size_table []

Detailed Description

Definition in file idprop.c.


Define Documentation

#define GETPROP (   prop,
  i 
)    (((IDProperty*)(prop)->data.pointer)+(i))
#define SWITCH_LONGINT (   a)
Value:
{ \
    char s_i, *p_i; \
    p_i= (char *)&(a);  \
    s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \
    s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \
    s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \
    s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; }

Definition at line 296 of file idprop.c.


Typedef Documentation

typedef struct IDPIter IDPIter

Function Documentation

int IDP_AddToGroup ( struct IDProperty group,
struct IDProperty prop 
)

This function has a sanity check to make sure ID properties with the same name don't get added to the group.

The sanity check just means the property is not added to the group if another property exists with the same name; the client code using ID properties then needs to detect this (the function that adds new properties to groups, IDP_AddToGroup, returns 0 if a property can't be added to the group, and 1 if it can) and free the property.

Currently the code to free ID properties is designesd to leave the actual struct you pass it un-freed, this is needed for how the system works. This means to free an ID property, you first call IDP_FreeProperty then MEM_freeN the struct. In the future this will just be IDP_FreeProperty and the code will be reorganized to work properly.

Definition at line 507 of file idprop.c.

References BLI_addtail(), IDProperty::data, IDPropertyData::group, IDP_GetPropertyFromGroup(), IDProperty::len, IDProperty::name, and NULL.

Referenced by RNA_property_boolean_set(), RNA_property_boolean_set_array(), RNA_property_collection_add(), RNA_property_enum_set(), RNA_property_float_set(), RNA_property_float_set_array(), RNA_property_int_set(), RNA_property_int_set_array(), RNA_property_pointer_add(), RNA_property_string_set(), texture_paint_image_from_view_exec(), and ui_menu_block_set_keymaps().

IDProperty* IDP_AppendArray ( IDProperty prop,
IDProperty item 
) [read]
void IDP_AssignString ( IDProperty prop,
const char *  st,
int  maxlen 
)
void IDP_ConcatString ( IDProperty str1,
IDProperty append 
)
void IDP_ConcatStringC ( IDProperty prop,
const char *  st 
)
static IDProperty* IDP_CopyArray ( IDProperty prop) [static]
static IDProperty* IDP_CopyGroup ( IDProperty prop) [static]
IDProperty* IDP_CopyIDPArray ( IDProperty array)
IDProperty* IDP_CopyProperty ( IDProperty prop) [read]
static IDProperty* IDP_CopyString ( IDProperty prop) [static]
int IDP_EqualsProperties ( IDProperty prop1,
IDProperty prop2 
)
void IDP_FreeArray ( IDProperty prop)

Definition at line 251 of file idprop.c.

References IDProperty::data, idp_resize_group_array(), MEM_freeN(), NULL, and IDPropertyData::pointer.

Referenced by IDP_FreeProperty().

static void IDP_FreeGroup ( IDProperty prop) [static]
void IDP_FreeIDPArray ( IDProperty prop)
void IDP_FreeIterBeforeEnd ( void *  vself)

Frees the iterator pointed to at vself, only use this if iteration is stopped early; when the iterator hits the end of the list it'll automatially free itself.

Definition at line 572 of file idprop.c.

References MEM_freeN().

void IDP_FreeProperty ( struct IDProperty prop)
void IDP_FreeString ( IDProperty prop)

Definition at line 388 of file idprop.c.

References IDProperty::data, MEM_freeN(), and IDPropertyData::pointer.

Referenced by IDP_FreeProperty().

static IDProperty* idp_generic_copy ( IDProperty prop) [static]
void* IDP_GetGroupIterator ( struct IDProperty prop)

Get an iterator to iterate over the members of an id property group. Note that this will automatically free the iterator once iteration is complete; if you stop the iteration before hitting the end, make sure to call IDP_FreeIterBeforeEnd().

Definition at line 551 of file idprop.c.

References IDProperty::data, ListBase::first, IDPropertyData::group, MEM_callocN(), IDPIter::next, and IDPIter::parent.

IDProperty* IDP_GetIndexArray ( IDProperty prop,
int  index 
) [read]

Definition at line 120 of file idprop.c.

References GETPROP.

Referenced by RNA_property_collection_add().

IDProperty* IDP_GetProperties ( struct ID id,
int  create_if_needed 
) [read]

Get the Group property that contains the id properties for ID id. Set create_if_needed to create the Group property and attach it to id if it doesn't exist; otherwise the function will return NULL if there's no Group property attached to the ID.

Definition at line 604 of file idprop.c.

References IDP_GROUP, MEM_callocN(), and ID::properties.

Referenced by project_paint_begin(), shader_preview_free(), texture_paint_camera_project_exec(), and texture_paint_image_from_view_exec().

IDProperty* IDP_GetPropertyFromGroup ( IDProperty prop,
const char *  name 
)
IDProperty* IDP_GetPropertyTypeFromGroup ( struct IDProperty prop,
const char *  name,
const char  type 
)
IDProperty* IDP_GroupIterNext ( void *  vself)

Returns the next item in the iteration. To use, simple for a loop like the following: while (IDP_GroupIterNext(iter) != NULL) { . . . }

Definition at line 559 of file idprop.c.

References if(), MEM_freeN(), next, Link::next, and NULL.

int IDP_InsertToGroup ( struct IDProperty group,
struct IDProperty previous,
struct IDProperty pnew 
)

this is the same as IDP_AddToGroup, only you pass an item in the group list to be inserted after.

Definition at line 518 of file idprop.c.

References BLI_insertlink(), IDProperty::data, IDPropertyData::group, IDP_GetPropertyFromGroup(), IDProperty::len, IDProperty::name, and NULL.

void IDP_LinkID ( IDProperty prop,
ID id 
)

Definition at line 397 of file idprop.c.

References IDProperty::data, id_us_plus(), and IDPropertyData::pointer.

IDProperty* IDP_New ( const int  type,
const IDPropertyTemplate val,
const char *  name 
) [read]

Allocate a new ID.

This function takes three arguments: the ID property type, a union which defines it's initial value, and a name.

The union is simple to use; see the top of this header file for its definition. An example of using this function:

IDPropertyTemplate val; IDProperty *group, *idgroup, *color; group = IDP_New(IDP_GROUP, val, "group1"); //groups don't need a template.

val.array.len = 4 val.array.type = IDP_FLOAT; color = IDP_New(IDP_ARRAY, val, "color1");

idgroup = IDP_GetProperties(some_id, 1); IDP_AddToGroup(idgroup, color); IDP_AddToGroup(idgroup, group);

Note that you MUST either attach the id property to an id property group with IDP_AddToGroup or MEM_freeN the property, doing anything else might result in a memory leak.

Definition at line 675 of file idprop.c.

References IDPropertyTemplate::array, IDPropertyTemplate::d, IDProperty::data, DEFAULT_ALLOC_FOR_NULL_STRINGS, IDPropertyTemplate::f, IDPropertyTemplate::i, IDP_ARRAY, IDP_DOUBLE, IDP_FLOAT, IDP_GROUP, IDP_INT, idp_size_table, IDP_STRING, IDP_STRING_SUB_BYTE, IDP_STRING_SUB_UTF8, if(), IDProperty::len, IDPropertyTemplate::len, MEM_callocN(), MEM_mallocN(), NULL, IDPropertyData::pointer, IDPropertyTemplate::str, IDPropertyTemplate::string, strlen(), IDPropertyTemplate::subtype, IDProperty::subtype, IDProperty::totallen, IDPropertyTemplate::type, and IDPropertyData::val.

Referenced by BPy_IDProperty_Map_ValidateAndCreate(), idp_resize_group_array(), RNA_property_boolean_set(), RNA_property_boolean_set_array(), RNA_property_collection_add(), RNA_property_enum_set(), RNA_property_float_set(), RNA_property_float_set_array(), RNA_property_int_set(), RNA_property_int_set_array(), RNA_property_pointer_add(), texture_paint_image_from_view_exec(), ui_menu_block_set_keymaps(), uiItemFullO(), uiLayoutOperatorButs(), wm_operator_create(), and WM_operator_properties_alloc().

IDProperty* IDP_NewIDPArray ( const char *  name)
IDProperty* IDP_NewString ( const char *  st,
const char *  name,
int  maxlen 
)
void IDP_RemFromGroup ( struct IDProperty group,
struct IDProperty prop 
)
Note:
this does not free the property!!

To free the property, you have to do: IDP_FreeProperty(prop); //free all subdata MEM_freeN(prop); //free property struct itself

Definition at line 529 of file idprop.c.

References BLI_remlink(), IDProperty::data, IDPropertyData::group, and IDProperty::len.

Referenced by BPy_IDGroup_Pop(), BPy_Wrap_SetMapItem(), rna_idproperty_check(), RNA_property_pointer_remove(), and RNA_struct_idprops_unset().

void IDP_ReplaceGroupInGroup ( struct IDProperty dest,
struct IDProperty src 
)

replaces all properties with the same name in a destination group from a source group.

Definition at line 460 of file idprop.c.

References BLI_addtail(), BLI_insertlink(), BLI_remlink(), copy(), IDProperty::data, ListBase::first, IDPropertyData::group, IDP_CopyProperty(), IDP_FreeProperty(), IDProperty::len, MEM_freeN(), IDProperty::name, IDProperty::next, and NULL.

Referenced by wm_operator_create().

void IDP_ReplaceInGroup ( struct IDProperty group,
struct IDProperty prop 
)

checks if a property with the same name as prop exists, and if so replaces it. Use this to preserve order!

Definition at line 489 of file idprop.c.

References BLI_addtail(), BLI_insertlink(), BLI_remlink(), IDProperty::data, IDPropertyData::group, IDP_FreeProperty(), IDP_GetPropertyFromGroup(), IDProperty::len, MEM_freeN(), and IDProperty::name.

Referenced by BPy_IDProperty_Map_ValidateAndCreate(), and wm_operator_init_from_last().

static void idp_resize_group_array ( IDProperty prop,
int  newlen,
void *  newarr 
) [static]
void IDP_ResizeArray ( IDProperty prop,
int  newlen 
)
void IDP_ResizeIDPArray ( IDProperty prop,
int  newlen 
)
void IDP_SetIndexArray ( IDProperty prop,
int  index,
IDProperty item 
)

Definition at line 111 of file idprop.c.

References GETPROP, IDP_FreeProperty(), and IDProperty::len.

Referenced by IDP_AppendArray().

void IDP_SyncGroupValues ( struct IDProperty dest,
struct IDProperty src 
)
void IDP_UnlinkID ( IDProperty prop)

Definition at line 404 of file idprop.c.

References IDProperty::data, and IDPropertyData::pointer.

Referenced by IDP_UnlinkProperty().

void IDP_UnlinkProperty ( struct IDProperty prop)

Unlinks any struct IDProperty<->ID linkage that might be going on.

Definition at line 787 of file idprop.c.

References IDP_ID, IDP_UnlinkID(), and IDProperty::type.


Variable Documentation

char idp_size_table[] [static]
Initial value:
 {
    1, 
    sizeof(int),
    sizeof(float),
    sizeof(float)*3, 
    sizeof(float)*16, 
    0, 
    sizeof(ListBase), 
    sizeof(void*),
    sizeof(double)
}

Definition at line 46 of file idprop.c.

Referenced by IDP_EqualsProperties(), IDP_New(), and IDP_ResizeArray().