Skip to content

Commit

Permalink
Only refer to the --help switch on illegal arguments, don't print the…
Browse files Browse the repository at this point in the history
… help; enhanced comments.
  • Loading branch information
dnadlinger committed Feb 13, 2010
1 parent 61a2fa6 commit b48896c
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions src/d4/app/Application.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import d4.output.Surface;
*
* For example, a typical 3D application class might be derived from
* <code>FreeCamera!( Rendering!( Sdl!( Application ) ) )</code>.
*
* Pressing Escape closes the application.
*/
abstract class Application {
public:
Expand Down Expand Up @@ -201,6 +203,43 @@ protected:
}


/*
* Asynchronous keyboard handling.
*/

/**
* Handler function called when the user presses a key.
*
* You might probably want to overwrite this in subclasses to react to
* keyboard input. Be sure to always call the implementation from the parent
* class, regardless whether you handled the key or not.
*
* Params:
* key = The keycode of the pressed key.
*/
void handleKeyDown( Key key ) {
m_keyDownList[ key ] = true;
}

/**
* Handler function called when the user releases a key.
*
* You might probably want to overwrite this in subclasses to react to
* keyboard input. Be sure to always call the implementation from the parent
* class, regardless whether you handled the key or not.
*
* Params:
* key = The keycode of the released key.
*/
void handleKeyUp( Key key ) {
m_keyDownList[ key ] = false;

if ( key == Key.ESCAPE ) {
exit();
}
}


/*
* Argument handling
*/
Expand All @@ -224,8 +263,8 @@ protected:
m_appFinished = true;
break;
default:
printHelp();
throw new Exception( "Invalid argument: " ~ name );
throw new Exception( "Invalid argument: " ~ name ~ ". "
"Try " ~ m_args[ 0 ] ~ " --help." );
}
}

Expand All @@ -243,8 +282,10 @@ protected:
* value = The value of the argument (without the »=« sign).
*/
void handleValueArgument( char[] name, char[] value ) {
printHelp();
throw new Exception( "Invalid argument: " ~ name );
// If this point is reached, none of the subclasses has handeled the
// argument.
throw new Exception( "Invalid argument: " ~ name ~ ". "
"Try " ~ m_args[ 0 ] ~ " --help." );
}

/**
Expand All @@ -261,8 +302,9 @@ protected:
*/
void handleUnnamedArguments( char[][] values ) {
if ( values.length > 0 ) {
printHelp();
throw new Exception( "Too many arguments!" );
// There are arguments left which no subclass has handled.
throw new Exception( "Too many arguments. "
"Try " ~ m_args[ 0 ] ~ " --help." );
}
}

Expand Down Expand Up @@ -314,21 +356,6 @@ protected:
Stdout.newline;
}

/*
* Callback functions for the key tracking system.
*/
void handleKeyDown( Key key ) {
m_keyDownList[ key ] = true;
}

void handleKeyUp( Key key ) {
m_keyDownList[ key ] = false;

if ( key == Key.ESCAPE ) {
exit();
}
}

private:
void parseCommandLineArgs() {
char[][] unnamedArguments;
Expand Down

0 comments on commit b48896c

Please sign in to comment.