Changeset 5636 in orxonox.OLD for trunk/src/lib/shell/shell_command.cc
- Timestamp:
- Nov 18, 2005, 6:55:18 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command.cc
r5634 r5636 40 40 this->className = className; 41 41 this->classID = CL_NULL; 42 this->commandList = new tList<ShellCommand Base>;42 this->commandList = new tList<ShellCommand>; 43 43 44 44 ShellCommandClass::commandClassList->add(this); … … 50 50 ShellCommandClass::~ShellCommandClass() 51 51 { 52 tIterator<ShellCommand Base>* iterator = this->commandList->getIterator();53 ShellCommand Base* elem = iterator->firstElement();52 tIterator<ShellCommand>* iterator = this->commandList->getIterator(); 53 ShellCommand* elem = iterator->firstElement(); 54 54 while(elem != NULL) 55 55 { … … 78 78 if (!strcmp (elem->getName(), className)) 79 79 { 80 tIterator<ShellCommand Base>* itFkt = elem->commandList->getIterator();81 ShellCommand Base* command = itFkt->firstElement();80 tIterator<ShellCommand>* itFkt = elem->commandList->getIterator(); 81 ShellCommand* command = itFkt->firstElement(); 82 82 while (command != NULL) 83 83 { … … 120 120 void ShellCommandClass::unregisterAllCommands() 121 121 { 122 // unregister all commands 122 if (ShellCommandClass::commandClassList != NULL) 123 { 124 // unregister all commands 125 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator(); 126 ShellCommandClass* elem = iterator->firstElement(); 127 while(elem != NULL) 128 { 129 delete elem; 130 131 elem = iterator->nextElement(); 132 } 133 delete iterator; 134 135 delete ShellCommandClass::commandClassList; 136 ShellCommandClass::commandClassList = NULL; 137 } 138 139 // unregister all aliases (there should be nothing to do here :)) 140 if (ShellCommandClass::aliasList != NULL) 141 { 142 tIterator<ShellCommandAlias>* itAL = ShellCommandClass::aliasList->getIterator(); 143 ShellCommandAlias* elemAL = itAL->firstElement(); 144 while(elemAL != NULL) 145 { 146 delete elemAL; 147 elemAL = itAL->nextElement(); 148 } 149 delete itAL; 150 delete ShellCommandClass::aliasList; 151 ShellCommandClass::aliasList = NULL; 152 } 153 } 154 155 /** 156 * checks if a Class is already registered to the Commands' class-stack 157 * @param className the Name of the Class to check for 158 * @returns the CommandClass if found, NULL otherwise 159 */ 160 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className) 161 { 162 if (ShellCommandClass::commandClassList == NULL) 163 initCommandClassList(); 164 123 165 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator(); 124 166 ShellCommandClass* elem = iterator->firstElement(); 125 167 while(elem != NULL) 126 168 { 127 delete elem; 128 169 if (!strcmp(className, elem->className)) 170 { 171 if (elem->classID == CL_NULL) 172 elem->classID = ClassList::StringToID(className); 173 174 delete iterator; 175 return elem; 176 } 129 177 elem = iterator->nextElement(); 130 178 } 131 179 delete iterator; 132 133 delete ShellCommandClass::commandClassList; 134 ShellCommandClass::commandClassList = NULL; 135 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(); 141 while(elemAL != NULL) 142 { 143 delete elemAL; 144 elemAL = itAL->nextElement(); 145 } 146 delete itAL; 147 delete ShellCommandClass::aliasList; 148 ShellCommandClass::aliasList = NULL; 149 } 150 } 151 152 /** 153 * checks if a Class is already registered to the Commands' class-stack 154 * @param className the Name of the Class to check for 155 * @returns the CommandClass if found, NULL otherwise 156 */ 157 const ShellCommandClass* ShellCommandClass::isRegistered(const char* className) 180 return NULL; 181 } 182 183 /** 184 * searches for a CommandClass 185 * @param className the name of the CommandClass 186 * @returns the CommandClass if found, or a new CommandClass if not 187 */ 188 ShellCommandClass* ShellCommandClass::getCommandClass(const char* className) 158 189 { 159 190 if (ShellCommandClass::commandClassList == NULL) … … 166 197 if (!strcmp(className, elem->className)) 167 198 { 168 if (elem->classID == CL_NULL)169 elem->classID = ClassList::StringToID(className);170 171 199 delete iterator; 172 200 return elem; … … 175 203 } 176 204 delete iterator; 177 return NULL; 178 } 179 180 /** 181 * searches for a CommandClass 182 * @param className the name of the CommandClass 183 * @returns the CommandClass if found, or a new CommandClass if not 184 */ 185 ShellCommandClass* ShellCommandClass::getCommandClass(const char* className) 205 return new ShellCommandClass(className); 206 } 207 208 /** 209 * initializes the CommandList (if it is NULL) 210 */ 211 void ShellCommandClass::initCommandClassList() 186 212 { 187 213 if (ShellCommandClass::commandClassList == NULL) 188 initCommandClassList();189 190 tIterator<ShellCommandClass>* iterator = ShellCommandClass::commandClassList->getIterator();191 ShellCommandClass* elem = iterator->firstElement();192 while(elem != NULL)193 {194 if (!strcmp(className, elem->className))195 {196 delete iterator;197 return elem;198 }199 elem = iterator->nextElement();200 }201 delete iterator;202 return new ShellCommandClass(className);203 }204 205 /**206 * initializes the CommandList (if it is NULL)207 */208 void ShellCommandClass::initCommandClassList()209 {210 if (ShellCommandClass::commandClassList == NULL)211 214 { 212 215 ShellCommandClass::commandClassList = new tList<ShellCommandClass>; 213 ShellCommand Static<ShellCommandBase>::registerCommand("debug", "ShellCommand", ShellCommandBase::debug);216 ShellCommand::registerCommand("debug", "ShellCommand", new ExecutorStatic<ShellCommand>(ShellCommand::debug)); 214 217 } 215 218 } … … 228 231 { 229 232 PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize()); 230 tIterator<ShellCommand Base>* iterator = elemCL->commandList->getIterator();231 const ShellCommand Base* elem = iterator->firstElement();233 tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator(); 234 const ShellCommand* elem = iterator->firstElement(); 232 235 while(elem != NULL) 233 236 { 234 237 PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->paramCount); 235 238 for (unsigned int i = 0; i< elem->paramCount; i++) 236 PRINT(0)("%s ", ShellCommand Base::paramToString(elem->parameters[i]));239 PRINT(0)("%s ", ShellCommand::paramToString(elem->parameters[i])); 237 240 if (elem->description != NULL) 238 241 PRINT(0)("- %s", elem->description); … … 277 280 * @param paramCount the count of parameters this command takes 278 281 */ 279 ShellCommand Base::ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...)282 ShellCommand::ShellCommand(const char* commandName, const char* className, unsigned int paramCount, ...) 280 283 { 281 284 this->setClassID(CL_SHELL_COMMAND, "ShellCommand"); … … 306 309 * deconstructs a ShellCommand 307 310 */ 308 ShellCommand Base::~ShellCommandBase()311 ShellCommand::~ShellCommand() 309 312 { 310 313 delete[] this->parameters; … … 318 321 319 322 /** 323 * registers a new ShellCommand 324 */ 325 ShellCommand* ShellCommand::registerCommand(const char* commandName, const char* className, Executor* executor) 326 { 327 return NULL; 328 329 } 330 331 332 333 334 /** 320 335 * unregister an existing commandName 321 336 * @param className the name of the Class the command belongs to. 322 337 * @param commandName the name of the command itself 323 338 */ 324 void ShellCommand Base::unregisterCommand(const char* commandName, const char* className)339 void ShellCommand::unregisterCommand(const char* commandName, const char* className) 325 340 { 326 341 if (ShellCommandClass::commandClassList == NULL) … … 331 346 if (checkClass != NULL) 332 347 { 333 tIterator<ShellCommand Base>* iterator = checkClass->commandList->getIterator();334 ShellCommand Base* elem = iterator->firstElement();348 tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator(); 349 ShellCommand* elem = iterator->firstElement(); 335 350 while(elem != NULL) 336 351 { … … 363 378 * This is checked in the registerCommand-function. 364 379 */ 365 bool ShellCommand Base::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...)380 bool ShellCommand::isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...) 366 381 { 367 382 if (ShellCommandClass::commandClassList == NULL) … … 374 389 if (checkClass != NULL) 375 390 { 376 tIterator<ShellCommand Base>* iterator = checkClass->commandList->getIterator();377 ShellCommand Base* elem = iterator->firstElement();391 tIterator<ShellCommand>* iterator = checkClass->commandList->getIterator(); 392 ShellCommand* elem = iterator->firstElement(); 378 393 while(elem != NULL) 379 394 { … … 400 415 * @return true on success, false otherwise. 401 416 */ 402 bool ShellCommand Base::execute(const char* executionString)417 bool ShellCommand::execute(const char* executionString) 403 418 { 404 419 if (ShellCommandClass::commandClassList == NULL) … … 489 504 if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3))) 490 505 { 491 tIterator<ShellCommand Base>* itCMD = commandClass->commandList->getIterator();492 ShellCommand Base* enumCMD = itCMD->firstElement();506 tIterator<ShellCommand>* itCMD = commandClass->commandList->getIterator(); 507 ShellCommand* enumCMD = itCMD->firstElement(); 493 508 while (enumCMD != NULL) 494 509 { … … 520 535 * @param description the description of the Given command 521 536 */ 522 ShellCommand Base* ShellCommandBase::describe(const char* description)537 ShellCommand* ShellCommand::describe(const char* description) 523 538 { 524 539 if (this == NULL) … … 536 551 * @returns itself 537 552 */ 538 ShellCommand Base* ShellCommandBase::setAlias(const char* alias)553 ShellCommand* ShellCommand::setAlias(const char* alias) 539 554 { 540 555 if (this == NULL) … … 566 581 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS] 567 582 */ 568 ShellCommand Base* ShellCommandBase::defaultValues(unsigned int count, ...)583 ShellCommand* ShellCommand::defaultValues(unsigned int count, ...) 569 584 { 570 585 if (this == NULL) … … 615 630 * prints out nice information about the Shells Commands 616 631 */ 617 void ShellCommand Base::debug()632 void ShellCommand::debug() 618 633 { 619 634 if (ShellCommandClass::commandClassList == NULL) … … 628 643 { 629 644 PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize()); 630 tIterator<ShellCommand Base>* iterator = elemCL->commandList->getIterator();631 const ShellCommand Base* elem = iterator->firstElement();645 tIterator<ShellCommand>* iterator = elemCL->commandList->getIterator(); 646 const ShellCommand* elem = iterator->firstElement(); 632 647 while(elem != NULL) 633 648 { 634 649 PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->paramCount); 635 650 for (unsigned int i = 0; i< elem->paramCount; i++) 636 printf("%s ", ShellCommand Base::paramToString(elem->parameters[i]));651 printf("%s ", ShellCommand::paramToString(elem->parameters[i])); 637 652 if (elem->description != NULL) 638 653 printf("- %s", elem->description); … … 652 667 * @returns the Name of the Parameter at Hand 653 668 */ 654 const char* ShellCommand Base::paramToString(long parameter)669 const char* ShellCommand::paramToString(long parameter) 655 670 { 656 671 return MultiType::MultiTypeToString((MT_Type)parameter);
Note: See TracChangeset
for help on using the changeset viewer.