From 1e77f5dc8d95bbf912205c85274d294a80ea65c9 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sat, 23 Feb 2013 14:28:21 -0800 Subject: Replace struct dbt with typesafe std::map wrappers Also fix broken save/accreg.txt reading. --- src/map/storage.cpp | 47 +++++++++++------------------------------------ 1 file changed, 11 insertions(+), 36 deletions(-) (limited to 'src/map/storage.cpp') diff --git a/src/map/storage.cpp b/src/map/storage.cpp index bcdf8bc..dcd0dd7 100644 --- a/src/map/storage.cpp +++ b/src/map/storage.cpp @@ -19,7 +19,7 @@ #include "../poison.hpp" static -struct dbt *storage_db; +Map storage_db; /*========================================== * 倉庫内アイテムソート @@ -40,13 +40,6 @@ int storage_comp_item(const void *_i1, const void *_i2) return i1->nameid - i2->nameid; } -static -void storage_db_final(db_key_t, db_val_t data) -{ - struct storage *stor = (struct storage *) data; - free(stor); -} - static void sortage_sortitem(struct storage *stor) { @@ -55,31 +48,22 @@ void sortage_sortitem(struct storage *stor) storage_comp_item); } -/*========================================== - * 初期化とか - *------------------------------------------ - */ -int do_init_storage(void) // map.c::do_init()から呼ばれる +void do_init_storage(void) { - storage_db = numdb_init(); - return 1; } -void do_final_storage(void) // by [MC Cameri] +void do_final_storage(void) { - if (storage_db) - numdb_final(storage_db, storage_db_final); + storage_db.clear(); } struct storage *account2storage(int account_id) { - struct storage *stor = - (struct storage *) numdb_search(storage_db, account_id); + struct storage *stor = storage_db.search(account_id); if (stor == NULL) { - CREATE(stor, struct storage, 1); + stor = storage_db.init(account_id); stor->account_id = account_id; - numdb_insert(storage_db, stor->account_id, stor); } return stor; } @@ -87,20 +71,13 @@ struct storage *account2storage(int account_id) // Just to ask storage, without creation struct storage *account2storage2(int account_id) { - return (struct storage *) numdb_search(storage_db, account_id); + return storage_db.search(account_id); } static -int storage_delete(int account_id) +void storage_delete(int account_id) { - struct storage *stor = - (struct storage *) numdb_search(storage_db, account_id); - if (stor) - { - numdb_erase(storage_db, account_id); - free(stor); - } - return 0; + storage_db.erase(account_id); } /*========================================== @@ -109,15 +86,13 @@ int storage_delete(int account_id) */ int storage_storageopen(struct map_session_data *sd) { - struct storage *stor; nullpo_ret(sd); if (sd->state.storage_open) return 1; //Already open? - if ((stor = - (struct storage *) numdb_search(storage_db, - sd->status.account_id)) == NULL) + struct storage *stor = storage_db.search(sd->status.account_id); + if (stor == NULL) { //Request storage. intif_request_storage(sd->status.account_id); return 1; -- cgit v1.2.3-60-g2f50