2011-02-18 14:05:18 +01:00
|
|
|
/*
|
2008-04-17 00:40:48 +02:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2006-11-30 00:31:46 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-17 00:40:48 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2006-11-30 00:31:46 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 14:34:04 +01:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-11-30 00:31:46 +01:00
|
|
|
*
|
|
|
|
* Contributor(s): Joseph Eagar
|
|
|
|
*
|
2008-04-17 00:40:48 +02:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2006-11-30 00:31:46 +01:00
|
|
|
*/
|
|
|
|
|
2012-02-17 19:59:41 +01:00
|
|
|
#ifndef __BKE_IDPROP_H__
|
|
|
|
#define __BKE_IDPROP_H__
|
2006-11-17 05:46:48 +01:00
|
|
|
|
2011-02-18 14:05:18 +01:00
|
|
|
/** \file BKE_idprop.h
|
|
|
|
* \ingroup bke
|
|
|
|
* \author Joseph Eagar
|
|
|
|
*/
|
|
|
|
|
2006-11-17 05:46:48 +01:00
|
|
|
#include "DNA_ID.h"
|
|
|
|
|
2013-09-01 17:01:15 +02:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
2006-11-17 05:46:48 +01:00
|
|
|
struct IDProperty;
|
|
|
|
struct ID;
|
|
|
|
|
2010-10-21 09:39:18 +02:00
|
|
|
typedef union IDPropertyTemplate {
|
2006-11-17 05:46:48 +01:00
|
|
|
int i;
|
|
|
|
float f;
|
2008-07-24 21:22:17 +02:00
|
|
|
double d;
|
2011-11-15 10:12:10 +01:00
|
|
|
struct {
|
|
|
|
char *str;
|
|
|
|
short len;
|
|
|
|
char subtype;
|
|
|
|
} string;
|
2006-11-17 05:46:48 +01:00
|
|
|
struct ID *id;
|
|
|
|
struct {
|
|
|
|
short type;
|
|
|
|
short len;
|
|
|
|
} array;
|
|
|
|
struct {
|
|
|
|
int matvec_size;
|
|
|
|
float *example;
|
|
|
|
} matrix_or_vector;
|
|
|
|
} IDPropertyTemplate;
|
|
|
|
|
2008-12-31 14:16:37 +01:00
|
|
|
/* ----------- Property Array Type ---------- */
|
|
|
|
|
2013-09-01 17:01:15 +02:00
|
|
|
IDProperty *IDP_NewIDPArray(const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2013-12-12 11:57:37 +01:00
|
|
|
IDProperty *IDP_CopyIDPArray(const IDProperty *array) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2008-12-31 14:16:37 +01:00
|
|
|
|
|
|
|
void IDP_FreeIDPArray(IDProperty *prop);
|
|
|
|
|
|
|
|
/* shallow copies item */
|
2013-09-01 17:01:15 +02:00
|
|
|
void IDP_SetIndexArray(struct IDProperty *prop, int index, struct IDProperty *item) ATTR_NONNULL();
|
|
|
|
struct IDProperty *IDP_GetIndexArray(struct IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2012-07-08 08:00:27 +02:00
|
|
|
void IDP_AppendArray(struct IDProperty *prop, struct IDProperty *item);
|
2008-12-31 14:16:37 +01:00
|
|
|
void IDP_ResizeIDPArray(struct IDProperty *prop, int len);
|
|
|
|
|
|
|
|
/* ----------- Numeric Array Type ----------- */
|
2006-11-17 05:46:48 +01:00
|
|
|
/*this function works for strings too!*/
|
|
|
|
void IDP_ResizeArray(struct IDProperty *prop, int newlen);
|
|
|
|
void IDP_FreeArray(struct IDProperty *prop);
|
|
|
|
|
|
|
|
/* ---------- String Type ------------ */
|
2013-09-01 17:01:15 +02:00
|
|
|
IDProperty *IDP_NewString(const char *st, const char *name, int maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2 /* 'name 'arg */); /* maxlen excludes '\0' */
|
|
|
|
void IDP_AssignString(struct IDProperty *prop, const char *st, int maxlen) ATTR_NONNULL(); /* maxlen excludes '\0' */
|
|
|
|
void IDP_ConcatStringC(struct IDProperty *prop, const char *st) ATTR_NONNULL();
|
|
|
|
void IDP_ConcatString(struct IDProperty *str1, struct IDProperty *append) ATTR_NONNULL();
|
|
|
|
void IDP_FreeString(struct IDProperty *prop) ATTR_NONNULL();
|
2006-11-17 05:46:48 +01:00
|
|
|
|
|
|
|
/*-------- ID Type -------*/
|
|
|
|
void IDP_LinkID(struct IDProperty *prop, ID *id);
|
|
|
|
void IDP_UnlinkID(struct IDProperty *prop);
|
|
|
|
|
|
|
|
/*-------- Group Functions -------*/
|
2007-05-22 06:41:21 +02:00
|
|
|
|
2011-04-08 11:31:13 +02:00
|
|
|
/** Sync values from one group to another, only where they match */
|
2013-12-12 11:57:37 +01:00
|
|
|
void IDP_SyncGroupValues(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL();
|
2013-12-12 14:28:35 +01:00
|
|
|
void IDP_SyncGroupTypes(struct IDProperty *dest, const struct IDProperty *src, const bool do_arraylen) ATTR_NONNULL();
|
2013-12-12 11:57:37 +01:00
|
|
|
void IDP_ReplaceGroupInGroup(struct IDProperty *dest, const struct IDProperty *src) ATTR_NONNULL();
|
2013-09-01 17:01:15 +02:00
|
|
|
void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
2013-12-12 11:57:37 +01:00
|
|
|
void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overwrite) ATTR_NONNULL();
|
|
|
|
bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
|
|
|
bool IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous,
|
2013-09-01 17:01:15 +02:00
|
|
|
struct IDProperty *pnew) ATTR_NONNULL(1 /* group */, 3 /* pnew */);
|
2013-10-16 07:29:28 +02:00
|
|
|
void IDP_RemoveFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
|
|
|
void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
|
2006-12-01 04:04:36 +01:00
|
|
|
|
2013-09-01 17:01:15 +02:00
|
|
|
IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
IDProperty *IDP_GetPropertyTypeFromGroup(struct IDProperty *prop, const char *name, const char type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2006-11-17 05:46:48 +01:00
|
|
|
|
|
|
|
/*-------- Main Functions --------*/
|
2013-12-12 11:57:37 +01:00
|
|
|
struct IDProperty *IDP_GetProperties(struct ID *id, const bool create_if_needed) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
struct IDProperty *IDP_CopyProperty(const struct IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2006-11-17 05:46:48 +01:00
|
|
|
|
2013-12-12 11:57:37 +01:00
|
|
|
bool IDP_EqualsProperties_ex(IDProperty *prop1, IDProperty *prop2, const bool is_strict) ATTR_WARN_UNUSED_RESULT;
|
2012-10-31 21:29:32 +01:00
|
|
|
|
2013-12-12 11:57:37 +01:00
|
|
|
bool IDP_EqualsProperties(struct IDProperty *prop1, struct IDProperty *prop2) ATTR_WARN_UNUSED_RESULT;
|
2009-01-29 00:29:27 +01:00
|
|
|
|
2013-09-01 17:01:15 +02:00
|
|
|
struct IDProperty *IDP_New(const int type, const IDPropertyTemplate *val, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2011-04-08 11:31:13 +02:00
|
|
|
|
2006-11-17 05:46:48 +01:00
|
|
|
void IDP_FreeProperty(struct IDProperty *prop);
|
|
|
|
|
2013-01-03 00:10:14 +01:00
|
|
|
void IDP_ClearProperty(IDProperty *prop);
|
|
|
|
|
2006-11-17 05:46:48 +01:00
|
|
|
void IDP_UnlinkProperty(struct IDProperty *prop);
|
|
|
|
|
2012-11-03 19:23:30 +01:00
|
|
|
#define IDP_Int(prop) ((prop)->data.val)
|
|
|
|
#define IDP_Array(prop) ((prop)->data.pointer)
|
2014-08-01 13:59:42 +02:00
|
|
|
/* C11 const correctness for casts */
|
|
|
|
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
2014-08-04 03:43:10 +02:00
|
|
|
# define IDP_Float(prop) _Generic((prop), \
|
2014-08-01 13:59:42 +02:00
|
|
|
IDProperty *: (*(float *)&(prop)->data.val), \
|
|
|
|
const IDProperty *: (*(const float *)&(prop)->data.val))
|
2014-08-04 03:43:10 +02:00
|
|
|
# define IDP_Double(prop) _Generic((prop), \
|
2014-08-01 13:59:42 +02:00
|
|
|
IDProperty *: (*(double *)&(prop)->data.val), \
|
|
|
|
const IDProperty *: (*(const double *)&(prop)->data.val))
|
2014-08-04 03:43:10 +02:00
|
|
|
# define IDP_String(prop) _Generic((prop), \
|
2014-08-01 13:59:42 +02:00
|
|
|
IDProperty *: ((char *) (prop)->data.pointer), \
|
|
|
|
const IDProperty *: ((const char *) (prop)->data.pointer))
|
2014-08-04 03:43:10 +02:00
|
|
|
# define IDP_IDPArray(prop) _Generic((prop), \
|
2014-08-01 13:59:42 +02:00
|
|
|
IDProperty *: ((IDProperty *) (prop)->data.pointer), \
|
|
|
|
const IDProperty *: ((const IDProperty *) (prop)->data.pointer))
|
|
|
|
#else
|
|
|
|
# define IDP_Float(prop) (*(float *)&(prop)->data.val)
|
|
|
|
# define IDP_Double(prop) (*(double *)&(prop)->data.val)
|
|
|
|
# define IDP_String(prop) ((char *) (prop)->data.pointer)
|
|
|
|
# define IDP_IDPArray(prop) ((IDProperty *) (prop)->data.pointer)
|
|
|
|
#endif
|
2008-05-11 22:40:55 +02:00
|
|
|
|
2014-08-11 16:58:42 +02:00
|
|
|
#ifndef NDEBUG
|
2012-10-31 21:29:32 +01:00
|
|
|
/* for printout only */
|
|
|
|
void IDP_spit(IDProperty *prop);
|
|
|
|
#endif
|
|
|
|
|
2012-02-17 19:59:41 +01:00
|
|
|
#endif /* __BKE_IDPROP_H__ */
|