summaryrefslogtreecommitdiff
path: root/src/map/map.c
diff options
context:
space:
mode:
authorgepard1984 <gepard1984@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-03-13 14:46:28 +0000
committergepard1984 <gepard1984@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-03-13 14:46:28 +0000
commitdc5babf8c3fb943a22c440f5afd6957b121926c5 (patch)
treefcf7000486b4172803ff2929c0b746013d0fb6a9 /src/map/map.c
parentd0932858a07e7df3159003c0b920c50e2e6a1b76 (diff)
downloadhercules-dc5babf8c3fb943a22c440f5afd6957b121926c5.tar.gz
hercules-dc5babf8c3fb943a22c440f5afd6957b121926c5.tar.bz2
hercules-dc5babf8c3fb943a22c440f5afd6957b121926c5.tar.xz
hercules-dc5babf8c3fb943a22c440f5afd6957b121926c5.zip
Enhanced `DBMap` implementation to allow storing integer type data in addition to void pointers.
- Added enum for data: `int`, `unsigned int` and `void*` - Replaced generic `void*` data with `DBData` struct to hold `int`, `unsigned int` or `void*` (member of `DBNode`) - Added `db_i2data`, `db_ui2data` and `db_ptr2data` functions to cast from `int`/`uint`/`void*` to `DBData` (used in `DBMap::put()`) - Added `db_data2i`, `db_data2ui` and `db_data2ptr` functions to get `int`/`uint`/`void*` from `DBData` - Enabled statistics for new functions in `db_stats` struct - `DBCreateData` functions (used in `DBMap::ensure()`) now return `DBData` instead of `void*` - `DBApply` functions (used in `DBMap::foreach()` and `DBMap::destroy()`) now take `DBData*` as a parameter instead of `void*` - `DBMatcher` functions (used in `DBMap::getall()`) now take `DBData` as a parameter instead of `void*` - `DBReleaser` functions now take `DBData` as parameter instead of `void*` - Default releasers release data if it is `void*` (`DB_DATA_PTR`) type - `DBIterator` functions: `first()`, `last()`, `next()` and `prev()` now return `DBData*` instead of `void*` - `DBIterator::remove()` now returns `int` (1 if node was found and removed, 0 otherwise) instead of `void*` and takes an extra `DBData*` parameter for the data of removed entry - `DBMap::get()` and `DBMap::ensure()` now return `DBData*` instead of `void*` - `DBMap::remove()` and `DBMap::put()` now return `int` (1 if node already existed, 0 otherwise) instead of `void*` and take an extra `DBData*` parameter for the data of removed entry - `DBMap::put()` now takes `DBData` as parameter instead of `void*` - `DBMap::getall()` now puts data into `DBData**` buffer instead of `void**` buffer - Updated macros: - (`i`/`ui`/`str`)`db_get` and (`i`/`ui`/`str`)`db_ensure` were wrapped with `db_data2ptr` to extract data from `DBData*` that is now returned by `DBMap::get()` - added (`i`/`ui`/`str`)`db_iget` and (`i`/`ui`/`str`)`db_uiget` that get `DBData` from `DBMap` and extract `int`/`unsigned int` from it (with `db_data2i`/`db_data2ui`) - `db_put`, `idb_put`, `uidb_put` and `strdb_put` data params were wrapped with `db_ptr2data` to match new signature of `DBMap::put()` (`DBData` instead of `void*`) - added (`i`/`ui`/`str`)`db_iput` and (`i`/`ui`/`str`)`db_uiput` that put `int`/`unsigned int` into `DBMap` (first wrapping it with `DBData`) - added `NULL` in place of extra parameter for removed data in `db_remove` macros - `dbi_first`, `dbi_last`, `dbi_next` and `dbi_prev` were wrapped with `db_data2ptr` to extract data from `DBData*` that is now returned by these `DBIterator` functions - Updated `DBMap` documentation, and fixed a dozen of typos in it. - Updated rest of rA code to reflect `DBMap` changes (mostly required signature changes of `DBCreateData` and `DBApply` functions). - Fixed a bug where `DBMap::put()` would return data of a deleted entry. - Removed some unnecessary pointer casts. - Increased `showmsg.c` static buffer size to fit entire DBMap stats report. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15682 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/map.c')
-rw-r--r--src/map/map.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 73a9445ef..172f921ea 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1472,11 +1472,14 @@ int map_addflooritem(struct item *item_data,int amount,int m,int x,int y,int fir
return fitem->bl.id;
}
-static void* create_charid2nick(DBKey key, va_list args)
+/**
+ * @see DBCreateData
+ */
+static DBData create_charid2nick(DBKey key, va_list args)
{
struct charid2nick *p;
CREATE(p, struct charid2nick, 1);
- return p;
+ return db_ptr2data(p);
}
/// Adds(or replaces) the nick of charid to nick_db and fullfils pending requests.
@@ -1490,7 +1493,7 @@ void map_addnickdb(int charid, const char* nick)
if( map_charid2sd(charid) )
return;// already online
- p = (struct charid2nick*)idb_ensure(nick_db, charid, create_charid2nick);
+ p = idb_ensure(nick_db, charid, create_charid2nick);
safestrncpy(p->nick, nick, sizeof(p->nick));
while( p->requests )
@@ -1511,8 +1514,10 @@ void map_delnickdb(int charid, const char* name)
struct charid2nick* p;
struct charid_request* req;
struct map_session_data* sd;
+ DBData data;
- p = (struct charid2nick*)idb_remove(nick_db, charid);
+ nick_db->remove(nick_db, db_i2key(charid), &data);
+ p = db_data2ptr(&data);
if( p == NULL )
return;
@@ -1546,7 +1551,7 @@ void map_reqnickdb(struct map_session_data * sd, int charid)
return;
}
- p = (struct charid2nick*)idb_ensure(nick_db, charid, create_charid2nick);
+ p = idb_ensure(nick_db, charid, create_charid2nick);
if( *p->nick )
{
clif_solved_charname(sd->fd, charid, p->nick);
@@ -1765,7 +1770,7 @@ const char* map_charid2nick(int charid)
if( sd )
return sd->status.name;// character is online, return it's name
- p = (struct charid2nick*)idb_ensure(nick_db, charid, create_charid2nick);
+ p = idb_ensure(nick_db, charid, create_charid2nick);
if( *p->nick )
return p->nick;// name in nick_db
@@ -2662,14 +2667,17 @@ void map_iwall_remove(const char *wall_name)
strdb_remove(iwall_db, iwall->wall_name);
}
-static void* create_map_data_other_server(DBKey key, va_list args)
+/**
+ * @see DBCreateData
+ */
+static DBData create_map_data_other_server(DBKey key, va_list args)
{
struct map_data_other_server *mdos;
unsigned short mapindex = (unsigned short)key.ui;
mdos=(struct map_data_other_server *)aCalloc(1,sizeof(struct map_data_other_server));
mdos->index = mapindex;
memcpy(mdos->name, mapindex_id2name(mapindex), MAP_NAME_LENGTH);
- return mdos;
+ return db_ptr2data(mdos);
}
/*==========================================
@@ -2679,7 +2687,7 @@ int map_setipport(unsigned short mapindex, uint32 ip, uint16 port)
{
struct map_data_other_server *mdos=NULL;
- mdos=(struct map_data_other_server *)uidb_ensure(map_db,(unsigned int)mapindex, create_map_data_other_server);
+ mdos= uidb_ensure(map_db,(unsigned int)mapindex, create_map_data_other_server);
if(mdos->cell) //Local map,Do nothing. Give priority to our own local maps over ones from another server. [Skotlex]
return 0;
@@ -2693,12 +2701,13 @@ int map_setipport(unsigned short mapindex, uint32 ip, uint16 port)
return 1;
}
-/*==========================================
+/**
* 他鯖管理のマップを全て削除
- *------------------------------------------*/
-int map_eraseallipport_sub(DBKey key,void *data,va_list va)
+ * @see DBApply
+ */
+int map_eraseallipport_sub(DBKey key, DBData *data, va_list va)
{
- struct map_data_other_server *mdos = (struct map_data_other_server*)data;
+ struct map_data_other_server *mdos = db_data2ptr(data);
if(mdos->cell == NULL) {
db_remove(map_db,key);
aFree(mdos);
@@ -3425,17 +3434,23 @@ int log_sql_init(void)
return 0;
}
-int map_db_final(DBKey k,void *d,va_list ap)
+/**
+ * @see DBApply
+ */
+int map_db_final(DBKey key, DBData *data, va_list ap)
{
- struct map_data_other_server *mdos = (struct map_data_other_server*)d;
+ struct map_data_other_server *mdos = db_data2ptr(data);
if(mdos && mdos->cell == NULL)
aFree(mdos);
return 0;
}
-int nick_db_final(DBKey key, void *data, va_list args)
+/**
+ * @see DBApply
+ */
+int nick_db_final(DBKey key, DBData *data, va_list args)
{
- struct charid2nick* p = (struct charid2nick*)data;
+ struct charid2nick* p = db_data2ptr(data);
struct charid_request* req;
if( p == NULL )
@@ -3478,9 +3493,12 @@ int cleanup_sub(struct block_list *bl, va_list ap)
return 1;
}
-static int cleanup_db_sub(DBKey key,void *data,va_list va)
+/**
+ * @see DBApply
+ */
+static int cleanup_db_sub(DBKey key, DBData *data, va_list va)
{
- return cleanup_sub((struct block_list*)data, va);
+ return cleanup_sub(db_data2ptr(data), va);
}
/*==========================================