diff options
author | Haru <haru@dotalux.com> | 2016-02-20 03:00:09 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2016-03-20 18:32:07 +0100 |
commit | 13dcf1e6c32b672e72f70a6cdbb42b4c3a2df3d8 (patch) | |
tree | 28d87e3e5219d5beb5e2dcf0f714e27184818940 /src/common | |
parent | 68c5122499f0cc2f4ce224c1ac82b6ec47d6abbe (diff) | |
download | hercules-13dcf1e6c32b672e72f70a6cdbb42b4c3a2df3d8.tar.gz hercules-13dcf1e6c32b672e72f70a6cdbb42b4c3a2df3d8.tar.bz2 hercules-13dcf1e6c32b672e72f70a6cdbb42b4c3a2df3d8.tar.xz hercules-13dcf1e6c32b672e72f70a6cdbb42b4c3a2df3d8.zip |
Dropped typedefs from union DBKey and struct DBData
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/db.c | 190 | ||||
-rw-r--r-- | src/common/db.h | 118 |
2 files changed, 154 insertions, 154 deletions
diff --git a/src/common/db.c b/src/common/db.c index 4b8e16b5d..639d42156 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -161,8 +161,8 @@ typedef struct dbn { struct dbn *left; struct dbn *right; // Node data - DBKey key; - DBData data; + union DBKey key; + struct DBData data; // Other enum DBNodeColor color; unsigned deleted : 1; @@ -447,7 +447,7 @@ static void db_rotate_right(DBNode *node, DBNode **root) * @private * @see #db_rotate_left(DBNode *,DBNode **) * @see #db_rotate_right(DBNode *,DBNode **) - * @see #db_obj_put(DBMap*,DBKey,DBData) + * @see #db_obj_put() */ static void db_rebalance(DBNode *node, DBNode **root) { @@ -648,11 +648,11 @@ static void db_rebalance_erase(DBNode *node, DBNode **root) * @param key Key being tested * @return not 0 if considered NULL, 0 otherwise * @private - * @see #db_obj_get(DBMap*,DBKey) - * @see #db_obj_put(DBMap*,DBKey,DBData) - * @see #db_obj_remove(DBMap*,DBKey) + * @see #db_obj_get() + * @see #db_obj_put() + * @see #db_obj_remove() */ -static int db_is_key_null(enum DBType type, DBKey key) +static int db_is_key_null(enum DBType type, union DBKey key) { DB_COUNTSTAT(db_is_key_null); switch (type) { @@ -673,10 +673,10 @@ static int db_is_key_null(enum DBType type, DBKey key) * @private * @see #db_free_add(DBMap_impl*,DBNode *,DBNode **) * @see #db_free_remove(DBMap_impl*,DBNode *) - * @see #db_obj_put(DBMap*,DBKey,void *) - * @see #db_dup_key_free(DBMap_impl*,DBKey) + * @see #db_obj_put() + * @see #db_dup_key_free() */ -static DBKey db_dup_key(DBMap_impl* db, DBKey key) +static union DBKey db_dup_key(DBMap_impl* db, union DBKey key) { char *str; size_t len; @@ -702,9 +702,9 @@ static DBKey db_dup_key(DBMap_impl* db, DBKey key) * @param db Database the key is being used in * @param key Key to be freed * @private - * @see #db_dup_key(DBMap_impl*,DBKey) + * @see #db_dup_key() */ -static void db_dup_key_free(DBMap_impl* db, DBKey key) +static void db_dup_key_free(DBMap_impl* db, union DBKey key) { DB_COUNTSTAT(db_dup_key_free); switch (db->type) { @@ -730,12 +730,12 @@ static void db_dup_key_free(DBMap_impl* db, DBKey key) * @see DBMap_impl#free_list * @see DBMap_impl#free_count * @see DBMap_impl#free_max - * @see #db_obj_remove(DBMap*,DBKey) + * @see #db_obj_remove() * @see #db_free_remove(DBMap_impl*,DBNode *) */ static void db_free_add(DBMap_impl* db, DBNode *node, DBNode **root) { - DBKey old_key; + union DBKey old_key; DB_COUNTSTAT(db_free_add); if (db->free_lock == (unsigned int)~0) { @@ -779,7 +779,7 @@ static void db_free_add(DBMap_impl* db, DBNode *node, DBNode **root) * @see #struct db_free * @see DBMap_impl#free_list * @see DBMap_impl#free_count - * @see #db_obj_put(DBMap*,DBKey,DBData) + * @see #db_obj_put() * @see #db_free_add(DBMap_impl*,DBNode**,DBNode*) */ static void db_free_remove(DBMap_impl* db, DBNode *node) @@ -893,7 +893,7 @@ static void db_free_unlock(DBMap_impl* db) * @see #DBComparator * @see #db_default_cmp() */ -static int db_int_cmp(DBKey key1, DBKey key2, unsigned short maxlen) +static int db_int_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen) { (void)maxlen;//not used DB_COUNTSTAT(db_int_cmp); @@ -915,7 +915,7 @@ static int db_int_cmp(DBKey key1, DBKey key2, unsigned short maxlen) * @see #DBComparator * @see #db_default_cmp() */ -static int db_uint_cmp(DBKey key1, DBKey key2, unsigned short maxlen) +static int db_uint_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen) { (void)maxlen;//not used DB_COUNTSTAT(db_uint_cmp); @@ -936,7 +936,7 @@ static int db_uint_cmp(DBKey key1, DBKey key2, unsigned short maxlen) * @see #DBComparator * @see #db_default_cmp() */ -static int db_string_cmp(DBKey key1, DBKey key2, unsigned short maxlen) +static int db_string_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen) { DB_COUNTSTAT(db_string_cmp); return strncmp((const char *)key1.str, (const char *)key2.str, maxlen); @@ -954,7 +954,7 @@ static int db_string_cmp(DBKey key1, DBKey key2, unsigned short maxlen) * @see #DBComparator * @see #db_default_cmp() */ -static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen) +static int db_istring_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen) { DB_COUNTSTAT(db_istring_cmp); return strncasecmp((const char *)key1.str, (const char *)key2.str, maxlen); @@ -973,7 +973,7 @@ static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen) * @see #DBComparator * @see #db_default_cmp() */ -static int db_int64_cmp(DBKey key1, DBKey key2, unsigned short maxlen) +static int db_int64_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen) { (void)maxlen;//not used DB_COUNTSTAT(db_int64_cmp); @@ -995,7 +995,7 @@ static int db_int64_cmp(DBKey key1, DBKey key2, unsigned short maxlen) * @see #DBComparator * @see #db_default_cmp() */ -static int db_uint64_cmp(DBKey key1, DBKey key2, unsigned short maxlen) +static int db_uint64_cmp(union DBKey key1, union DBKey key2, unsigned short maxlen) { (void)maxlen;//not used DB_COUNTSTAT(db_uint64_cmp); @@ -1016,7 +1016,7 @@ static int db_uint64_cmp(DBKey key1, DBKey key2, unsigned short maxlen) * @see #DBHasher * @see #db_default_hash() */ -static uint64 db_int_hash(DBKey key, unsigned short maxlen) +static uint64 db_int_hash(union DBKey key, unsigned short maxlen) { (void)maxlen;//not used DB_COUNTSTAT(db_int_hash); @@ -1034,7 +1034,7 @@ static uint64 db_int_hash(DBKey key, unsigned short maxlen) * @see #DBHasher * @see #db_default_hash() */ -static uint64 db_uint_hash(DBKey key, unsigned short maxlen) +static uint64 db_uint_hash(union DBKey key, unsigned short maxlen) { (void)maxlen;//not used DB_COUNTSTAT(db_uint_hash); @@ -1050,7 +1050,7 @@ static uint64 db_uint_hash(DBKey key, unsigned short maxlen) * @see #DBHasher * @see #db_default_hash() */ -static uint64 db_string_hash(DBKey key, unsigned short maxlen) +static uint64 db_string_hash(union DBKey key, unsigned short maxlen) { const char *k = key.str; unsigned int hash = 0; @@ -1076,7 +1076,7 @@ static uint64 db_string_hash(DBKey key, unsigned short maxlen) * @see enum DBType#DB_ISTRING * @see #db_default_hash() */ -static uint64 db_istring_hash(DBKey key, unsigned short maxlen) +static uint64 db_istring_hash(union DBKey key, unsigned short maxlen) { const char *k = key.str; unsigned int hash = 0; @@ -1105,7 +1105,7 @@ static uint64 db_istring_hash(DBKey key, unsigned short maxlen) * @see #DBHasher * @see #db_default_hash() */ -static uint64 db_int64_hash(DBKey key, unsigned short maxlen) +static uint64 db_int64_hash(union DBKey key, unsigned short maxlen) { (void)maxlen;//not used DB_COUNTSTAT(db_int64_hash); @@ -1123,7 +1123,7 @@ static uint64 db_int64_hash(DBKey key, unsigned short maxlen) * @see #DBHasher * @see #db_default_hash() */ -static uint64 db_uint64_hash(DBKey key, unsigned short maxlen) +static uint64 db_uint64_hash(union DBKey key, unsigned short maxlen) { (void)maxlen;//not used DB_COUNTSTAT(db_uint64_hash); @@ -1139,7 +1139,7 @@ static uint64 db_uint64_hash(DBKey key, unsigned short maxlen) * @see #DBReleaser * @see #db_default_releaser() */ -static void db_release_nothing(DBKey key, DBData data, enum DBReleaseOption which) +static void db_release_nothing(union DBKey key, struct DBData data, enum DBReleaseOption which) { (void)key;(void)data;(void)which;//not used DB_COUNTSTAT(db_release_nothing); @@ -1154,7 +1154,7 @@ static void db_release_nothing(DBKey key, DBData data, enum DBReleaseOption whic * @see #DBReleaser * @see #db_default_release() */ -static void db_release_key(DBKey key, DBData data, enum DBReleaseOption which) +static void db_release_key(union DBKey key, struct DBData data, enum DBReleaseOption which) { (void)data;//not used DB_COUNTSTAT(db_release_key); @@ -1167,12 +1167,12 @@ static void db_release_key(DBKey key, DBData data, enum DBReleaseOption which) * @param data Data of the database entry * @param which What is being requested to be released * @protected - * @see #DBData + * @see struct DBData * @see enum DBReleaseOption * @see #DBReleaser * @see #db_default_release() */ -static void db_release_data(DBKey key, DBData data, enum DBReleaseOption which) +static void db_release_data(union DBKey key, struct DBData data, enum DBReleaseOption which) { (void)key;//not used DB_COUNTSTAT(db_release_data); @@ -1188,13 +1188,13 @@ static void db_release_data(DBKey key, DBData data, enum DBReleaseOption which) * @param data Data of the database entry * @param which What is being requested to be released * @protected - * @see #DBKey - * @see #DBData + * @see union DBKey + * @see struct DBData * @see enum DBReleaseOption * @see #DBReleaser * @see #db_default_release() */ -static void db_release_both(DBKey key, DBData data, enum DBReleaseOption which) +static void db_release_both(union DBKey key, struct DBData data, enum DBReleaseOption which) { DB_COUNTSTAT(db_release_both); if (which&DB_RELEASE_KEY) aFree((char*)key.str); // needs to be a pointer @@ -1247,7 +1247,7 @@ static void db_release_both(DBKey key, DBData data, enum DBReleaseOption which) * @protected * @see DBIterator#first */ -DBData* dbit_obj_first(DBIterator* self, DBKey* out_key) +struct DBData *dbit_obj_first(DBIterator* self, union DBKey *out_key) { DBIterator_impl* it = (DBIterator_impl*)self; @@ -1269,7 +1269,7 @@ DBData* dbit_obj_first(DBIterator* self, DBKey* out_key) * @protected * @see DBIterator#last */ -DBData* dbit_obj_last(DBIterator* self, DBKey* out_key) +struct DBData *dbit_obj_last(DBIterator* self, union DBKey *out_key) { DBIterator_impl* it = (DBIterator_impl*)self; @@ -1291,7 +1291,7 @@ DBData* dbit_obj_last(DBIterator* self, DBKey* out_key) * @protected * @see DBIterator#next */ -DBData* dbit_obj_next(DBIterator* self, DBKey* out_key) +struct DBData *dbit_obj_next(DBIterator* self, union DBKey *out_key) { DBIterator_impl* it = (DBIterator_impl*)self; DBNode *node; @@ -1348,7 +1348,7 @@ DBData* dbit_obj_next(DBIterator* self, DBKey* out_key) {// found next entry it->node = node; if( out_key ) - memcpy(out_key, &node->key, sizeof(DBKey)); + memcpy(out_key, &node->key, sizeof(union DBKey)); return &node->data; } } @@ -1367,7 +1367,7 @@ DBData* dbit_obj_next(DBIterator* self, DBKey* out_key) * @protected * @see DBIterator#prev */ -DBData* dbit_obj_prev(DBIterator* self, DBKey* out_key) +struct DBData *dbit_obj_prev(DBIterator* self, union DBKey *out_key) { DBIterator_impl* it = (DBIterator_impl*)self; DBNode *node; @@ -1424,7 +1424,7 @@ DBData* dbit_obj_prev(DBIterator* self, DBKey* out_key) {// found previous entry it->node = node; if( out_key ) - memcpy(out_key, &node->key, sizeof(DBKey)); + memcpy(out_key, &node->key, sizeof(union DBKey)); return &node->data; } } @@ -1462,7 +1462,7 @@ bool dbit_obj_exists(DBIterator* self) * @see DBMap#remove * @see DBIterator#remove */ -int dbit_obj_remove(DBIterator* self, DBData *out_data) +int dbit_obj_remove(DBIterator* self, struct DBData *out_data) { DBIterator_impl* it = (DBIterator_impl*)self; DBNode *node; @@ -1477,7 +1477,7 @@ int dbit_obj_remove(DBIterator* self, DBData *out_data) db->cache = NULL; db->release(node->key, node->data, DB_RELEASE_DATA); if( out_data ) - memcpy(out_data, &node->data, sizeof(DBData)); + memcpy(out_data, &node->data, sizeof(struct DBData)); retval = 1; db_free_add(db, node, &db->ht[it->ht_index]); } @@ -1541,7 +1541,7 @@ static DBIterator* db_obj_iterator(DBMap* self) * @protected * @see DBMap#exists */ -static bool db_obj_exists(DBMap* self, DBKey key) +static bool db_obj_exists(DBMap* self, union DBKey key) { DBMap_impl* db = (DBMap_impl*)self; DBNode *node; @@ -1591,11 +1591,11 @@ static bool db_obj_exists(DBMap* self, DBKey key) * @protected * @see DBMap#get */ -static DBData* db_obj_get(DBMap* self, DBKey key) +static struct DBData *db_obj_get(DBMap* self, union DBKey key) { DBMap_impl* db = (DBMap_impl*)self; DBNode *node; - DBData *data = NULL; + struct DBData *data = NULL; DB_COUNTSTAT(db_get); if (db == NULL) return NULL; // nullpo candidate @@ -1650,7 +1650,7 @@ static DBData* db_obj_get(DBMap* self, DBKey key) * @protected * @see DBMap#vgetall */ -static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max, DBMatcher match, va_list args) +static unsigned int db_obj_vgetall(DBMap* self, struct DBData **buf, unsigned int max, DBMatcher match, va_list args) { DBMap_impl* db = (DBMap_impl*)self; unsigned int i; @@ -1722,7 +1722,7 @@ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max, * @see DBMap#vgetall * @see DBMap#getall */ -static unsigned int db_obj_getall(DBMap* self, DBData **buf, unsigned int max, DBMatcher match, ...) +static unsigned int db_obj_getall(DBMap* self, struct DBData **buf, unsigned int max, DBMatcher match, ...) { va_list args; unsigned int ret; @@ -1748,14 +1748,14 @@ static unsigned int db_obj_getall(DBMap* self, DBData **buf, unsigned int max, D * @protected * @see DBMap#vensure */ -static DBData* db_obj_vensure(DBMap* self, DBKey key, DBCreateData create, va_list args) +static struct DBData *db_obj_vensure(DBMap* self, union DBKey key, DBCreateData create, va_list args) { DBMap_impl* db = (DBMap_impl*)self; DBNode *node; DBNode *parent = NULL; unsigned int hash; int c = 0; - DBData *data = NULL; + struct DBData *data = NULL; DB_COUNTSTAT(db_vensure); if (db == NULL) return NULL; // nullpo candidate @@ -1848,10 +1848,10 @@ static DBData* db_obj_vensure(DBMap* self, DBKey key, DBCreateData create, va_li * @see DBMap#vensure * @see DBMap#ensure */ -static DBData* db_obj_ensure(DBMap* self, DBKey key, DBCreateData create, ...) +static struct DBData *db_obj_ensure(DBMap* self, union DBKey key, DBCreateData create, ...) { va_list args; - DBData *ret = NULL; + struct DBData *ret = NULL; DB_COUNTSTAT(db_ensure); if (self == NULL) return NULL; // nullpo candidate @@ -1877,7 +1877,7 @@ static DBData* db_obj_ensure(DBMap* self, DBKey key, DBCreateData create, ...) * FIXME: If this method fails shouldn't it return another value? * Other functions rely on this to know if they were able to put something [Panikon] */ -static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data) +static int db_obj_put(DBMap* self, union DBKey key, struct DBData data, struct DBData *out_data) { DBMap_impl* db = (DBMap_impl*)self; DBNode *node; @@ -1982,7 +1982,7 @@ static int db_obj_put(DBMap* self, DBKey key, DBData data, DBData *out_data) * @see #db_free_add(DBMap_impl*,DBNode*,DBNode **) * @see DBMap#remove */ -static int db_obj_remove(DBMap* self, DBKey key, DBData *out_data) +static int db_obj_remove(DBMap* self, union DBKey key, struct DBData *out_data) { DBMap_impl* db = (DBMap_impl*)self; DBNode *node; @@ -2372,17 +2372,17 @@ static enum DBOptions db_obj_options(DBMap* self) * db_default_release - Get the default releaser for a type of database with the specified options. * db_custom_release - Get a releaser that behaves a certain way. * db_alloc - Allocate a new database. - * db_i2key - Manual cast from 'int' to 'DBKey'. - * db_ui2key - Manual cast from 'unsigned int' to 'DBKey'. - * db_str2key - Manual cast from 'unsigned char *' to 'DBKey'. - * db_i642key - Manual cast from 'int64' to 'DBKey'. - * db_ui642key - Manual cast from 'uin64' to 'DBKey'. - * db_i2data - Manual cast from 'int' to 'DBData'. - * db_ui2data - Manual cast from 'unsigned int' to 'DBData'. - * db_ptr2data - Manual cast from 'void*' to 'DBData'. - * db_data2i - Gets 'int' value from 'DBData'. - * db_data2ui - Gets 'unsigned int' value from 'DBData'. - * db_data2ptr - Gets 'void*' value from 'DBData'. + * db_i2key - Manual cast from `int` to `union DBKey`. + * db_ui2key - Manual cast from `unsigned int` to `union DBKey`. + * db_str2key - Manual cast from `unsigned char *` to `union DBKey`. + * db_i642key - Manual cast from `int64` to `union DBKey`. + * db_ui642key - Manual cast from `uin64` to `union DBKey`. + * db_i2data - Manual cast from `int` to `struct DBData`. + * db_ui2data - Manual cast from `unsigned int` to `struct DBData`. + * db_ptr2data - Manual cast from `void*` to `struct DBData`. + * db_data2i - Gets `int` value from `struct DBData`. + * db_data2ui - Gets `unsigned int` value from `struct DBData`. + * db_data2ptr - Gets `void*` value from `struct DBData`. * db_init - Initializes the database system. * db_final - Finalizes the database system. \*****************************************************************************/ @@ -2421,12 +2421,12 @@ enum DBOptions db_fix_options(enum DBType type, enum DBOptions options) * @param type Type of database * @return Comparator for the type of database or NULL if unknown database * @public - * @see #db_int_cmp(DBKey,DBKey,unsigned short) - * @see #db_uint_cmp(DBKey,DBKey,unsigned short) - * @see #db_string_cmp(DBKey,DBKey,unsigned short) - * @see #db_istring_cmp(DBKey,DBKey,unsigned short) - * @see #db_int64_cmp(DBKey,DBKey,unsigned short) - * @see #db_uint64_cmp(DBKey,DBKey,unsigned short) + * @see #db_int_cmp() + * @see #db_uint_cmp() + * @see #db_string_cmp() + * @see #db_istring_cmp() + * @see #db_int64_cmp() + * @see #db_uint64_cmp() */ DBComparator db_default_cmp(enum DBType type) { @@ -2449,12 +2449,12 @@ DBComparator db_default_cmp(enum DBType type) * @param type Type of database * @return Hasher of the type of database or NULL if unknown database * @public - * @see #db_int_hash(DBKey,unsigned short) - * @see #db_uint_hash(DBKey,unsigned short) - * @see #db_string_hash(DBKey,unsigned short) - * @see #db_istring_hash(DBKey,unsigned short) - * @see #db_int64_hash(DBKey,unsigned short) - * @see #db_uint64_hash(DBKey,unsigned short) + * @see #db_int_hash() + * @see #db_uint_hash() + * @see #db_string_hash() + * @see #db_istring_hash() + * @see #db_int64_hash() + * @see #db_uint64_hash() */ DBHasher db_default_hash(enum DBType type) { @@ -2619,9 +2619,9 @@ DBMap* db_alloc(const char *file, const char *func, int line, enum DBType type, * @return The key as a DBKey union * @public */ -DBKey db_i2key(int key) +union DBKey db_i2key(int key) { - DBKey ret; + union DBKey ret; DB_COUNTSTAT(db_i2key); ret.i = key; @@ -2634,9 +2634,9 @@ DBKey db_i2key(int key) * @return The key as a DBKey union * @public */ -DBKey db_ui2key(unsigned int key) +union DBKey db_ui2key(unsigned int key) { - DBKey ret; + union DBKey ret; DB_COUNTSTAT(db_ui2key); ret.ui = key; @@ -2649,9 +2649,9 @@ DBKey db_ui2key(unsigned int key) * @return The key as a DBKey union * @public */ -DBKey db_str2key(const char *key) +union DBKey db_str2key(const char *key) { - DBKey ret; + union DBKey ret; DB_COUNTSTAT(db_str2key); ret.str = key; @@ -2664,9 +2664,9 @@ DBKey db_str2key(const char *key) * @return The key as a DBKey union * @public */ -DBKey db_i642key(int64 key) +union DBKey db_i642key(int64 key) { - DBKey ret; + union DBKey ret; DB_COUNTSTAT(db_i642key); ret.i64 = key; @@ -2679,9 +2679,9 @@ DBKey db_i642key(int64 key) * @return The key as a DBKey union * @public */ -DBKey db_ui642key(uint64 key) +union DBKey db_ui642key(uint64 key) { - DBKey ret; + union DBKey ret; DB_COUNTSTAT(db_ui642key); ret.ui64 = key; @@ -2694,9 +2694,9 @@ DBKey db_ui642key(uint64 key) * @return The data as a DBData struct * @public */ -DBData db_i2data(int data) +struct DBData db_i2data(int data) { - DBData ret; + struct DBData ret; DB_COUNTSTAT(db_i2data); ret.type = DB_DATA_INT; @@ -2710,9 +2710,9 @@ DBData db_i2data(int data) * @return The data as a DBData struct * @public */ -DBData db_ui2data(unsigned int data) +struct DBData db_ui2data(unsigned int data) { - DBData ret; + struct DBData ret; DB_COUNTSTAT(db_ui2data); ret.type = DB_DATA_UINT; @@ -2726,9 +2726,9 @@ DBData db_ui2data(unsigned int data) * @return The data as a DBData struct * @public */ -DBData db_ptr2data(void *data) +struct DBData db_ptr2data(void *data) { - DBData ret; + struct DBData ret; DB_COUNTSTAT(db_ptr2data); ret.type = DB_DATA_PTR; @@ -2743,7 +2743,7 @@ DBData db_ptr2data(void *data) * @return Integer value of the data. * @public */ -int db_data2i(DBData *data) +int db_data2i(struct DBData *data) { DB_COUNTSTAT(db_data2i); if (data && DB_DATA_INT == data->type) @@ -2758,7 +2758,7 @@ int db_data2i(DBData *data) * @return Unsigned int value of the data. * @public */ -unsigned int db_data2ui(DBData *data) +unsigned int db_data2ui(struct DBData *data) { DB_COUNTSTAT(db_data2ui); if (data && DB_DATA_UINT == data->type) @@ -2773,7 +2773,7 @@ unsigned int db_data2ui(DBData *data) * @return Void* value of the data. * @public */ -void* db_data2ptr(DBData *data) +void *db_data2ptr(struct DBData *data) { DB_COUNTSTAT(db_data2ptr); if (data && DB_DATA_PTR == data->type) diff --git a/src/common/db.h b/src/common/db.h index 02f917923..1c2da3917 100644 --- a/src/common/db.h +++ b/src/common/db.h @@ -43,8 +43,7 @@ * 2007/11/09 - Added an iterator to the database. * * 2.1 (Athena build #???#) - Portability fix * * - Fixed the portability of casting to union and added the functions * - * {@link DBMap#ensure(DBMap,DBKey,DBCreateData,...)} and * - * {@link DBMap#clear(DBMap,DBApply,...)}. * + * DBMap#ensure() and {@link DBMap#clear(DBMap,DBApply,...)}. * * 2.0 (Athena build 4859) - Transition version * * - Almost everything recoded with a strategy similar to objects, * * database structure is maintained. * @@ -69,9 +68,9 @@ * enum DBReleaseOption - Enumeration of release options. * * enum DBType - Enumeration of database types. * * enum DBOptions - Bitfield enumeration of database options. * - * DBKey - Union of used key types. * + * union DBKey - Union of used key types. * * enum DBDataType - Enumeration of data types. * - * DBData - Struct for used data types. * + * struct DBData - Struct for used data types. * * DBApply - Format of functions applied to the databases. * * DBMatcher - Format of matchers used in DBMap::getall. * * DBComparator - Format of the comparators used by the databases. * @@ -108,7 +107,7 @@ enum DBReleaseOption { * @param DB_UINT64 Uses uint64's for keys * @public * @see enum DBOptions - * @see #DBKey + * @see union DBKey * @see #db_fix_options() * @see #db_default_cmp() * @see #db_default_hash() @@ -167,13 +166,13 @@ enum DBOptions { * @see DBMap#put * @see DBMap#remove */ -typedef union DBKey { +union DBKey { int i; unsigned int ui; const char *str; int64 i64; uint64 ui64; -} DBKey; +}; /** * Supported types of database data. @@ -181,7 +180,7 @@ typedef union DBKey { * @param DB_DATA_UINT Uses unsigned ints for data. * @param DB_DATA_PTR Uses void pointers for data. * @public - * @see #DBData + * @see struct DBData */ enum DBDataType { DB_DATA_INT, @@ -198,14 +197,14 @@ enum DBDataType { * @param u.ptr Data of void* type * @public */ -typedef struct DBData { +struct DBData { enum DBDataType type; union { int i; unsigned int ui; void *ptr; } u; -} DBData; +}; /** * Format of functions that create the data for the key when the entry doesn't @@ -217,7 +216,7 @@ typedef struct DBData { * @see DBMap#vensure * @see DBMap#ensure */ -typedef DBData (*DBCreateData)(DBKey key, va_list args); +typedef struct DBData (*DBCreateData)(union DBKey key, va_list args); /** * Format of functions to be applied to an unspecified quantity of entries of @@ -234,7 +233,7 @@ typedef DBData (*DBCreateData)(DBKey key, va_list args); * @see DBMap#vdestroy * @see DBMap#destroy */ -typedef int (*DBApply)(DBKey key, DBData *data, va_list args); +typedef int (*DBApply)(union DBKey key, struct DBData *data, va_list args); /** * Format of functions that match database entries. @@ -247,7 +246,7 @@ typedef int (*DBApply)(DBKey key, DBData *data, va_list args); * @public * @see DBMap#getall */ -typedef int (*DBMatcher)(DBKey key, DBData data, va_list args); +typedef int (*DBMatcher)(union DBKey key, struct DBData data, va_list args); /** * Format of the comparators used internally by the database system. @@ -261,7 +260,7 @@ typedef int (*DBMatcher)(DBKey key, DBData data, va_list args); * @public * @see #db_default_cmp() */ -typedef int (*DBComparator)(DBKey key1, DBKey key2, unsigned short maxlen); +typedef int (*DBComparator)(union DBKey key1, union DBKey key2, unsigned short maxlen); /** * Format of the hashers used internally by the database system. @@ -273,7 +272,7 @@ typedef int (*DBComparator)(DBKey key1, DBKey key2, unsigned short maxlen); * @public * @see #db_default_hash() */ -typedef uint64 (*DBHasher)(DBKey key, unsigned short maxlen); +typedef uint64 (*DBHasher)(union DBKey key, unsigned short maxlen); /** * Format of the releaser used by the database system. @@ -287,7 +286,7 @@ typedef uint64 (*DBHasher)(DBKey key, unsigned short maxlen); * @see #db_default_releaser() * @see #db_custom_release() */ -typedef void (*DBReleaser)(DBKey key, DBData data, enum DBReleaseOption which); +typedef void (*DBReleaser)(union DBKey key, struct DBData data, enum DBReleaseOption which); typedef struct DBIterator DBIterator; typedef struct DBMap DBMap; @@ -313,7 +312,7 @@ struct DBIterator * @return Data of the entry * @protected */ - DBData* (*first)(DBIterator* self, DBKey* out_key); + struct DBData *(*first)(DBIterator* self, union DBKey *out_key); /** * Fetches the last entry in the database. @@ -324,7 +323,7 @@ struct DBIterator * @return Data of the entry * @protected */ - DBData* (*last)(DBIterator* self, DBKey* out_key); + struct DBData *(*last)(DBIterator* self, union DBKey *out_key); /** * Fetches the next entry in the database. @@ -335,7 +334,7 @@ struct DBIterator * @return Data of the entry * @protected */ - DBData* (*next)(DBIterator* self, DBKey* out_key); + struct DBData *(*next)(DBIterator* self, union DBKey *out_key); /** * Fetches the previous entry in the database. @@ -346,7 +345,7 @@ struct DBIterator * @return Data of the entry * @protected */ - DBData* (*prev)(DBIterator* self, DBKey* out_key); + struct DBData *(*prev)(DBIterator* self, union DBKey *out_key); /** * Returns true if the fetched entry exists. @@ -369,7 +368,7 @@ struct DBIterator * @protected * @see DBMap#remove */ - int (*remove)(DBIterator* self, DBData *out_data); + int (*remove)(DBIterator* self, struct DBData *out_data); /** * Destroys this iterator and unlocks the database. @@ -406,7 +405,7 @@ struct DBMap { * @return true is the entry exists * @protected */ - bool (*exists)(DBMap* self, DBKey key); + bool (*exists)(DBMap* self, union DBKey key); /** * Get the data of the entry identified by the key. @@ -415,7 +414,7 @@ struct DBMap { * @return Data of the entry or NULL if not found * @protected */ - DBData* (*get)(DBMap* self, DBKey key); + struct DBData *(*get)(DBMap* self, union DBKey key); /** * Just calls {@link DBMap#vgetall}. @@ -434,7 +433,7 @@ struct DBMap { * @protected * @see DBMap#vgetall(DBMap*,void **,unsigned int,DBMatcher,va_list) */ - unsigned int (*getall)(DBMap* self, DBData** buf, unsigned int max, DBMatcher match, ...); + unsigned int (*getall)(DBMap* self, struct DBData **buf, unsigned int max, DBMatcher match, ...); /** * Get the data of the entries matched by <code>match</code>. @@ -452,22 +451,23 @@ struct DBMap { * @protected * @see DBMap#getall(DBMap*,void **,unsigned int,DBMatcher,...) */ - unsigned int (*vgetall)(DBMap* self, DBData** buf, unsigned int max, DBMatcher match, va_list args); + unsigned int (*vgetall)(DBMap* self, struct DBData **buf, unsigned int max, DBMatcher match, va_list args); /** - * Just calls {@link DBMap#vensure}. - * Get the data of the entry identified by the key. - * If the entry does not exist, an entry is added with the data returned by - * <code>create</code>. + * Just calls DBMap#vensure. + * + * Get the data of the entry identified by the key. If the entry does + * not exist, an entry is added with the data returned by `create`. + * * @param self Database * @param key Key that identifies the entry * @param create Function used to create the data if the entry doesn't exist * @param ... Extra arguments for create * @return Data of the entry * @protected - * @see DBMap#vensure(DBMap*,DBKey,DBCreateData,va_list) + * @see DBMap#vensure() */ - DBData* (*ensure)(DBMap* self, DBKey key, DBCreateData create, ...); + struct DBData *(*ensure)(DBMap* self, union DBKey key, DBCreateData create, ...); /** * Get the data of the entry identified by the key. @@ -479,9 +479,9 @@ struct DBMap { * @param args Extra arguments for create * @return Data of the entry * @protected - * @see DBMap#ensure(DBMap*,DBKey,DBCreateData,...) + * @see DBMap#ensure() */ - DBData* (*vensure)(DBMap* self, DBKey key, DBCreateData create, va_list args); + struct DBData *(*vensure)(DBMap* self, union DBKey key, DBCreateData create, va_list args); /** * Put the data identified by the key in the database. @@ -494,7 +494,7 @@ struct DBMap { * @return 1 if if the entry already exists, 0 otherwise * @protected */ - int (*put)(DBMap* self, DBKey key, DBData data, DBData *out_data); + int (*put)(DBMap* self, union DBKey key, struct DBData data, struct DBData *out_data); /** * Remove an entry from the database. @@ -506,7 +506,7 @@ struct DBMap { * @return 1 if if the entry already exists, 0 otherwise * @protected */ - int (*remove)(DBMap* self, DBKey key, DBData *out_data); + int (*remove)(DBMap* self, union DBKey key, struct DBData *out_data); /** * Just calls {@link DBMap#vforeach}. @@ -714,7 +714,7 @@ struct DBMap { #define dbi_exists(dbi) ( (dbi)->exists(dbi) ) #define dbi_destroy(dbi) ( (dbi)->destroy(dbi) ) -/*****************************************************************************\ +/***************************************************************************** * (2) Section with public functions. * * db_fix_options - Fix the options for a type of database. * * db_default_cmp - Get the default comparator for a type of database. * @@ -723,20 +723,20 @@ struct DBMap { * with the fixed options. * * db_custom_release - Get the releaser that behaves as specified. * * db_alloc - Allocate a new database. * - * db_i2key - Manual cast from 'int' to 'DBKey'. * - * db_ui2key - Manual cast from 'unsigned int' to 'DBKey'. * - * db_str2key - Manual cast from 'unsigned char *' to 'DBKey'. * - * db_i642key - Manual cast from 'int64' to 'DBKey'. * - * db_ui642key - Manual cast from 'uint64' to 'DBKey'. * - * db_i2data - Manual cast from 'int' to 'DBData'. * - * db_ui2data - Manual cast from 'unsigned int' to 'DBData'. * - * db_ptr2data - Manual cast from 'void*' to 'DBData'. * - * db_data2i - Gets 'int' value from 'DBData'. * - * db_data2ui - Gets 'unsigned int' value from 'DBData'. * - * db_data2ptr - Gets 'void*' value from 'DBData'. * + * db_i2key - Manual cast from `int` to `union DBKey`. * + * db_ui2key - Manual cast from `unsigned int` to `union DBKey`. * + * db_str2key - Manual cast from `unsigned char *` to `union DBKey`.* + * db_i642key - Manual cast from `int64` to `union DBKey`. * + * db_ui642key - Manual cast from `uint64` to `union DBKey`. * + * db_i2data - Manual cast from `int` to `struct DBData`. * + * db_ui2data - Manual cast from `unsigned int` to `struct DBData`. * + * db_ptr2data - Manual cast from `void*` to `struct DBData`. * + * db_data2i - Gets `int` value from `struct DBData`. * + * db_data2ui - Gets `unsigned int` value from `struct DBData`. * + * db_data2ptr - Gets `void*` value from `struct DBData`. * * db_init - Initializes the database system. * * db_final - Finalizes the database system. * -\*****************************************************************************/ + *****************************************************************************/ struct db_interface { /** @@ -835,7 +835,7 @@ DBMap* (*alloc) (const char *file, const char *func, int line, enum DBType type, * @return The key as a DBKey union * @public */ -DBKey (*i2key) (int key); +union DBKey (*i2key) (int key); /** * Manual cast from 'unsigned int' to the union DBKey. @@ -843,7 +843,7 @@ DBKey (*i2key) (int key); * @return The key as a DBKey union * @public */ -DBKey (*ui2key) (unsigned int key); +union DBKey (*ui2key) (unsigned int key); /** * Manual cast from 'unsigned char *' to the union DBKey. @@ -851,7 +851,7 @@ DBKey (*ui2key) (unsigned int key); * @return The key as a DBKey union * @public */ -DBKey (*str2key) (const char *key); +union DBKey (*str2key) (const char *key); /** * Manual cast from 'int64' to the union DBKey. @@ -859,7 +859,7 @@ DBKey (*str2key) (const char *key); * @return The key as a DBKey union * @public */ -DBKey (*i642key) (int64 key); +union DBKey (*i642key) (int64 key); /** * Manual cast from 'uint64' to the union DBKey. @@ -867,7 +867,7 @@ DBKey (*i642key) (int64 key); * @return The key as a DBKey union * @public */ -DBKey (*ui642key) (uint64 key); +union DBKey (*ui642key) (uint64 key); /** * Manual cast from 'int' to the struct DBData. @@ -875,7 +875,7 @@ DBKey (*ui642key) (uint64 key); * @return The data as a DBData struct * @public */ -DBData (*i2data) (int data); +struct DBData (*i2data) (int data); /** * Manual cast from 'unsigned int' to the struct DBData. @@ -883,7 +883,7 @@ DBData (*i2data) (int data); * @return The data as a DBData struct * @public */ -DBData (*ui2data) (unsigned int data); +struct DBData (*ui2data) (unsigned int data); /** * Manual cast from 'void *' to the struct DBData. @@ -891,7 +891,7 @@ DBData (*ui2data) (unsigned int data); * @return The data as a DBData struct * @public */ -DBData (*ptr2data) (void *data); +struct DBData (*ptr2data) (void *data); /** * Gets int type data from struct DBData. @@ -900,7 +900,7 @@ DBData (*ptr2data) (void *data); * @return Integer value of the data. * @public */ -int (*data2i) (DBData *data); +int (*data2i) (struct DBData *data); /** * Gets unsigned int type data from struct DBData. @@ -909,7 +909,7 @@ int (*data2i) (DBData *data); * @return Unsigned int value of the data. * @public */ -unsigned int (*data2ui) (DBData *data); +unsigned int (*data2ui) (struct DBData *data); /** * Gets void* type data from struct DBData. @@ -918,7 +918,7 @@ unsigned int (*data2ui) (DBData *data); * @return Void* value of the data. * @public */ -void* (*data2ptr) (DBData *data); +void* (*data2ptr) (struct DBData *data); /** * Initialize the database system. |