2010-08-08 10:06:34 +02:00
|
|
|
/*
|
2015-01-30 22:10:29 +01:00
|
|
|
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
2014-10-18 14:16:26 +02:00
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef ATTRIB_H
|
|
|
|
#define ATTRIB_H
|
2014-10-18 14:16:26 +02:00
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-10-18 14:16:26 +02:00
|
|
|
struct gamedata;
|
|
|
|
struct storage;
|
|
|
|
typedef void(*afun) (void);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-10-18 14:16:26 +02:00
|
|
|
typedef struct attrib {
|
|
|
|
const struct attrib_type *type;
|
|
|
|
union {
|
2015-07-12 10:35:09 +02:00
|
|
|
afun f; //TODO: V117 http://www.viva64.com/en/V117 Memsize type is used in the union.
|
|
|
|
void *v; //TODO: V117 http://www.viva64.com/en/V117 Memsize type is used in the union.
|
2014-10-18 14:16:26 +02:00
|
|
|
int i;
|
|
|
|
float flt;
|
|
|
|
char c;
|
|
|
|
short s;
|
|
|
|
short sa[2];
|
2015-07-12 10:35:09 +02:00
|
|
|
char ca[4]; //TODO: V112 http://www.viva64.com/en/V112 Dangerous magic number 4 used: char ca[4];.
|
2014-10-18 14:16:26 +02:00
|
|
|
} data;
|
|
|
|
/* internal data, do not modify: */
|
|
|
|
struct attrib *next; /* next attribute in the list */
|
|
|
|
struct attrib *nexttype; /* skip to attribute of a different type */
|
|
|
|
} attrib;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
#define ATF_UNIQUE (1<<0) /* only one per attribute-list */
|
|
|
|
#define ATF_PRESERVE (1<<1) /* preserve order in list. append to back */
|
2010-08-08 10:06:34 +02:00
|
|
|
#define ATF_USER_DEFINED (1<<2) /* use this to make udf */
|
|
|
|
|
2014-10-18 14:16:26 +02:00
|
|
|
typedef struct attrib_type {
|
|
|
|
const char *name;
|
|
|
|
void(*initialize) (struct attrib *);
|
|
|
|
void(*finalize) (struct attrib *);
|
|
|
|
int(*age) (struct attrib *);
|
|
|
|
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
|
|
|
|
void(*write) (const struct attrib *, const void *owner, struct storage *);
|
|
|
|
int(*read) (struct attrib *, void *owner, struct storage *); /* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
|
|
|
|
unsigned int flags;
|
|
|
|
/* ---- internal data, do not modify: ---- */
|
|
|
|
struct attrib_type *nexthash;
|
|
|
|
unsigned int hashkey;
|
|
|
|
} attrib_type;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-10-18 14:16:26 +02:00
|
|
|
extern void at_register(attrib_type * at);
|
|
|
|
extern void at_deprecate(const char * name, int(*reader)(attrib *, void *, struct storage *));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-10-18 14:16:26 +02:00
|
|
|
extern attrib *a_select(attrib * a, const void *data,
|
|
|
|
bool(*compare) (const attrib *, const void *));
|
|
|
|
extern attrib *a_find(attrib * a, const attrib_type * at);
|
|
|
|
extern const attrib *a_findc(const attrib * a, const attrib_type * at);
|
|
|
|
extern attrib *a_add(attrib ** pa, attrib * at);
|
|
|
|
extern int a_remove(attrib ** pa, attrib * at);
|
|
|
|
extern void a_removeall(attrib ** a, const attrib_type * at);
|
|
|
|
extern attrib *a_new(const attrib_type * at);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-10-18 14:16:26 +02:00
|
|
|
extern int a_age(attrib ** attribs);
|
|
|
|
extern int a_read(struct storage *store, attrib ** attribs, void *owner);
|
|
|
|
extern void a_write(struct storage *store, const attrib * attribs,
|
|
|
|
const void *owner);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-12-31 01:17:49 +01:00
|
|
|
void free_attribs(void);
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
#define DEFAULT_AGE NULL
|
|
|
|
#define DEFAULT_INIT NULL
|
|
|
|
#define DEFAULT_FINALIZE NULL
|
|
|
|
#define NO_WRITE NULL
|
|
|
|
#define NO_READ NULL
|
|
|
|
|
|
|
|
#define AT_READ_OK 0
|
|
|
|
#define AT_READ_FAIL -1
|
|
|
|
|
2015-07-03 17:36:37 +02:00
|
|
|
#define AT_AGE_KEEP 0 /* keep the attribute for another turn */
|
|
|
|
#define AT_AGE_REMOVE 1 /* remove the attribute after calling age() */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|