[Bf-committers] Patch 6402 Bug in IDProperty handling of matrices
and vectors
Hannu Parviainen
hannu at astro.helsinki.fi
Sat Apr 14 15:15:04 CEST 2007
> Is RM_GetPropertyPointer a utility function you wrote? If so,
> submitting utility functions to the patch tracker (assigned to me) is
> great, since the C API of id properties still needs some
> review/improvement.
Yes, it is a utility function, but it is a bit specific to the Renderman
integration I've been working with,
so I doubt it is of much use.
I've got RM_GetPropertyPointer, RM_GetAttributePointer and
RM_GetOptionPointer functions,
as well as functions to set properties, attributes and options, and
several other utility
functions for convenience. The code for the function is simple (shown
for the general properties
and Renderman options)
void *rm_GetPropertyPointer(ID *id, char *propName, int propType, int
create){
IDProperty *rmg, *idp;
if((rmg = IDP_GetProperties(id, 0)) != NULL){
if((rmg = IDP_GetPropertyFromGroup(rmg, "Renderman")) != NULL){
if((idp = IDP_GetPropertyFromGroup(rmg, propName)) != NULL){
switch(idp->type){
case IDP_FLOAT:
return &idp->data.val;
case IDP_INT:
return &idp->data.val;
case IDP_STRING:
return idp->data.pointer;
case IDP_VECTOR:
return idp->data.pointer;
default:
fprintf(stderr, "Error: Unsupported type identifier.\n");
return NULL;
}
}
}
}
if(create){
return rm_SetProperty(id, propName, propType, NULL);
}
else
return NULL;
}
void *rm_GetOptionPointer(ID *id, char *optGroupName, char *optName, int
optType, int create){
IDProperty *idg, *idp;
idg = IDP_GetProperties(id, 0);
if((idp = IDP_GetPropertyFromGroup(idg, "Renderman")) != NULL){
if((idp = IDP_GetPropertyFromGroup(idp, "Options")) != NULL){
if((idp = IDP_GetPropertyFromGroup(idp, optGroupName)) != NULL){
if((idp = IDP_GetPropertyFromGroup(idp, optName)) != NULL){
switch(idp->type){
case IDP_INT:
return &idp->data.val;
break;
case IDP_FLOAT:
return &idp->data.val;
break;
case IDP_STRING:
return idp->data.pointer;
break;
case IDP_VECTOR:
return idp->data.pointer;
break;
default:
return NULL;
}
}
}
}
}
if(create){
return rm_SetOption(id, optGroupName, optName, optType, NULL);
}
else
return NULL;
}
> Anyway, could you post the code for RM_GetPropertyPointer? Also, you
> probably need to set the id property len property of the string to the
> string's length + 1. Strings in ID properties are always assumed to
> have the correct string_property->len set; this might be a bad idea,
> and one I might be able to do away with via the magic of MEM_alloc_len.
I'm using the IDP_New() to create the string properties, and I'm not
modifying them afterwards
(other than reading from and writing to the allowed memory space), but
maybe I'll have to recheck
this, thanks.
Hannu
More information about the Bf-committers
mailing list