- change max threads from 8 to 64, need to keep an eye on stack memory use here.
[blender.git] / source / blender / blenkernel / intern / idprop.c
index c2474e847ae79fee3c153e81268953b643642ddd..c2e4dbb6c096e82f7b1161248286723b1e7c2614 100644 (file)
@@ -167,7 +167,7 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
                for (i=newlen; i<prop->len; i++) {
                        IDP_FreeProperty(GETPROP(prop, i));
                }
-               memcpy(newarr, prop->data.pointer, newlen*prop->len*sizeof(IDProperty));
+               memcpy(newarr, prop->data.pointer, newlen*sizeof(IDProperty));
        }
 
        if(prop->data.pointer)
@@ -230,16 +230,16 @@ void IDP_ResizeArray(IDProperty *prop, int newlen)
         */
        newsize = (newsize >> 3) + (newsize < 9 ? 3 : 6) + newsize;
 
-       newarr = MEM_callocN(idp_size_table[prop->subtype]*newsize, "idproperty array resized");
+       newarr = MEM_callocN(idp_size_table[(int)prop->subtype]*newsize, "idproperty array resized");
        if (newlen >= prop->len) {
                /* newlen is bigger*/
-               memcpy(newarr, prop->data.pointer, prop->len*idp_size_table[prop->subtype]);
+               memcpy(newarr, prop->data.pointer, prop->len*idp_size_table[(int)prop->subtype]);
                idp_resize_group_array(prop, newlen, newarr);
        }
        else {
                /* newlen is smaller*/
                idp_resize_group_array(prop, newlen, newarr);
-               memcpy(newarr, prop->data.pointer, newlen*prop->len*idp_size_table[prop->subtype]);
+               memcpy(newarr, prop->data.pointer, newlen*prop->len*idp_size_table[(int)prop->subtype]);
        }
 
        MEM_freeN(prop->data.pointer);
@@ -385,6 +385,34 @@ IDProperty *IDP_CopyGroup(IDProperty *prop)
        return newp;
 }
 
+/*
+ replaces all properties with the same name in a destination group from a source group.
+*/
+void IDP_ReplaceGroupInGroup(IDProperty *dest, IDProperty *src)
+{
+       IDProperty *loop, *prop;
+       for (prop=src->data.group.first; prop; prop=prop->next) {
+               for (loop=dest->data.group.first; loop; loop=loop->next) {
+                       if (BSTR_EQ(loop->name, prop->name)) {
+                               IDProperty *copy = IDP_CopyProperty(prop);
+
+                               BLI_insertlink(&dest->data.group, loop, copy);
+
+                               BLI_remlink(&dest->data.group, loop);
+                               IDP_FreeProperty(loop);
+                               MEM_freeN(loop);
+                               break;
+                       }
+               }
+
+               /* only add at end if not added yet */
+               if (loop == NULL) {
+                       IDProperty *copy = IDP_CopyProperty(prop);
+                       dest->len++;
+                       BLI_addtail(&dest->data.group, copy);
+               }
+       }
+}
 /*
  replaces a property with the same name in a group, or adds 
  it if the propery doesn't exist.
@@ -394,8 +422,7 @@ void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop)
        IDProperty *loop;
        for (loop=group->data.group.first; loop; loop=loop->next) {
                if (BSTR_EQ(loop->name, prop->name)) {
-                       if (loop->next) BLI_insertlinkbefore(&group->data.group, loop->next, prop);
-                       else BLI_addtail(&group->data.group, prop);
+                       BLI_insertlink(&group->data.group, loop, prop);
                        
                        BLI_remlink(&group->data.group, loop);
                        IDP_FreeProperty(loop);
@@ -442,7 +469,7 @@ void IDP_RemFromGroup(IDProperty *group, IDProperty *prop)
        BLI_remlink(&group->data.group, prop);
 }
 
-IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, char *name)
+IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, const char *name)
 {
        IDProperty *loop;
        for (loop=prop->data.group.first; loop; loop=loop->next) {
@@ -488,14 +515,12 @@ void IDP_FreeIterBeforeEnd(void *vself)
   direct data.*/
 static void IDP_FreeGroup(IDProperty *prop)
 {
-       IDProperty *loop, *next;
-       for (loop=prop->data.group.first; loop; loop=next)
+       IDProperty *loop;
+       for (loop=prop->data.group.first; loop; loop=loop->next)
        {
-               next = loop->next;
-               BLI_remlink(&prop->data.group, loop);
                IDP_FreeProperty(loop);
-               MEM_freeN(loop);
        }
+       BLI_freelistN(&prop->data.group);
 }
 
 
@@ -527,6 +552,60 @@ IDProperty *IDP_GetProperties(ID *id, int create_if_needed)
        }
 }
 
+int IDP_EqualsProperties(IDProperty *prop1, IDProperty *prop2)
+{
+       if(prop1 == NULL && prop2 == NULL)
+               return 1;
+       else if(prop1 == NULL || prop2 == NULL)
+               return 0;
+       else if(prop1->type != prop2->type)
+               return 0;
+
+       if(prop1->type == IDP_INT)
+               return (IDP_Int(prop1) == IDP_Int(prop2));
+       else if(prop1->type == IDP_FLOAT)
+               return (IDP_Float(prop1) == IDP_Float(prop2));
+       else if(prop1->type == IDP_DOUBLE)
+               return (IDP_Double(prop1) == IDP_Double(prop2));
+       else if(prop1->type == IDP_STRING)
+               return BSTR_EQ(IDP_String(prop1), IDP_String(prop2));
+       else if(prop1->type == IDP_ARRAY) {
+               if(prop1->len == prop2->len && prop1->subtype == prop2->subtype)
+                       return memcmp(IDP_Array(prop1), IDP_Array(prop2), idp_size_table[(int)prop1->subtype]*prop1->len);
+               else
+                       return 0;
+       }
+       else if(prop1->type == IDP_GROUP) {
+               IDProperty *link1, *link2;
+
+               if(BLI_countlist(&prop1->data.group) != BLI_countlist(&prop2->data.group))
+                       return 0;
+
+               for(link1=prop1->data.group.first; link1; link1=link1->next) {
+                       link2= IDP_GetPropertyFromGroup(prop2, link1->name);
+
+                       if(!IDP_EqualsProperties(link1, link2))
+                               return 0;
+               }
+
+               return 1;
+       }
+       else if(prop1->type == IDP_IDPARRAY) {
+               IDProperty *array1= IDP_IDPArray(prop1);
+               IDProperty *array2= IDP_IDPArray(prop2);
+               int i;
+
+               if(prop1->len != prop2->len)
+                       return 0;
+               
+               for(i=0; i<prop1->len; i++)
+                       if(!IDP_EqualsProperties(&array1[i], &array2[i]))
+                               return 0;
+       }
+       
+       return 1;
+}
+
 IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name)
 {
        IDProperty *prop=NULL;