From d4beb67d0e0ffe245138c9d13bc8df174a0ff78c Mon Sep 17 00:00:00 2001 From: elvez Date: Tue, 11 Jul 2006 15:46:46 +0000 Subject: [PATCH] - Added the GET and SET commands to TextSimulation git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@752 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/text_simulation.cc | 74 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 5 deletions(-) diff --git a/src/text_simulation.cc b/src/text_simulation.cc index 41549ff..5c95724 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -286,7 +286,6 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments) } - void TextSimulation::on_help(const Tokens& arguments) { @@ -331,9 +330,11 @@ TextSimulation::on_help(const Tokens& arguments) p_stdout(_("\n-- Do you really want me to explain what HELP means? --" "\n ************** YOU ARE JOKING ME !!! ************\n\n")); else if(command == "GET") - p_stderr(_("\nFIXME: Not implemented")); + p_stdout(_("\n -- GET COMMAND --\nSyntax: GET \n where " + "may be simulation_tick")); else if(command == "SET") - p_stderr(_("\nFIXME: Not implemented")); + p_stdout(_("\n -- SET COMMAND --\nSyntax: SET [=] \n" + "where may be simulation_tick")); else if(command == "SHOW") p_stderr(_("\nFIXME: Not implemented")); else if(command == "ADD") @@ -360,13 +361,76 @@ TextSimulation::on_quit(const Tokens& arguments) void TextSimulation::on_get(const Tokens& arguments) { - p_stderr(_("\nFIXME: Not implemented\n")); + //make a local copy which we'll probably modify + Tokens args = arguments; + + ustring attr; + + if(args.size() == 0) + { + p_stderr("\nERROR: you must provide an argument\n"); + return; + } + else + { + attr = args[0].uppercase(); + args.erase(args.begin()); + } + + arguments_ignored(args); + + if(attr == "SIMULATION_TICK") + { + ostringstream oss; + oss << "\nsimulation_tick = " << get_timer() << "ms" << endl; + p_stdout(oss.str()); + } + else + p_stderr("\nERROR: invalid attribute. Accepted are: simulation_tick\n"); } void TextSimulation::on_set(const Tokens& arguments) { - p_stderr(_("\nFIXME: Not implemented\n")); + //make a local copy which we'll probably modify + Tokens args = arguments; + + ustring attr; + ustring value; + + if(args.size() < 2) + { + p_stderr("\nERROR: you must provide an attribute name and a value\n"); + return; + } + else + { + attr = args[0].uppercase(); + args.erase(args.begin()); + + if(args[0] == "=") + args.erase(args.begin()); + + value = args[0].uppercase(); + args.erase(args.begin()); + } + + arguments_ignored(args); + + if(attr == "SIMULATION_TICK") + { + try + { + set_timer(string_to(value)); + } + catch(domain_error e) + { + p_stderr("\nERROR: you must provide a valid integer value\n"); + } + + } + else + p_stderr("\nERROR: invalid attribute. Accepted are: simulation_tick\n"); } void