Skip to content

Commit

Permalink
Dropped typedef from DBIterator
Browse files Browse the repository at this point in the history
Signed-off-by: Haru <haru@dotalux.com>
  • Loading branch information
MishimaHaruna committed Mar 20, 2016
1 parent 13dcf1e commit 9975335
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 133 deletions.
4 changes: 2 additions & 2 deletions src/char/int_auction.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int inter_auction_count(int char_id, bool buy)
{
int i = 0;
struct auction_data *auction;
DBIterator *iter = db_iterator(inter_auction->db);
struct DBIterator *iter = db_iterator(inter_auction->db);

for( auction = dbi_first(iter); dbi_exists(iter); auction = dbi_next(iter) )
{
Expand Down Expand Up @@ -280,7 +280,7 @@ void mapif_parse_auction_requestlist(int fd)
int price = RFIFOL(fd,10);
short type = RFIFOW(fd,8), page = max(1,RFIFOW(fd,14));
unsigned char buf[5 * sizeof(struct auction_data)];
DBIterator *iter = db_iterator(inter_auction->db);
struct DBIterator *iter = db_iterator(inter_auction->db);
struct auction_data *auction;
short i = 0, j = 0, pages = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/char/int_guild.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static const char dataToHex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9
int inter_guild_save_timer(int tid, int64 tick, int id, intptr_t data) {
static int last_id = 0; //To know in which guild we were.
int state = 0; //0: Have not reached last guild. 1: Reached last guild, ready for save. 2: Some guild saved, don't do further saving.
DBIterator *iter = db_iterator(inter_guild->guild_db);
struct DBIterator *iter = db_iterator(inter_guild->guild_db);
union DBKey key;
struct guild* g;

Expand Down
56 changes: 29 additions & 27 deletions src/common/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,17 @@ typedef struct DBMap_impl {
* @param ht_index Current index of the hashtable
* @param node Current node
* @private
* @see #DBIterator
* @see struct DBIterator
* @see #DBMap_impl
* @see #DBNode
*/
typedef struct DBIterator_impl {
struct DBIterator_impl {
// Iterator interface
struct DBIterator vtable;
DBMap_impl* db;
int ht_index;
DBNode *node;
} DBIterator_impl;
};

#if defined(DB_ENABLE_STATS)
/**
Expand Down Expand Up @@ -1245,11 +1245,11 @@ static void db_release_both(union DBKey key, struct DBData data, enum DBReleaseO
* @param out_key Key of the entry
* @return Data of the entry
* @protected
* @see DBIterator#first
* @see struct DBIterator#first()
*/
struct DBData *dbit_obj_first(DBIterator* self, union DBKey *out_key)
struct DBData *dbit_obj_first(struct DBIterator *self, union DBKey *out_key)
{
DBIterator_impl* it = (DBIterator_impl*)self;
struct DBIterator_impl *it = (struct DBIterator_impl *)self;

DB_COUNTSTAT(dbit_first);
// position before the first entry
Expand All @@ -1267,11 +1267,11 @@ struct DBData *dbit_obj_first(DBIterator* self, union DBKey *out_key)
* @param out_key Key of the entry
* @return Data of the entry
* @protected
* @see DBIterator#last
* @see struct DBIterator#last()
*/
struct DBData *dbit_obj_last(DBIterator* self, union DBKey *out_key)
struct DBData *dbit_obj_last(struct DBIterator *self, union DBKey *out_key)
{
DBIterator_impl* it = (DBIterator_impl*)self;
struct DBIterator_impl *it = (struct DBIterator_impl *)self;

DB_COUNTSTAT(dbit_last);
// position after the last entry
Expand All @@ -1289,11 +1289,11 @@ struct DBData *dbit_obj_last(DBIterator* self, union DBKey *out_key)
* @param out_key Key of the entry
* @return Data of the entry
* @protected
* @see DBIterator#next
* @see struct DBIterator#next()
*/
struct DBData *dbit_obj_next(DBIterator* self, union DBKey *out_key)
struct DBData *dbit_obj_next(struct DBIterator *self, union DBKey *out_key)
{
DBIterator_impl* it = (DBIterator_impl*)self;
struct DBIterator_impl *it = (struct DBIterator_impl *)self;
DBNode *node;
DBNode *parent;
struct dbn fake;
Expand Down Expand Up @@ -1365,11 +1365,11 @@ struct DBData *dbit_obj_next(DBIterator* self, union DBKey *out_key)
* @param out_key Key of the entry
* @return Data of the entry
* @protected
* @see DBIterator#prev
* @see struct DBIterator#prev()
*/
struct DBData *dbit_obj_prev(DBIterator* self, union DBKey *out_key)
struct DBData *dbit_obj_prev(struct DBIterator *self, union DBKey *out_key)
{
DBIterator_impl* it = (DBIterator_impl*)self;
struct DBIterator_impl *it = (struct DBIterator_impl *)self;
DBNode *node;
DBNode *parent;
struct dbn fake;
Expand Down Expand Up @@ -1440,31 +1440,33 @@ struct DBData *dbit_obj_prev(DBIterator* self, union DBKey *out_key)
* @param self Iterator
* @return true if the entry exists
* @protected
* @see DBIterator#exists
* @see struct DBIterator#exists()
*/
bool dbit_obj_exists(DBIterator* self)
bool dbit_obj_exists(struct DBIterator *self)
{
DBIterator_impl* it = (DBIterator_impl*)self;
struct DBIterator_impl *it = (struct DBIterator_impl *)self;

DB_COUNTSTAT(dbit_exists);
return (it->node && !it->node->deleted);
}

/**
* Removes the current entry from the database.
* NOTE: {@link DBIterator#exists} will return false until another entry
* is fetched
*
* NOTE: struct DBIterator#exists() will return false until another entry is
* fetched.
*
* Puts data of the removed entry in out_data, if out_data is not NULL (unless data has been released)
* @param self Iterator
* @param out_data Data of the removed entry.
* @return 1 if entry was removed, 0 otherwise
* @protected
* @see DBMap#remove
* @see DBIterator#remove
* @see struct DBIterator#remove()
*/
int dbit_obj_remove(DBIterator* self, struct DBData *out_data)
int dbit_obj_remove(struct DBIterator *self, struct DBData *out_data)
{
DBIterator_impl* it = (DBIterator_impl*)self;
struct DBIterator_impl *it = (struct DBIterator_impl *)self;
DBNode *node;
int retval = 0;

Expand All @@ -1489,9 +1491,9 @@ int dbit_obj_remove(DBIterator* self, struct DBData *out_data)
* @param self Iterator
* @protected
*/
void dbit_obj_destroy(DBIterator* self)
void dbit_obj_destroy(struct DBIterator *self)
{
DBIterator_impl* it = (DBIterator_impl*)self;
struct DBIterator_impl *it = (struct DBIterator_impl *)self;

DB_COUNTSTAT(dbit_destroy);
// unlock the database
Expand All @@ -1509,10 +1511,10 @@ void dbit_obj_destroy(DBIterator* self)
* @return New iterator
* @protected
*/
static DBIterator* db_obj_iterator(DBMap* self)
static struct DBIterator *db_obj_iterator(DBMap* self)
{
DBMap_impl* db = (DBMap_impl*)self;
DBIterator_impl* it;
struct DBIterator_impl *it;

DB_COUNTSTAT(db_iterator);
it = ers_alloc(db_iterator_ers, struct DBIterator_impl);
Expand Down
36 changes: 19 additions & 17 deletions src/common/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
* DBComparator - Format of the comparators used by the databases. *
* DBHasher - Format of the hashers used by the databases. *
* DBReleaser - Format of the releasers used by the databases. *
* DBIterator - Database iterator. *
* struct DBIterator - Database iterator. *
* DBMap - Database interface. *
\*****************************************************************************/
*****************************************************************************/

/**
* Bitfield with what should be released by the releaser function (if the
Expand Down Expand Up @@ -288,21 +288,21 @@ typedef uint64 (*DBHasher)(union DBKey key, unsigned short maxlen);
*/
typedef void (*DBReleaser)(union DBKey key, struct DBData data, enum DBReleaseOption which);

typedef struct DBIterator DBIterator;
typedef struct DBMap DBMap;

/**
* Database iterator.
*
* Supports forward iteration, backward iteration and removing entries from the database.
* The iterator is initially positioned before the first entry of the database.
*
* While the iterator exists the database is locked internally, so invoke
* {@link DBIterator#destroy} as soon as possible.
* struct DBIterator#destroy() as soon as possible.
*
* @public
* @see #DBMap
*/
struct DBIterator
{

struct DBIterator {
/**
* Fetches the first entry in the database.
* Returns the data of the entry.
Expand All @@ -312,7 +312,7 @@ struct DBIterator
* @return Data of the entry
* @protected
*/
struct DBData *(*first)(DBIterator* self, union DBKey *out_key);
struct DBData *(*first)(struct DBIterator *self, union DBKey *out_key);

/**
* Fetches the last entry in the database.
Expand All @@ -323,7 +323,7 @@ struct DBIterator
* @return Data of the entry
* @protected
*/
struct DBData *(*last)(DBIterator* self, union DBKey *out_key);
struct DBData *(*last)(struct DBIterator *self, union DBKey *out_key);

/**
* Fetches the next entry in the database.
Expand All @@ -334,7 +334,7 @@ struct DBIterator
* @return Data of the entry
* @protected
*/
struct DBData *(*next)(DBIterator* self, union DBKey *out_key);
struct DBData *(*next)(struct DBIterator *self, union DBKey *out_key);

/**
* Fetches the previous entry in the database.
Expand All @@ -345,7 +345,7 @@ struct DBIterator
* @return Data of the entry
* @protected
*/
struct DBData *(*prev)(DBIterator* self, union DBKey *out_key);
struct DBData *(*prev)(struct DBIterator *self, union DBKey *out_key);

/**
* Returns true if the fetched entry exists.
Expand All @@ -355,27 +355,29 @@ struct DBIterator
* @return true is the entry exists
* @protected
*/
bool (*exists)(DBIterator* self);
bool (*exists)(struct DBIterator *self);

/**
* Removes the current entry from the database.
* NOTE: {@link DBIterator#exists} will return false until another entry
* is fetched
*
* NOTE: struct DBIterator#exists() will return false until another
* entry is fetched.
*
* Puts data of the removed entry in out_data, if out_data is not NULL.
* @param self Iterator
* @param out_data Data of the removed entry.
* @return 1 if entry was removed, 0 otherwise
* @protected
* @see DBMap#remove
*/
int (*remove)(DBIterator* self, struct DBData *out_data);
int (*remove)(struct DBIterator *self, struct DBData *out_data);

/**
* Destroys this iterator and unlocks the database.
* @param self Iterator
* @protected
*/
void (*destroy)(DBIterator* self);
void (*destroy)(struct DBIterator *self);

};

Expand All @@ -396,7 +398,7 @@ struct DBMap {
* @return New iterator
* @protected
*/
DBIterator* (*iterator)(DBMap* self);
struct DBIterator *(*iterator)(DBMap* self);

/**
* Returns true if the entry exists.
Expand Down
2 changes: 1 addition & 1 deletion src/common/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ static int connect_check_clear(int tid, int64 tick, int id, intptr_t data) {
int clear = 0;
int list = 0;
ConnectHistory *hist = NULL;
DBIterator *iter;
struct DBIterator *iter;

if( !db_size(connect_history) )
return 0;
Expand Down
18 changes: 9 additions & 9 deletions src/map/atcommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ ACMD(help) {
clif->message(fd, atcmd_output);

{ // Display aliases
DBIterator* iter;
struct DBIterator *iter;
AtCommandInfo *command_info;
AliasInfo *alias_info = NULL;
StringBuf buf;
Expand Down Expand Up @@ -5278,10 +5278,11 @@ ACMD(clearcart)
*------------------------------------------*/
#define MAX_SKILLID_PARTIAL_RESULTS 5
#define MAX_SKILLID_PARTIAL_RESULTS_LEN 74 /* "skill " (6) + "%d:" (up to 5) + "%s" (up to 30) + " (%s)" (up to 33) */
ACMD(skillid) {
ACMD(skillid)
{
int i, found = 0;
size_t skillen;
DBIterator* iter;
struct DBIterator *iter;
union DBKey key;
struct DBData *data;
char partials[MAX_SKILLID_PARTIAL_RESULTS][MAX_SKILLID_PARTIAL_RESULTS_LEN];
Expand Down Expand Up @@ -8352,7 +8353,7 @@ void atcommand_commands_sub(struct map_session_data* sd, const int fd, AtCommand
char line_buff[CHATBOX_SIZE];
char* cur = line_buff;
AtCommandInfo* cmd;
DBIterator *iter = db_iterator(atcommand->db);
struct DBIterator *iter = db_iterator(atcommand->db);
int count = 0;

memset(line_buff,' ',CHATBOX_SIZE);
Expand Down Expand Up @@ -8826,7 +8827,7 @@ ACMD(channel) {
clif->messagecolor_self(fd, channel->config->colors[k], atcmd_output);
}
} else {
DBIterator *iter = db_iterator(channel->db);
struct DBIterator *iter = db_iterator(channel->db);
bool show_all = pc_has_permission(sd, PC_PERM_HCHSYS_ADMIN) ? true : false;
clif->message(fd, msg_fd(fd,1410)); // -- Public Channels
if (channel->config->local) {
Expand Down Expand Up @@ -9056,7 +9057,7 @@ ACMD(channel) {
clif->message(fd, atcmd_output);
} else if (strcmpi(subcmd,"banlist") == 0) {
// sub1 = channel name; sub2 = unused; sub3 = unused
DBIterator *iter = NULL;
struct DBIterator *iter = NULL;
union DBKey key;
struct DBData *data;
bool isA = pc_has_permission(sd, PC_PERM_HCHSYS_ADMIN)?true:false;
Expand Down Expand Up @@ -9733,8 +9734,7 @@ const char* atcommand_checkalias(const char *aliasname) {

/// AtCommand suggestion
void atcommand_get_suggestions(struct map_session_data* sd, const char *name, bool is_atcmd_cmd) {
DBIterator* atcommand_iter;
DBIterator* alias_iter;
struct DBIterator *atcommand_iter, *alias_iter;
AtCommandInfo* command_info = NULL;
AliasInfo* alias_info = NULL;
AtCommandType type = is_atcmd_cmd ? COMMAND_ATCOMMAND : COMMAND_CHARCOMMAND;
Expand Down Expand Up @@ -10120,7 +10120,7 @@ static inline int atcommand_command_type2idx(AtCommandType type)
*/
void atcommand_db_load_groups(GroupSettings **groups, struct config_setting_t **commands_, size_t sz)
{
DBIterator *iter = db_iterator(atcommand->db);
struct DBIterator *iter = db_iterator(atcommand->db);
AtCommandInfo *atcmd;

nullpo_retv(groups);
Expand Down
5 changes: 2 additions & 3 deletions src/map/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ void channel_delete(struct channel_data *chan)
nullpo_retv(chan);

if (db_size(chan->users) && !channel->config->closing) {
DBIterator *iter;
struct map_session_data *sd;
iter = db_iterator(chan->users);
struct DBIterator *iter = db_iterator(chan->users);
for (sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) {
channel->leave_sub(chan, sd);
}
Expand Down Expand Up @@ -814,7 +813,7 @@ int do_init_channel(bool minimal)

void do_final_channel(void)
{
DBIterator *iter = db_iterator(channel->db);
struct DBIterator *iter = db_iterator(channel->db);
struct channel_data *chan;
unsigned char i;

Expand Down
Loading

0 comments on commit 9975335

Please sign in to comment.