Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] (PR#9641) RfP: cities_iterate doesn't respect "break"
Home

[Freeciv-Dev] (PR#9641) RfP: cities_iterate doesn't respect "break"

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9641) RfP: cities_iterate doesn't respect "break"
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 10 Aug 2004 21:56:19 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9641 >

There are several possible solutions:

1.  Remove the macro, and make users hard-code it.  Currently there's
only one user, but there may be more in the future.  Surely someday
someone will ask "why doesn't this operation have a macro iterator" and
rewrite it.

2.  Leave it as it is, and document that break doesn't work.  Of course
someone will use break on it someday, and become confused and complain.

3.  Use some crazy code magic to determine whether "break" was called. 
For instance:

#define iterate
  players_iterate(pplayer) {
    int counted = 0;
    cities_iterate(pplayer->cities, pcity) {

#define iterate_end \
      counted++;
    } cities_iterate_end;
    if (counted != pplayer->cities.size) {
      /* Respect "break". */
      break;
    }
  } players_iterate_end;

...but this is ugly.

4.  Do a single-loop iteration over hash numbers (city id's).  But this
will be inefficient and bug-prone.

5.  Add in a new game.cities citylist.  This is actually quite easy
(only about 3 lines of code needed).

I think I favor #5.

jason



[Prev in Thread] Current Thread [Next in Thread]