Changeset 1427 for code/branches/console
- Timestamp:
- May 26, 2008, 3:08:39 AM (17 years ago)
- Location:
- code/branches/console/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/CommandEvaluation.cc
r1424 r1427 57 57 this->functionclass_ = 0; 58 58 this->function_ = 0; 59 this->possibleArgument_ = ""; 60 this->argument_ = ""; 59 61 60 62 this->errorMessage_ = ""; … … 97 99 if (!this->bNewCommand_) 98 100 { 99 std::cout << " ASDF" << std::endl;101 std::cout << "not new" << std::endl; 100 102 switch (this->state_) 101 103 { … … 106 108 case CS_ShortcutOrIdentifier: 107 109 if (this->function_) 108 return CommandExecutor::complete(this->function_->getName() + " "); 110 { 111 if (this->function_->getParamCount() == 0) 112 return /*CommandExecutor::complete*/(this->command_ = this->function_->getName()); 113 else 114 return /*CommandExecutor::complete*/(this->command_ = this->function_->getName() + " "); 115 } 109 116 else if (this->functionclass_) 110 return CommandExecutor::complete(this->functionclass_->getName() + " ");117 return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " "); 111 118 break; 112 119 case CS_Function: 113 120 if (this->function_) 114 return CommandExecutor::complete(this->functionclass_->getName() + " " + this->function_->getName() + " "); 115 break; 121 { 122 if (this->function_->getParamCount() == 0) 123 return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " " + this->function_->getName()); 124 else 125 return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " " + this->function_->getName() + " "); 126 } 127 break; 128 case CS_ParamPreparation: 116 129 case CS_Params: 117 break; 130 { 131 unsigned int maxIndex = this->commandTokens_.size(); 132 if (this->command_[this->command_.size() - 1] != ' ') 133 maxIndex -= 1; 134 std::string whitespace = ""; 135 if (this->function_->getParamCount() > (maxIndex + 1 - this->getStartindex())) 136 whitespace = " "; 137 138 if (this->possibleArgument_ != "") 139 { 140 maxIndex -= 1; 141 this->argument_ = this->possibleArgument_; 142 } 143 144 return /*CommandExecutor::complete*/(this->command_ = this->commandTokens_.subSet(0, maxIndex).join() + " " + this->argument_ + whitespace); 145 break; 146 } 118 147 case CS_Finished: 119 148 break; … … 144 173 return CommandEvaluation::dump(this->listOfPossibleFunctions_); 145 174 break; 175 case CS_ParamPreparation: 146 176 case CS_Params: 147 177 if (this->listOfPossibleArguments_.size() > 0) … … 241 271 std::string CommandEvaluation::dump(const ConsoleCommand* command) 242 272 { 243 std::string output = command->getName() + ": "; 273 std::string output = command->getName(); 274 if (command->getParamCount() > 0) 275 output += ": "; 276 244 277 for (unsigned int i = 0; i < command->getParamCount(); i++) 245 278 { -
code/branches/console/src/core/CommandEvaluation.h
r1424 r1427 46 46 CS_ShortcutOrIdentifier, 47 47 CS_Function, 48 CS_ParamPreparation, 48 49 CS_Params, 49 50 CS_Finished, … … 98 99 Identifier* functionclass_; 99 100 ConsoleCommand* function_; 101 std::string possibleArgument_; 102 std::string argument_; 100 103 101 104 std::string errorMessage_; -
code/branches/console/src/core/CommandExecutor.cc
r1424 r1427 146 146 void CommandExecutor::parse(const std::string& command, bool bInitialize) 147 147 { 148 std::cout << "parse : command: >" << command << "<" << std::endl;148 std::cout << "parse (" << bInitialize << "): command: >" << command << "<" << std::endl; 149 149 if (bInitialize) 150 150 CommandExecutor::getEvaluation().initialize(command); … … 185 185 { 186 186 // It's a shortcut 187 CommandExecutor::getEvaluation().state_ = CS_Param s;187 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 188 188 CommandExecutor::getEvaluation().functionclass_ = 0; 189 189 // Move on to next case … … 224 224 CommandExecutor::getEvaluation().bCommandChanged_ = true; 225 225 } 226 CommandExecutor::getEvaluation().state_ = CS_Param s;226 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 227 227 CommandExecutor::getEvaluation().functionclass_ = 0; 228 228 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().function_->getName(); 229 229 if (CommandExecutor::getEvaluation().function_->getParamCount() > 0) 230 { 230 231 CommandExecutor::getEvaluation().command_ += " "; 232 CommandExecutor::getEvaluation().bCommandChanged_ = true; 233 } 231 234 // Move on to next case 232 235 } … … 263 266 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0)); 264 267 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0)); 268 CommandExecutor::getEvaluation().bCommandChanged_ = true; 265 269 return; 266 270 } … … 280 284 { 281 285 // It's a function 282 CommandExecutor::getEvaluation().state_ = CS_Param s;286 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 283 287 // Move on to next case 284 288 } … … 308 312 CommandExecutor::getEvaluation().bCommandChanged_ = true; 309 313 } 310 CommandExecutor::getEvaluation().state_ = CS_Param s;314 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 311 315 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getEvaluation().function_->getName(); 312 316 if (CommandExecutor::getEvaluation().function_->getParamCount() > 0) 317 { 313 318 CommandExecutor::getEvaluation().command_ += " "; 319 CommandExecutor::getEvaluation().bCommandChanged_ = true; 320 } 314 321 // Move on to next case 315 322 } … … 327 334 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleFunctions_); 328 335 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 336 CommandExecutor::getEvaluation().bCommandChanged_ = true; 329 337 return; 330 338 } … … 333 341 else 334 342 { 335 // There is no classname - move on to CS_Shortcut_Params 336 } 337 } 338 std::cout << "Waiting for arguments" << std::endl; 343 // There is no classname - move on to CS_ParamPreparation 344 } 345 } 346 std::cout << "1\n"; 347 case CS_ParamPreparation: 348 std::cout << "2\n"; 349 { 350 if (CommandExecutor::getEvaluation().function_->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_)) 351 { 352 CommandExecutor::getEvaluation().state_ = CS_Finished; 353 return; 354 } 355 else 356 { 357 unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1; 358 if (CommandExecutor::getEvaluation().functionclass_) 359 argumentNumber -= 1; 360 361 CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 362 CommandExecutor::getEvaluation().state_ = CS_Params; 363 364 if (CommandExecutor::getEvaluation().bCommandChanged_) 365 { 366 // Don't do more than one change 367 return; 368 } 369 } 370 } 339 371 case CS_Params: 340 { 372 std::cout << "3\n"; 373 { 374 if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 1) 375 { 376 std::cout << "3_1\n"; 377 // There is exactly one possible argument 378 CommandExecutor::getEvaluation().argument_ = *(*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second; 379 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 380 return; 381 } 382 else if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 0) 383 { 384 std::cout << "3_2\n"; 385 // The user tries something new - we let him do 386 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 387 CommandExecutor::getEvaluation().argument_ = CommandExecutor::getLastArgument(); 388 return; 389 } 390 else 391 { 392 std::cout << "3_3\n"; 393 // There are several possibilities 394 unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1; 395 if (CommandExecutor::getEvaluation().functionclass_) 396 argumentNumber -= 1; 397 398 CommandExecutor::getEvaluation().argument_ = CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleArguments_); 399 CommandExecutor::getEvaluation().possibleArgument_ = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 400 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 401 return; 402 } 341 403 } 342 404 case CS_Finished: 405 std::cout << "4\n"; 343 406 { 344 407 // Nothing more to do … … 373 436 { 374 437 if (CommandExecutor::getEvaluation().functionclass_) 375 return (CommandExecutor:: getEvaluation().commandTokens_.size() >=(2 + command->getParamCount()));376 else 377 return (CommandExecutor:: getEvaluation().commandTokens_.size() >=(1 + command->getParamCount()));438 return (CommandExecutor::argumentsGiven() > (2 + command->getParamCount())); 439 else 440 return (CommandExecutor::argumentsGiven() > (1 + command->getParamCount())); 378 441 } 379 442 … … 388 451 std::string CommandExecutor::getLastArgument() 389 452 { 390 return CommandExecutor::getArgument(CommandExecutor::argumentsGiven() );453 return CommandExecutor::getArgument(CommandExecutor::argumentsGiven() - 1); 391 454 } 392 455 … … 462 525 } 463 526 464 const std::string*CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param)527 std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param) 465 528 { 466 529 std::string lowercase = getLowercase(name); 467 530 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it) 468 531 if ((*it).first == lowercase) 469 return &(*it).second;532 return (*it).second; 470 533 471 534 return 0; -
code/branches/console/src/core/CommandExecutor.h
r1424 r1427 91 91 static Identifier* getPossibleIdentifier(const std::string& name); 92 92 static ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0); 93 static const std::string*getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);93 static std::string getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param); 94 94 95 95 static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list); -
code/branches/console/src/orxonox/objects/SpaceShip.cc
r1341 r1427 54 54 { 55 55 SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug); 56 SetConsoleCommandGeneric(test1, SpaceShip, create Executor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug);57 SetConsoleCommandGeneric(test2, SpaceShip, create Executor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug);58 SetConsoleCommandGeneric(test3, SpaceShip, create Executor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug);56 SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug); 57 SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug); 58 SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug); 59 59 60 60 CreateFactory(SpaceShip);
Note: See TracChangeset
for help on using the changeset viewer.