M
Magius96
I'm writing a command parser for an application that I'm developing. I've
got everything up and working right now, but I'm currently using a switch
statement to determine what command was entered by the user.
I want to get away from using a switch statement for valid reasons. First,
I want to be able to readily return a list of all commands available to the
user when they type 'comm' into the command parser. Secondly, using a select
statement to determine what command was entered by the user will eventually
become very unwieldly to update and maintain.
I can't provide source code because the development machine isn't permitted
access to any networks for security reasons, but here's a generalized
explanation of how it's currently working.
The user is faced with a command prompt from within the application(it's
fully command driven). The user enteres a command and any arguments and
presses ENTER. The entire line entered by the user is split into two strings
(Command, ARGS). The Command string contains only the first word (all
characters until the first space). The ARGS string contains all the rest of
the users entry minus what's stored in Command and the space. All other
spaces are left in tact.
Currently, we're using "Switch (Command.ToLower())" to determine what
command the user entered. Like I said, this works fine, but it's going to
become unwieldly.
Every command will have it's own function in another class that should be
called by the command parser. For simplification, every function called by
the command parser has the exact same argument list (Connection ch, UserList
Users, string ARGS).
What I'd like, is to have some sort of table somewhere where every command
can be entered in this type of format
{ (string)CommandName, (pointer)FunctionName }
And some central core function that will pass through the table comparing
the value in Command to the CommandName in the table, then when a match is
found call FunctionName.
If you can help me find the best possible solution, I'd greatly appreciate
it. I'm not just looking for simplicity in updating, but I don't want to
make any major hits to performance as a result either. As you can probably
tell, this is a network application in which we expect to have thousands of
users at once, so increasing performance is a top priority for this project,
just second to making it work.
got everything up and working right now, but I'm currently using a switch
statement to determine what command was entered by the user.
I want to get away from using a switch statement for valid reasons. First,
I want to be able to readily return a list of all commands available to the
user when they type 'comm' into the command parser. Secondly, using a select
statement to determine what command was entered by the user will eventually
become very unwieldly to update and maintain.
I can't provide source code because the development machine isn't permitted
access to any networks for security reasons, but here's a generalized
explanation of how it's currently working.
The user is faced with a command prompt from within the application(it's
fully command driven). The user enteres a command and any arguments and
presses ENTER. The entire line entered by the user is split into two strings
(Command, ARGS). The Command string contains only the first word (all
characters until the first space). The ARGS string contains all the rest of
the users entry minus what's stored in Command and the space. All other
spaces are left in tact.
Currently, we're using "Switch (Command.ToLower())" to determine what
command the user entered. Like I said, this works fine, but it's going to
become unwieldly.
Every command will have it's own function in another class that should be
called by the command parser. For simplification, every function called by
the command parser has the exact same argument list (Connection ch, UserList
Users, string ARGS).
What I'd like, is to have some sort of table somewhere where every command
can be entered in this type of format
{ (string)CommandName, (pointer)FunctionName }
And some central core function that will pass through the table comparing
the value in Command to the CommandName in the table, then when a match is
found call FunctionName.
If you can help me find the best possible solution, I'd greatly appreciate
it. I'm not just looking for simplicity in updating, but I don't want to
make any major hits to performance as a result either. As you can probably
tell, this is a network application in which we expect to have thousands of
users at once, so increasing performance is a top priority for this project,
just second to making it work.