Skip to content

Commit

Permalink
Remove governments iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
psampathkumar authored and jwrober committed Jul 25, 2022
1 parent 1061dcd commit 2d534d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 59 deletions.
52 changes: 0 additions & 52 deletions common/government.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,58 +406,6 @@ const char *ruler_title_for_player(const struct player *pplayer, char *buf,
return buf;
}

/**************************************************************************
Government iterator.
**************************************************************************/
struct government_iter {
struct iterator vtable;
struct government *p, *end;
};
#define GOVERNMENT_ITER(p) ((struct government_iter *) (p))

/**
Implementation of iterator 'sizeof' function.
*/
size_t government_iter_sizeof() { return sizeof(struct government_iter); }

/**
Implementation of iterator 'next' function.
*/
static void government_iter_next(struct iterator *iter)
{
GOVERNMENT_ITER(iter)->p++;
}

/**
Implementation of iterator 'get' function.
*/
static void *government_iter_get(const struct iterator *iter)
{
return GOVERNMENT_ITER(iter)->p;
}

/**
Implementation of iterator 'valid' function.
*/
static bool government_iter_valid(const struct iterator *iter)
{
struct government_iter *it = GOVERNMENT_ITER(iter);
return it->p < it->end;
}

/**
Implementation of iterator 'init' function.
*/
struct iterator *government_iter_init(struct government_iter *it)
{
it->vtable.next = government_iter_next;
it->vtable.get = government_iter_get;
it->vtable.valid = government_iter_valid;
it->p = &governments[0];
it->end = &governments[0] + government_count();
return ITERATOR(it);
}

/**
Allocate resources associated with the given government.
*/
Expand Down
11 changes: 4 additions & 7 deletions common/government.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,12 @@ bool can_change_to_government(struct player *pplayer,
void governments_alloc(int num);
void governments_free();

struct government_iter;
size_t government_iter_sizeof();
struct iterator *government_iter_init(struct government_iter *it);

// Iterate over government types.
#define governments_iterate(NAME_pgov) \
generic_iterate(struct government_iter, struct government *, NAME_pgov, \
government_iter_sizeof, government_iter_init)
#define governments_iterate_end generic_iterate_end
for (auto &temp_gov : governments) { \
government *NAME_pgov = &temp_gov;

#define governments_iterate_end }

#define governments_re_active_iterate(_p) \
governments_iterate(_p) \
Expand Down

0 comments on commit 2d534d5

Please sign in to comment.