Changeset 5461 in orxonox.OLD for trunk/src/lib/event/command_chain.cc
- Timestamp:
- Oct 30, 2005, 10:37:14 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/event/command_chain.cc
r5460 r5461 30 30 31 31 /** 32 * creates a new ShellCommandClass32 * creates a new CommandChainClass 33 33 * @param className the Name of the command-class to create 34 34 */ 35 ShellCommandClass::ShellCommandClass(const char* className)36 { 37 this->setClassID(CL_ SHELL_COMMAND_CLASS, "ShellCommandClass");35 CommandChainClass::CommandChainClass(const char* className) 36 { 37 this->setClassID(CL_COMMAND_CHAIN_CLASS, "CommandChainClass"); 38 38 this->setName(className); 39 39 40 40 this->className = className; 41 41 this->classID = CL_NULL; 42 this->commandList = new tList< ShellCommandBase>;43 44 ShellCommandClass::commandClassList->add(this);42 this->commandList = new tList<CommandChainBase>; 43 44 CommandChainClass::commandClassList->add(this); 45 45 } 46 46 … … 48 48 * destructs the shellCommandClass again 49 49 */ 50 ShellCommandClass::~ShellCommandClass()51 { 52 tIterator< ShellCommandBase>* iterator = this->commandList->getIterator();53 ShellCommandBase* elem = iterator->firstElement();50 CommandChainClass::~CommandChainClass() 51 { 52 tIterator<CommandChainBase>* iterator = this->commandList->getIterator(); 53 CommandChainBase* elem = iterator->firstElement(); 54 54 while(elem != NULL) 55 55 { … … 67 67 * @returns true on success, false otherwise 68 68 */ 69 bool ShellCommandClass::getCommandListOfClass(const char* className, tList<const char>* stringList)69 bool CommandChainClass::getCommandListOfClass(const char* className, tList<const char>* stringList) 70 70 { 71 71 if (stringList == NULL || className == NULL) 72 72 return false; 73 73 74 tIterator< ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();75 ShellCommandClass* elem = iterator->firstElement();74 tIterator<CommandChainClass>* iterator = CommandChainClass::commandClassList->getIterator(); 75 CommandChainClass* elem = iterator->firstElement(); 76 76 while(elem != NULL) 77 77 { 78 78 if (!strcmp (elem->getName(), className)) 79 79 { 80 tIterator< ShellCommandBase>* itFkt = elem->commandList->getIterator();81 ShellCommandBase* command = itFkt->firstElement();80 tIterator<CommandChainBase>* itFkt = elem->commandList->getIterator(); 81 CommandChainBase* command = itFkt->firstElement(); 82 82 while (command != NULL) 83 83 { … … 95 95 96 96 /** 97 * collects the Aliases registered to the ShellCommands97 * collects the Aliases registered to the CommandChains 98 98 * @param stringList a List to paste the Aliases into. 99 99 * @returns true on success, false otherwise 100 100 */ 101 bool ShellCommandClass::getCommandListOfAlias(tList<const char>* stringList)102 { 103 if (stringList == NULL || ShellCommandClass::aliasList == NULL)101 bool CommandChainClass::getCommandListOfAlias(tList<const char>* stringList) 102 { 103 if (stringList == NULL || CommandChainClass::aliasList == NULL) 104 104 return false; 105 105 106 tIterator< ShellCommandAlias>* iterator = ShellCommandClass::aliasList->getIterator();107 ShellCommandAlias* elem = iterator->firstElement();106 tIterator<CommandChainAlias>* iterator = CommandChainClass::aliasList->getIterator(); 107 CommandChainAlias* elem = iterator->firstElement(); 108 108 while(elem != NULL) 109 109 { … … 118 118 * unregisters all Commands that exist 119 119 */ 120 void ShellCommandClass::unregisterAllCommands()120 void CommandChainClass::unregisterAllCommands() 121 121 { 122 122 // unregister all commands 123 tIterator< ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();124 ShellCommandClass* elem = iterator->firstElement();123 tIterator<CommandChainClass>* iterator = CommandChainClass::commandClassList->getIterator(); 124 CommandChainClass* elem = iterator->firstElement(); 125 125 while(elem != NULL) 126 126 { … … 131 131 delete iterator; 132 132 133 delete ShellCommandClass::commandClassList;134 ShellCommandClass::commandClassList = NULL;133 delete CommandChainClass::commandClassList; 134 CommandChainClass::commandClassList = NULL; 135 135 136 136 // unregister all aliases (there should be nothing to do here :)) 137 if ( ShellCommandClass::aliasList != NULL)138 { 139 tIterator< ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();140 ShellCommandAlias* elemAL = itAL->firstElement();137 if (CommandChainClass::aliasList != NULL) 138 { 139 tIterator<CommandChainAlias>* itAL = CommandChainClass::aliasList->getIterator(); 140 CommandChainAlias* elemAL = itAL->firstElement(); 141 141 while(elemAL != NULL) 142 142 { … … 145 145 } 146 146 delete itAL; 147 delete ShellCommandClass::aliasList;148 ShellCommandClass::aliasList = NULL;147 delete CommandChainClass::aliasList; 148 CommandChainClass::aliasList = NULL; 149 149 } 150 150 } … … 155 155 * @returns the CommandClass if found, NULL otherwise 156 156 */ 157 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className)158 { 159 if ( ShellCommandClass::commandClassList == NULL)157 const CommandChainClass* CommandChainClass::isRegistered(const char* className) 158 { 159 if (CommandChainClass::commandClassList == NULL) 160 160 initCommandClassList(); 161 161 162 tIterator< ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();163 ShellCommandClass* elem = iterator->firstElement();162 tIterator<CommandChainClass>* iterator = CommandChainClass::commandClassList->getIterator(); 163 CommandChainClass* elem = iterator->firstElement(); 164 164 while(elem != NULL) 165 165 { … … 183 183 * @returns the CommandClass if found, or a new CommandClass if not 184 184 */ 185 ShellCommandClass* ShellCommandClass::getCommandClass(const char* className)186 { 187 if ( ShellCommandClass::commandClassList == NULL)185 CommandChainClass* CommandChainClass::getCommandClass(const char* className) 186 { 187 if (CommandChainClass::commandClassList == NULL) 188 188 initCommandClassList(); 189 189 190 tIterator< ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();191 ShellCommandClass* elem = iterator->firstElement();190 tIterator<CommandChainClass>* iterator = CommandChainClass::commandClassList->getIterator(); 191 CommandChainClass* elem = iterator->firstElement(); 192 192 while(elem != NULL) 193 193 { … … 200 200 } 201 201 delete iterator; 202 return new ShellCommandClass(className);202 return new CommandChainClass(className); 203 203 } 204 204 … … 206 206 * initializes the CommandList (if it is NULL) 207 207 */ 208 void ShellCommandClass::initCommandClassList()209 { 210 if ( ShellCommandClass::commandClassList == NULL)211 { 212 ShellCommandClass::commandClassList = new tList<ShellCommandClass>;213 ShellCommandStatic<ShellCommandBase>::registerCommand("debug", "ShellCommand", ShellCommandBase::debug);214 } 215 } 216 217 void ShellCommandClass::help(const char* className)208 void CommandChainClass::initCommandClassList() 209 { 210 if (CommandChainClass::commandClassList == NULL) 211 { 212 CommandChainClass::commandClassList = new tList<CommandChainClass>; 213 CommandChainStatic<CommandChainBase>::registerCommand("debug", "CommandChain", CommandChainBase::debug); 214 } 215 } 216 217 void CommandChainClass::help(const char* className) 218 218 { 219 219 if (className == NULL) 220 220 return; 221 if (likely( ShellCommandClass::commandClassList != NULL))222 { 223 tIterator< ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator();224 ShellCommandClass* elemCL = itCL->firstElement();221 if (likely(CommandChainClass::commandClassList != NULL)) 222 { 223 tIterator<CommandChainClass>* itCL = CommandChainClass::commandClassList->getIterator(); 224 CommandChainClass* elemCL = itCL->firstElement(); 225 225 while(elemCL != NULL) 226 226 { … … 228 228 { 229 229 PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize()); 230 tIterator< ShellCommandBase>* iterator = elemCL->commandList->getIterator();231 const ShellCommandBase* elem = iterator->firstElement();230 tIterator<CommandChainBase>* iterator = elemCL->commandList->getIterator(); 231 const CommandChainBase* elem = iterator->firstElement(); 232 232 while(elem != NULL) 233 233 { 234 234 PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->paramCount); 235 235 for (unsigned int i = 0; i< elem->paramCount; i++) 236 PRINT(0)("%s ", ShellCommandBase::paramToString(elem->parameters[i]));236 PRINT(0)("%s ", CommandChainBase::paramToString(elem->parameters[i])); 237 237 if (elem->description != NULL) 238 238 PRINT(0)("- %s", elem->description); … … 256 256 } 257 257 258 tList< ShellCommandClass>* ShellCommandClass::commandClassList = NULL;259 tList< ShellCommandAlias>* ShellCommandClass::aliasList = NULL;258 tList<CommandChainClass>* CommandChainClass::commandClassList = NULL; 259 tList<CommandChainAlias>* CommandChainClass::aliasList = NULL; 260 260 261 261 /** … … 266 266 * @return self 267 267 */ 268 ShellCommandBase::ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...)269 { 270 this->setClassID(CL_ SHELL_COMMAND, "ShellCommand");268 CommandChainBase::CommandChainBase(const char* commandName, const char* className, unsigned int paramCount, ...) 269 { 270 this->setClassID(CL_COMMAND_CHAIN, "CommandChain"); 271 271 this->setName(commandName); 272 272 this->description = NULL; … … 274 274 275 275 // this->classID = classID; 276 this->shellClass = ShellCommandClass::getCommandClass(className); //ClassList::IDToString(classID);276 this->shellClass = CommandChainClass::getCommandClass(className); //ClassList::IDToString(classID); 277 277 if (this->shellClass != NULL) 278 278 this->shellClass->commandList->add(this); … … 321 321 322 322 /** 323 * deconstructs a ShellCommand323 * deconstructs a CommandChain 324 324 * @return 325 325 */ 326 ShellCommandBase::~ShellCommandBase()326 CommandChainBase::~CommandChainBase() 327 327 { 328 328 delete[] this->parameters; 329 if (this->alias != NULL && ShellCommandClass::aliasList != NULL)330 { 331 ShellCommandClass::aliasList->remove(this->alias);329 if (this->alias != NULL && CommandChainClass::aliasList != NULL) 330 { 331 CommandChainClass::aliasList->remove(this->alias); 332 332 delete this->alias; 333 333 } … … 339 339 * @param commandName the name of the command itself 340 340 */ 341 void ShellCommandBase::unregisterCommand(const char* commandName, const char* className)342 { 343 if ( ShellCommandClass::commandClassList == NULL)344 ShellCommandClass::initCommandClassList();345 346 const ShellCommandClass* checkClass = ShellCommandClass::isRegistered(className);341 void CommandChainBase::unregisterCommand(const char* commandName, const char* className) 342 { 343 if (CommandChainClass::commandClassList == NULL) 344 CommandChainClass::initCommandClassList(); 345 346 const CommandChainClass* checkClass = CommandChainClass::isRegistered(className); 347 347 348 348 if (checkClass != NULL) 349 349 { 350 tIterator< ShellCommandBase>* iterator = checkClass->commandList->getIterator();351 ShellCommandBase* elem = iterator->firstElement();350 tIterator<CommandChainBase>* iterator = checkClass->commandList->getIterator(); 351 CommandChainBase* elem = iterator->firstElement(); 352 352 while(elem != NULL) 353 353 { … … 364 364 if (checkClass->commandList->getSize() == 0) 365 365 { 366 ShellCommandClass::commandClassList->remove(checkClass);366 CommandChainClass::commandClassList->remove(checkClass); 367 367 delete checkClass; 368 368 } … … 380 380 * This is checked in the registerCommand-function. 381 381 */ 382 bool ShellCommandBase::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...)383 { 384 if ( ShellCommandClass::commandClassList == NULL)385 { 386 ShellCommandClass::initCommandClassList();382 bool CommandChainBase::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...) 383 { 384 if (CommandChainClass::commandClassList == NULL) 385 { 386 CommandChainClass::initCommandClassList(); 387 387 return false; 388 388 } 389 389 390 const ShellCommandClass* checkClass = ShellCommandClass::isRegistered(className);390 const CommandChainClass* checkClass = CommandChainClass::isRegistered(className); 391 391 if (checkClass != NULL) 392 392 { 393 tIterator< ShellCommandBase>* iterator = checkClass->commandList->getIterator();394 ShellCommandBase* elem = iterator->firstElement();393 tIterator<CommandChainBase>* iterator = checkClass->commandList->getIterator(); 394 CommandChainBase* elem = iterator->firstElement(); 395 395 while(elem != NULL) 396 396 { … … 418 418 */ 419 419 #include "stdlibincl.h" 420 bool ShellCommandBase::execute(const char* executionString)421 { 422 if ( ShellCommandClass::commandClassList == NULL)420 bool CommandChainBase::execute(const char* executionString) 421 { 422 if (CommandChainClass::commandClassList == NULL) 423 423 return false; 424 424 425 425 long classID = CL_NULL; //< the classID retrieved from the Class. 426 ShellCommandClass* commandClass = NULL; //< the command class this command applies to.426 CommandChainClass* commandClass = NULL; //< the command class this command applies to. 427 427 tList<BaseObject>* objectList = NULL; //< the list of Objects stored in classID 428 428 BaseObject* objectPointer = NULL; //< a pointer to th Object to Execute the command on … … 437 437 { 438 438 // CHECK FOR ALIAS 439 if ( ShellCommandClass::aliasList != NULL)440 { 441 tIterator< ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator();442 ShellCommandAlias* elemAL = itAL->firstElement();439 if (CommandChainClass::aliasList != NULL) 440 { 441 tIterator<CommandChainAlias>* itAL = CommandChainClass::aliasList->getIterator(); 442 CommandChainAlias* elemAL = itAL->firstElement(); 443 443 while(elemAL != NULL) 444 444 { … … 462 462 } 463 463 // looking for a Matching Class 464 if (likely( ShellCommandClass::commandClassList != NULL))465 { 466 tIterator< ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator();467 ShellCommandClass* elemCL = itCL->firstElement();464 if (likely(CommandChainClass::commandClassList != NULL)) 465 { 466 tIterator<CommandChainClass>* itCL = CommandChainClass::commandClassList->getIterator(); 467 CommandChainClass* elemCL = itCL->firstElement(); 468 468 while(elemCL != NULL) 469 469 { … … 507 507 if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3))) 508 508 { 509 tIterator< ShellCommandBase>* itCMD = commandClass->commandList->getIterator();510 ShellCommandBase* enumCMD = itCMD->firstElement();509 tIterator<CommandChainBase>* itCMD = commandClass->commandList->getIterator(); 510 CommandChainBase* enumCMD = itCMD->firstElement(); 511 511 while (enumCMD != NULL) 512 512 { 513 513 if (!strcmp(enumCMD->getName(), inputSplits.getString(fktPos))) 514 514 { 515 if (objectPointer == NULL && enumCMD->functorType == ShellCommand_Objective)515 if (objectPointer == NULL && enumCMD->functorType == CommandChain_Objective) 516 516 { 517 517 delete itCMD; … … 538 538 * @param description the description of the Given command 539 539 */ 540 ShellCommandBase* ShellCommandBase::describe(const char* description)540 CommandChainBase* CommandChainBase::describe(const char* description) 541 541 { 542 542 if (this == NULL) … … 554 554 * @returns itself 555 555 */ 556 ShellCommandBase* ShellCommandBase::setAlias(const char* alias)556 CommandChainBase* CommandChainBase::setAlias(const char* alias) 557 557 { 558 558 if (this == NULL) … … 565 565 else 566 566 { 567 if ( ShellCommandClass::aliasList == NULL)568 ShellCommandClass::aliasList = new tList<ShellCommandAlias>;569 570 ShellCommandAlias* aliasCMD = new ShellCommandAlias(alias, this);571 ShellCommandClass::aliasList->add(aliasCMD);567 if (CommandChainClass::aliasList == NULL) 568 CommandChainClass::aliasList = new tList<CommandChainAlias>; 569 570 CommandChainAlias* aliasCMD = new CommandChainAlias(alias, this); 571 CommandChainClass::aliasList->add(aliasCMD); 572 572 this->alias = aliasCMD; 573 573 } … … 584 584 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS] 585 585 */ 586 ShellCommandBase* ShellCommandBase::defaultValues(unsigned int count, ...)586 CommandChainBase* CommandChainBase::defaultValues(unsigned int count, ...) 587 587 { 588 588 if (this == NULL) … … 633 633 * prints out nice information about the Shells Commands 634 634 */ 635 void ShellCommandBase::debug()636 { 637 if ( ShellCommandClass::commandClassList == NULL)635 void CommandChainBase::debug() 636 { 637 if (CommandChainClass::commandClassList == NULL) 638 638 { 639 639 PRINT(0)("No Command registered.\n"); … … 641 641 } 642 642 643 tIterator< ShellCommandClass>* iteratorCL = ShellCommandClass::commandClassList->getIterator();644 ShellCommandClass* elemCL = iteratorCL->firstElement();643 tIterator<CommandChainClass>* iteratorCL = CommandChainClass::commandClassList->getIterator(); 644 CommandChainClass* elemCL = iteratorCL->firstElement(); 645 645 while(elemCL != NULL) 646 646 { 647 647 PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize()); 648 tIterator< ShellCommandBase>* iterator = elemCL->commandList->getIterator();649 const ShellCommandBase* elem = iterator->firstElement();648 tIterator<CommandChainBase>* iterator = elemCL->commandList->getIterator(); 649 const CommandChainBase* elem = iterator->firstElement(); 650 650 while(elem != NULL) 651 651 { 652 652 PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->paramCount); 653 653 for (unsigned int i = 0; i< elem->paramCount; i++) 654 printf("%s ", ShellCommandBase::paramToString(elem->parameters[i]));654 printf("%s ", CommandChainBase::paramToString(elem->parameters[i])); 655 655 if (elem->description != NULL) 656 656 printf("- %s", elem->description); … … 670 670 * @returns the Name of the Parameter at Hand 671 671 */ 672 const char* ShellCommandBase::paramToString(long parameter)672 const char* CommandChainBase::paramToString(long parameter) 673 673 { 674 674 switch (parameter)
Note: See TracChangeset
for help on using the changeset viewer.