Jerry Krinock wrote:
Does anyone have an idiom or way of appreciating this problem which
does not produce such spaghetti and headaches?
How about a state machine:
enum State { STATE_INIT, STATE_PREPARE, STATE_EXECUTE, STATE_FINISHED,
STATE_DEAD };
State state;
HandleEvent(event)
{
switch (state) {
case STATE_INIT:
// initialize here
state = STATE_PREPARE:
// fallthru
case STATE_PREPARE:
if (need_some_particular_state_first) { break; }
if (need_user_response) { ask_for_it(); break; }
state = STATE_EXECUTE;
// fallthru
case STATE_EXECUTE:
// do stuff
state = STATE_FINISHED; // so when display is dismissed we continue
display_results();
break;
case STATE_FINISHED:
// wrap up
state = STATE_DEAD;
// fallthru
case STATE_DEAD:
break;
default:
assert(0);
}
}
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com