Changeset 7221 for code/branches/consolecommands3/src/libraries/core
- Timestamp:
- Aug 26, 2010, 2:06:16 AM (14 years ago)
- Location:
- code/branches/consolecommands3/src/libraries/core/command
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc
r7203 r7221 67 67 } 68 68 69 bool CommandEvaluation::isValid() const70 {71 return (this->function_);72 }73 74 69 bool CommandEvaluation::execute() const 75 70 { … … 84 79 *success = false; 85 80 86 if (!this-> isValid())81 if (!this->function_ || !this->function_->isActive()) 87 82 return MT_Type::Null; 88 83 … … 92 87 *success = true; 93 88 COUT(6) << "CE_execute (evaluation): " << this->function_->getName() << ' ' << this->param_[0] << ' ' << this->param_[1] << ' ' << this->param_[2] << ' ' << this->param_[3] << ' ' << this->param_[4] << std::endl; 94 return (*this->function_ )(this->param_[0], this->param_[1], this->param_[2], this->param_[3], this->param_[4]);89 return (*this->function_->getExecutor())(this->param_[0], this->param_[1], this->param_[2], this->param_[3], this->param_[4]); 95 90 } 96 91 … … 101 96 unsigned int startindex = this->getStartindex(); 102 97 if (this->commandTokens_.size() > startindex) 103 return this->function_-> parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()), success);98 return this->function_->getExecutor()->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()), success); 104 99 else 105 return this->function_-> parse(removeSlashes(this->additionalParameter_), success);100 return this->function_->getExecutor()->parse(removeSlashes(this->additionalParameter_), success); 106 101 } 107 102 … … 122 117 if (this->function_) 123 118 { 124 if (this->function_->get ParamCount() == 0)119 if (this->function_->getExecutor()->getParamCount() == 0) 125 120 return (this->command_ = this->function_->getName()); 126 121 else … … 133 128 if (this->function_) 134 129 { 135 if (this->function_->get ParamCount() == 0)130 if (this->function_->getExecutor()->getParamCount() == 0) 136 131 return (this->command_ = this->functionclass_->getName() + ' ' + this->function_->getName()); 137 132 else … … 153 148 { 154 149 this->argument_ = this->possibleArgument_; 155 if (this->function_->get ParamCount() > (maxIndex + 1 - this->getStartindex()))150 if (this->function_->getExecutor()->getParamCount() > (maxIndex + 1 - this->getStartindex())) 156 151 whitespace = " "; 157 152 } … … 213 208 this->param_[i] = MT_Type::Null; 214 209 215 if (!this-> isValid())210 if (!this->function_) 216 211 return; 217 212 … … 220 215 if (this->commandTokens_.size() <= startindex) 221 216 { 222 if (this->function_-> evaluate(this->getAdditionalParameter(), this->param_, " "))217 if (this->function_->getBaseExecutor()->evaluate(this->getAdditionalParameter(), this->param_, " ")) 223 218 this->bEvaluatedParams_ = true; 224 219 } 225 220 else if (this->commandTokens_.size() > startindex) 226 221 { 227 if (this->function_-> evaluate(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter(), this->param_, " "))222 if (this->function_->getBaseExecutor()->evaluate(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter(), this->param_, " ")) 228 223 this->bEvaluatedParams_ = true; 229 224 } … … 280 275 } 281 276 282 std::string CommandEvaluation::dump(const ConsoleCommand* command)277 std::string CommandEvaluation::dump(const _ConsoleCommand* command) 283 278 { 284 279 std::string output = command->getName(); 285 if (command->get ParamCount() > 0)280 if (command->getExecutor()->getParamCount() > 0) 286 281 output += ": "; 287 282 288 for (unsigned int i = 0; i < command->get ParamCount(); i++)283 for (unsigned int i = 0; i < command->getExecutor()->getParamCount(); i++) 289 284 { 290 285 if (i != 0) 291 286 output += ' '; 292 287 293 if (command-> defaultValueSet(i))288 if (command->getExecutor()->defaultValueSet(i)) 294 289 output += '['; 295 290 else 296 291 output += '{'; 297 292 298 output += command->get TypenameParam(i);299 300 if (command-> defaultValueSet(i))301 output += '=' + command->get DefaultValue(i).getString() + ']';293 output += command->getExecutor()->getTypenameParam(i); 294 295 if (command->getExecutor()->defaultValueSet(i)) 296 output += '=' + command->getExecutor()->getDefaultValue(i).getString() + ']'; 302 297 else 303 298 output += '}'; -
code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h
r7203 r7221 72 72 void evaluateParams(); 73 73 74 bool isValid() const; 74 bool isValid() const 75 { return this->function_; } 75 76 76 inline ConsoleCommand* getConsoleCommand() const77 inline _ConsoleCommand* getConsoleCommand() const 77 78 { return this->function_; } 78 79 inline const std::string& getOriginalCommand() const … … 93 94 static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list); 94 95 static std::string dump(const ArgumentCompletionList& list); 95 static std::string dump(const ConsoleCommand* command);96 static std::string dump(const _ConsoleCommand* command); 96 97 97 98 … … 109 110 110 111 Identifier* functionclass_; 111 ConsoleCommand* function_;112 _ConsoleCommand* function_; 112 113 std::string possibleArgument_; 113 114 std::string argument_; -
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.cc
r7216 r7221 49 49 } 50 50 51 const CommandEvaluation& CommandExecutor::getLastEvaluation()52 {53 return CommandExecutor::getInstance().evaluation_;54 }55 56 51 bool CommandExecutor::execute(const std::string& command, bool useTcl) 57 52 { … … 216 211 CommandExecutor::getEvaluation().functionclass_ = 0; 217 212 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().function_->getName(); 218 if (CommandExecutor::getEvaluation().function_->get ParamCount() > 0)213 if (CommandExecutor::getEvaluation().function_->getExecutor()->getParamCount() > 0) 219 214 { 220 215 CommandExecutor::getEvaluation().command_ += ' '; … … 303 298 CommandExecutor::getEvaluation().state_ = CommandState::ParamPreparation; 304 299 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + ' ' + CommandExecutor::getEvaluation().function_->getName(); 305 if (CommandExecutor::getEvaluation().function_->get ParamCount() > 0)300 if (CommandExecutor::getEvaluation().function_->getExecutor()->getParamCount() > 0) 306 301 { 307 302 CommandExecutor::getEvaluation().command_ += ' '; … … 335 330 case CommandState::ParamPreparation: 336 331 { 337 if (CommandExecutor::getEvaluation().function_->get ParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_))332 if (CommandExecutor::getEvaluation().function_->getExecutor()->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_)) 338 333 { 339 334 CommandExecutor::getEvaluation().state_ = CommandState::Finished; … … 418 413 } 419 414 420 bool CommandExecutor::enoughArgumentsGiven( ConsoleCommand* command)415 bool CommandExecutor::enoughArgumentsGiven(_ConsoleCommand* command) 421 416 { 422 417 if (CommandExecutor::getEvaluation().functionclass_) 423 return (CommandExecutor::argumentsGiven() > (2 + command->get ParamCount()));424 else 425 return (CommandExecutor::argumentsGiven() > (1 + command->get ParamCount()));418 return (CommandExecutor::argumentsGiven() > (2 + command->getExecutor()->getParamCount())); 419 else 420 return (CommandExecutor::argumentsGiven() > (1 + command->getExecutor()->getParamCount())); 426 421 } 427 422 … … 441 436 void CommandExecutor::createListOfPossibleIdentifiers(const std::string& fragment) 442 437 { 438 /* 443 439 CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.clear(); 444 440 const std::string& lowercase = getLowercase(fragment); … … 447 443 if (it->first.find(lowercase) == 0 || fragment.empty()) 448 444 CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.push_back(std::pair<const std::string*, const std::string*>(&it->first, &it->second->getName())); 445 */ 449 446 } 450 447 451 448 void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier) 452 449 { 450 /* 453 451 CommandExecutor::getEvaluation().listOfPossibleFunctions_.clear(); 454 452 const std::string& lowercase = getLowercase(fragment); 455 453 if (!identifier) 456 454 { 457 for (std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)455 for (std::map<std::string, _ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it) 458 456 if (it->first.find(lowercase) == 0 || fragment.empty()) 459 457 CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&it->first, &it->second->getName())); … … 461 459 else 462 460 { 463 for (std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)461 for (std::map<std::string, _ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it) 464 462 if (it->first.find(lowercase) == 0 || fragment.empty()) 465 463 CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&it->first, &it->second->getName())); 466 464 } 467 } 468 469 void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param) 470 { 465 */ 466 } 467 468 void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, _ConsoleCommand* command, unsigned int param) 469 { 470 /* 471 471 CommandExecutor::createArgumentCompletionList(command, param); 472 472 … … 486 486 } 487 487 } 488 */ 488 489 } 489 490 490 491 Identifier* CommandExecutor::getPossibleIdentifier(const std::string& name) 491 492 { 493 /* 492 494 const std::string& lowercase = getLowercase(name); 493 495 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMap().find(lowercase); 494 496 if ((it != Identifier::getLowercaseStringIdentifierMapEnd()) && it->second->hasConsoleCommands()) 495 497 return it->second; 496 498 */ 497 499 return 0; 498 500 } 499 501 500 ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier) 501 { 502 _ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier) 503 { 504 /* 502 505 const std::string& lowercase = getLowercase(name); 503 506 if (!identifier) 504 507 { 505 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase);508 std::map<std::string, _ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase); 506 509 if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd()) 507 510 return it->second; … … 509 512 else 510 513 { 511 std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase);514 std::map<std::string, _ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase); 512 515 if (it != identifier->getLowercaseConsoleCommandMapEnd()) 513 516 return it->second; 514 517 } 518 */ 515 519 return 0; 516 520 } 517 521 518 const std::string& CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param) 519 { 522 const std::string& CommandExecutor::getPossibleArgument(const std::string& name, _ConsoleCommand* command, unsigned int param) 523 { 524 /* 520 525 CommandExecutor::createArgumentCompletionList(command, param); 521 526 … … 534 539 } 535 540 } 536 541 */ 537 542 return BLANKSTRING; 538 543 } 539 544 540 void CommandExecutor::createArgumentCompletionList(ConsoleCommand* command, unsigned int param) 541 { 545 void CommandExecutor::createArgumentCompletionList(_ConsoleCommand* command, unsigned int param) 546 { 547 /* 542 548 std::string params[5]; 543 549 … … 554 560 555 561 command->createArgumentCompletionList(param, params[0], params[1], params[2], params[3], params[4]); 562 */ 556 563 } 557 564 … … 643 650 } 644 651 } 645 646 void CommandExecutor::destroyExternalCommands()647 {648 for (std::set<ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandExternals_.begin();649 it != CommandExecutor::getInstance().consoleCommandExternals_.end(); ++it)650 delete *it;651 }652 652 } -
code/branches/consolecommands3/src/libraries/core/command/CommandExecutor.h
r7216 r7221 55 55 56 56 static CommandEvaluation evaluate(const std::string& command); 57 static const CommandEvaluation& getLastEvaluation();58 57 59 58 private: … … 70 69 static unsigned int argumentsFinished(); 71 70 static unsigned int argumentsGiven(); 72 static bool enoughArgumentsGiven( ConsoleCommand* command);71 static bool enoughArgumentsGiven(_ConsoleCommand* command); 73 72 static const std::string& getArgument(unsigned int index); 74 73 static const std::string& getLastArgument(); … … 76 75 static void createListOfPossibleIdentifiers(const std::string& fragment); 77 76 static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier = 0); 78 static void createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param);77 static void createListOfPossibleArguments(const std::string& fragment, _ConsoleCommand* command, unsigned int param); 79 78 80 79 static Identifier* getPossibleIdentifier(const std::string& name); 81 static ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0);82 static const std::string& getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);80 static _ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0); 81 static const std::string& getPossibleArgument(const std::string& name, _ConsoleCommand* command, unsigned int param); 83 82 84 static void createArgumentCompletionList( ConsoleCommand* command, unsigned int param);83 static void createArgumentCompletionList(_ConsoleCommand* command, unsigned int param); 85 84 static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list); 86 85 static std::string getCommonBegin(const ArgumentCompletionList& list); -
code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
r7218 r7221 343 343 } 344 344 345 void _ConsoleCommand::createArgumentCompletionList(unsigned int param, const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5)346 {347 if (param < 5 && this->argumentCompleter_[param])348 this->argumentList_ = (*this->argumentCompleter_[param])(param1, param2, param3, param4, param5);349 else350 this->argumentList_.clear();351 }352 353 345 _ConsoleCommand& _ConsoleCommand::description(const std::string& description) 354 346 { -
code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
r7218 r7221 268 268 ArgumentCompleter* getArgumentCompleter(unsigned int param) const; 269 269 270 void createArgumentCompletionList(unsigned int param, const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "");271 const ArgumentCompletionList& getArgumentCompletionList() const272 { return this->argumentList_; }273 ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const274 { return this->argumentList_.begin(); }275 ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const276 { return this->argumentList_.end(); }277 278 270 inline _ConsoleCommand& setAsInputCommand() 279 271 { … … 325 317 326 318 ArgumentCompleter* argumentCompleter_[5]; 327 ArgumentCompletionList argumentList_;328 319 329 320 KeybindMode::Value keybindMode_;
Note: See TracChangeset
for help on using the changeset viewer.