Re: Modal Sheet without Spaghetti?
Re: Modal Sheet without Spaghetti?
- Subject: Re: Modal Sheet without Spaghetti?
- From: Jan Brittenson <email@hidden>
- Date: Wed, 28 Jan 2009 14:19:08 -0800
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 (email@hidden)
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:
This email sent to email@hidden