Blender  V2.59
BKE_idprop.h
Go to the documentation of this file.
00001 /*
00002  * $Id: BKE_idprop.h 36053 2011-04-08 09:31:13Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * Contributor(s): Joseph Eagar
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027  
00028 #ifndef _BKE_IDPROP_H
00029 #define _BKE_IDPROP_H
00030 
00036 #include "DNA_ID.h"
00037 
00038 struct IDProperty;
00039 struct ID;
00040 
00041 typedef union IDPropertyTemplate {
00042         int i;
00043         float f;
00044         double d;
00045         char *str;
00046         struct ID *id;
00047         struct {
00048                 short type;
00049                 short len;
00050         } array;
00051         struct {
00052                 int matvec_size;
00053                 float *example;
00054         } matrix_or_vector;
00055 } IDPropertyTemplate;
00056 
00057 /* ----------- Property Array Type ---------- */
00058 
00059 /*note: as a start to move away from the stupid IDP_New function, this type
00060   has it's own allocation function.*/
00061 IDProperty *IDP_NewIDPArray(const char *name);
00062 IDProperty *IDP_CopyIDPArray(IDProperty *array);
00063 
00064 void IDP_FreeIDPArray(IDProperty *prop);
00065 
00066 /* shallow copies item */
00067 void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item);
00068 struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index);
00069 struct IDProperty *IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item);
00070 void IDP_ResizeIDPArray(struct IDProperty *prop, int len);
00071 
00072 /* ----------- Numeric Array Type ----------- */
00073 /*this function works for strings too!*/
00074 void IDP_ResizeArray(struct IDProperty *prop, int newlen);
00075 void IDP_FreeArray(struct IDProperty *prop);
00076 void IDP_UnlinkArray(struct IDProperty *prop);
00077 
00078 /* ---------- String Type ------------ */
00079 IDProperty *IDP_NewString(const char *st, const char *name, int maxlen);/* maxlen excludes '\0' */
00080 void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen);     /* maxlen excludes '\0' */
00081 void IDP_ConcatStringC(struct IDProperty *prop, const char *st);
00082 void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append);
00083 void IDP_FreeString(struct IDProperty *prop);
00084 
00085 /*-------- ID Type -------*/
00086 void IDP_LinkID(struct IDProperty *prop, ID *id);
00087 void IDP_UnlinkID(struct IDProperty *prop);
00088 
00089 /*-------- Group Functions -------*/
00090 
00092 void IDP_SyncGroupValues(struct IDProperty *dest, struct IDProperty *src);
00093 
00097 void IDP_ReplaceGroupInGroup(struct IDProperty *dest, struct IDProperty *src);
00098 
00101 void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop);
00102 
00118 int IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop);
00119 
00122 int IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous, 
00123                                           struct IDProperty *pnew);
00124 
00132 void IDP_RemFromGroup(struct IDProperty *group, struct IDProperty *prop);
00133 
00134 IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, const char *name);
00136 IDProperty *IDP_GetPropertyTypeFromGroup(struct IDProperty *prop, const char *name, const char type);
00137 
00142 void *IDP_GetGroupIterator(struct IDProperty *prop);
00143 
00148 IDProperty *IDP_GroupIterNext(void *vself);
00149 
00152 void IDP_FreeIterBeforeEnd(void *vself);
00153 
00154 /*-------- Main Functions --------*/
00158 struct IDProperty *IDP_GetProperties(struct ID *id, int create_if_needed);
00159 struct IDProperty *IDP_CopyProperty(struct IDProperty *prop);
00160 
00161 int IDP_EqualsProperties(struct IDProperty *prop1, struct IDProperty *prop2);
00162 
00188 struct IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name);
00189 
00193 void IDP_FreeProperty(struct IDProperty *prop);
00194 
00196 void IDP_UnlinkProperty(struct IDProperty *prop);
00197 
00198 #define IDP_Int(prop) ((prop)->data.val)
00199 #define IDP_Float(prop) (*(float*)&(prop)->data.val)
00200 #define IDP_String(prop) ((char*)(prop)->data.pointer)
00201 #define IDP_Array(prop) ((prop)->data.pointer)
00202 #define IDP_IDPArray(prop) ((IDProperty*)(prop)->data.pointer)
00203 #define IDP_Double(prop) (*(double*)&(prop)->data.val)
00204 
00205 #endif /* _BKE_IDPROP_H */