Blender V2.61 - r43446

BKE_idprop.h

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