Changeset 5461 in orxonox.OLD for trunk/src/lib/event
- Timestamp:
- Oct 30, 2005, 10:37:14 AM (19 years ago)
- Location:
- trunk/src/lib/event
- Files:
-
- 2 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) -
trunk/src/lib/event/command_chain.h
r5460 r5461 1 1 /*! 2 * @file shell_command.h2 * @file command_chain.h 3 3 * Definition of a on-screen-shell 4 4 */ 5 5 6 #ifndef _ SHELL_COMMAND_H7 #define _ SHELL_COMMAND_H6 #ifndef _COMMAND_CHAIN_H 7 #define _COMMAND_CHAIN_H 8 8 9 9 #include "base_object.h" … … 15 15 #include <stdarg.h> 16 16 17 #define SHELL_COMMAND_MAX_SIZE //!< The maximum size of a Shell Command17 #define COMMAND_CHAIN_MAX_SIZE //!< The maximum size of a Shell Command 18 18 19 19 … … 29 29 * 30 30 * MEANING: 31 * ShellCommandBase* someUniqueVarName =32 * ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);31 * CommandChainBase* someUniqueVarName = 32 * CommandChain<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall); 33 33 * 34 34 * In the Shell you would call this Command using: 35 35 * $ ClassName [ObjectName] commandNameInShell [parameters] 36 36 */ 37 #define SHELL_COMMAND(command, class, function) \38 ShellCommandBase* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)37 #define COMMAND_CHAIN(command, class, function) \ 38 CommandChainBase* command_chain_##class##_##command = CommandChain<class>::registerCommand(#command, #class, &class::function) 39 39 /** 40 40 * an easy to use Macro to create a Command … … 44 44 * 45 45 * MEANING: 46 * ShellCommandBase* someUniqueVarName =47 * ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);46 * CommandChainBase* someUniqueVarName = 47 * CommandChain<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall); 48 48 * 49 49 * In the Shell you would call this Command using: 50 50 * $ ClassName [ObjectName] commandNameInShell [parameters] 51 51 */ 52 #define SHELL_COMMAND_STATIC(command, class, function) \53 ShellCommandBase* shell_command_##class##_##command = ShellCommandStatic<class>::registerCommand(#command, #class, function)52 #define COMMAND_CHAIN_STATIC(command, class, function) \ 53 CommandChainBase* command_chain_##class##_##command = CommandChainStatic<class>::registerCommand(#command, #class, function) 54 54 55 55 56 56 //! an enumerator for the definition of the Type. 57 57 typedef enum { 58 ShellCommand_Objective = 1,59 ShellCommand_Static = 2,60 } ShellCommand_Type;58 CommandChain_Objective = 1, 59 CommandChain_Static = 2, 60 } CommandChain_Type; 61 61 62 62 //////////////// 63 63 // BASE CLASS // 64 64 //////////////// 65 class ShellCommandBase;66 class ShellCommandAlias;65 class CommandChainBase; 66 class CommandChainAlias; 67 67 68 68 //! A class to hold all Classes that have (once) registered Commands. 69 class ShellCommandClass : public BaseObject69 class CommandChainClass : public BaseObject 70 70 { 71 friend class ShellCommandBase;71 friend class CommandChainBase; 72 72 73 73 public: 74 74 /** @returns the CommandClassList */ 75 static const tList< ShellCommandClass>* getCommandClassList() { return ShellCommandClass::commandClassList; };75 static const tList<CommandChainClass>* getCommandClassList() { return CommandChainClass::commandClassList; }; 76 76 static bool getCommandListOfClass(const char* className, tList<const char>* stringList); 77 77 static bool getCommandListOfAlias(tList<const char>* aliasList); 78 78 79 static ShellCommandClass* getCommandClass(const char* className);79 static CommandChainClass* getCommandClass(const char* className); 80 80 static void unregisterAllCommands(); 81 81 … … 83 83 84 84 private: 85 ShellCommandClass(const char* className);86 ~ ShellCommandClass();87 88 static const ShellCommandClass* isRegistered(const char* className);85 CommandChainClass(const char* className); 86 ~CommandChainClass(); 87 88 static const CommandChainClass* isRegistered(const char* className); 89 89 static void initCommandClassList(); 90 90 … … 92 92 const char* className; //!< The Name of the Class. This should match the ClassName of the Commands Class. 93 93 long classID; //!< The classID of this Class 94 tList< ShellCommandBase>* commandList; //!< A list of Commands from this Class95 static tList< ShellCommandClass>* commandClassList; //!< A list of Classes96 static tList< ShellCommandAlias>* aliasList; //!< An Alias to A Command. (only for classes with one Instance)94 tList<CommandChainBase>* commandList; //!< A list of Commands from this Class 95 static tList<CommandChainClass>* commandClassList; //!< A list of Classes 96 static tList<CommandChainAlias>* aliasList; //!< An Alias to A Command. (only for classes with one Instance) 97 97 }; 98 98 99 99 100 //! a baseClass for all possible ShellCommands101 class ShellCommandBase : public BaseObject100 //! a baseClass for all possible CommandChains 101 class CommandChainBase : public BaseObject 102 102 { 103 friend class ShellCommandClass;103 friend class CommandChainClass; 104 104 public: 105 105 static bool execute (const char* executionString); 106 106 107 ShellCommandBase* describe(const char* description);108 ShellCommandBase* setAlias(const char* alias);109 ShellCommandBase* defaultValues(unsigned int count, ...);107 CommandChainBase* describe(const char* description); 108 CommandChainBase* setAlias(const char* alias); 109 CommandChainBase* defaultValues(unsigned int count, ...); 110 110 111 111 /** @returns the CommandList of the Shell */ … … 115 115 116 116 protected: 117 ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...);118 ~ ShellCommandBase();117 CommandChainBase(const char* commandName, const char* className, unsigned int paramCount, ...); 118 ~CommandChainBase(); 119 119 120 120 /** @returns the Type of this Function (either static or objective) */ 121 inline ShellCommand_Type getType() { return this->functorType; };121 inline CommandChain_Type getType() { return this->functorType; }; 122 122 123 123 static bool isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...); … … 129 129 130 130 protected: 131 ShellCommand_Type functorType; //!< The type of Function we've got (either static or objective).131 CommandChain_Type functorType; //!< The type of Function we've got (either static or objective). 132 132 void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) 133 133 unsigned int paramCount; //!< the count of parameters. … … 140 140 141 141 private: 142 ShellCommandClass* shellClass; //!< A Pointer to the Shell-Class this Command belongs to.143 ShellCommandAlias* alias; //!< An Alias for the Class.142 CommandChainClass* shellClass; //!< A Pointer to the Shell-Class this Command belongs to. 143 CommandChainAlias* alias; //!< An Alias for the Class. 144 144 145 145 const char* description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla"); … … 168 168 // COMMAND REGISTRATION // 169 169 ////////////////////////// 170 // SHELLCOMMAND can be redefined as ShellCommand or ShellCommandStatic170 // SHELLCOMMAND can be redefined as CommandChain or CommandChainStatic 171 171 // SHELLCOMMANDEXECUTER can be redefined too. 172 172 // SHELLCOMMANDINCLASS 173 173 // SHELLCOMMANDTYPE 174 174 //! registers a command without any parameters 175 #define ShellCommandRegister0() \175 #define CommandChainRegister0() \ 176 176 static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)()) \ 177 177 { \ … … 182 182 183 183 //! registers a command with 1 parameter 184 #define ShellCommandRegister1(t1) \184 #define CommandChainRegister1(t1) \ 185 185 static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \ 186 186 { \ … … 191 191 192 192 //! registers a command with 2 parameters 193 #define ShellCommandRegister2(t1,t2) \193 #define CommandChainRegister2(t1,t2) \ 194 194 static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT) \ 195 195 { \ … … 200 200 201 201 //! registers a command with 3 parameters 202 #define ShellCommandRegister3(t1,t2,t3) \202 #define CommandChainRegister3(t1,t2,t3) \ 203 203 static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT) \ 204 204 { \ … … 209 209 210 210 //! registers a command with 4 parameters 211 #define ShellCommandRegister4(t1,t2,t3,t4) \211 #define CommandChainRegister4(t1,t2,t3,t4) \ 212 212 static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT) \ 213 213 { \ … … 218 218 219 219 //! registers a command with 5 parameters 220 #define ShellCommandRegister5(t1,t2,t3,t4,t5) \220 #define CommandChainRegister5(t1,t2,t3,t4,t5) \ 221 221 static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT, t5##_TYPE d5 = t5##_DEFAULT) \ 222 222 { \ 223 223 if (isRegistered(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \ 224 224 return NULL; \ 225 return new ShellCommand<T>(commandName, className, function, d1, d2, d3, d4, d5); \225 return new CommandChain<T>(commandName, className, function, d1, d2, d3, d4, d5); \ 226 226 } 227 227 … … 230 230 ///////////////// 231 231 //! creates a command that takes no parameters 232 #define ShellCommandConstructor0() \232 #define CommandChainConstructor0() \ 233 233 void SHELLCOMMANDINCLASS(*functionPointer_0)(); \ 234 234 SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)()) \ 235 : ShellCommandBase(commandName, className, 0) \235 : CommandChainBase(commandName, className, 0) \ 236 236 { \ 237 237 this->functorType = SHELLCOMMANDTYPE; \ … … 240 240 241 241 //! creates a command that takes one parameter 242 #define ShellCommandConstructor1(t1) \242 #define CommandChainConstructor1(t1) \ 243 243 void SHELLCOMMANDINCLASS(*functionPointer_1_##t1)(t1##_TYPE); \ 244 244 SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE), t1##_TYPE d1) \ 245 : ShellCommandBase(commandName, className, 1, t1##_PARAM, d1) \245 : CommandChainBase(commandName, className, 1, t1##_PARAM, d1) \ 246 246 { \ 247 247 this->functorType = SHELLCOMMANDTYPE; \ … … 250 250 251 251 //! creates a command that takes two parameters 252 #define ShellCommandConstructor2(t1,t2) \252 #define CommandChainConstructor2(t1,t2) \ 253 253 void SHELLCOMMANDINCLASS(*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE); \ 254 254 SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1, t2##_TYPE d2) \ 255 : ShellCommandBase(commandName, className, 2, t1##_PARAM, d1, t2##_PARAM, d2) \255 : CommandChainBase(commandName, className, 2, t1##_PARAM, d1, t2##_PARAM, d2) \ 256 256 { \ 257 257 this->functorType = SHELLCOMMANDTYPE; \ … … 260 260 261 261 //! creates a command that takes three parameter 262 #define ShellCommandConstructor3(t1,t2,t3) \262 #define CommandChainConstructor3(t1,t2,t3) \ 263 263 void SHELLCOMMANDINCLASS(*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE); \ 264 264 SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3) \ 265 : ShellCommandBase(commandName, className, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \265 : CommandChainBase(commandName, className, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \ 266 266 { \ 267 267 this->functorType = SHELLCOMMANDTYPE; \ … … 270 270 271 271 //! creates a command that takes four parameter 272 #define ShellCommandConstructor4(t1,t2,t3,t4) \272 #define CommandChainConstructor4(t1,t2,t3,t4) \ 273 273 void SHELLCOMMANDINCLASS(*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE); \ 274 274 SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4) \ 275 : ShellCommandBase(commandName, className, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \275 : CommandChainBase(commandName, className, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \ 276 276 { \ 277 277 this->functorType = SHELLCOMMANDTYPE; \ … … 280 280 281 281 //! creates a command that takes five parameter 282 #define ShellCommandConstructor5(t1,t2,t3,t4,t5) \282 #define CommandChainConstructor5(t1,t2,t3,t4,t5) \ 283 283 void SHELLCOMMANDINCLASS(*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \ 284 284 SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4, t5##_TYPE d5) \ 285 : ShellCommandBase(commandName, className, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \285 : CommandChainBase(commandName, className, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \ 286 286 { \ 287 287 this->functorType = SHELLCOMMANDTYPE; \ … … 293 293 /////////////// 294 294 //! execute-macro for functions with no parameters 295 #define ShellCommandExecute0() \295 #define CommandChainExecute0() \ 296 296 if (this->paramCount == 0) \ 297 297 SHELLCOMMANDEXECUTER(_0)() 298 298 299 299 //! execute-macro for functions with one parameter 300 #define ShellCommandExecute1(t1) \300 #define CommandChainExecute1(t1) \ 301 301 else if (this->paramCount == 1 && this->parameters[0] == t1##_PARAM) \ 302 302 SHELLCOMMANDEXECUTER(_1_##t1)(t1##_FUNC(parameters, t1##_DEFGRAB(0))) 303 303 304 304 //! execute-macro for functions with two parameters 305 #define ShellCommandExecute2(t1,t2) \305 #define CommandChainExecute2(t1,t2) \ 306 306 else if (this->paramCount == 2 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM) \ 307 307 SHELLCOMMANDEXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1))) 308 308 309 309 //! execute-macro for functions with three parameters 310 #define ShellCommandExecute3(t1,t2,t3) \310 #define CommandChainExecute3(t1,t2,t3) \ 311 311 else if (this->paramCount == 3 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM) \ 312 312 SHELLCOMMANDEXECUTER(_3_##t1##_##t2##_##t3)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2))) 313 313 314 314 //! execute-macro for functions with four parameters 315 #define ShellCommandExecute4(t1,t2,t3,t4) \315 #define CommandChainExecute4(t1,t2,t3,t4) \ 316 316 else if (this->paramCount == 4 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM) \ 317 317 SHELLCOMMANDEXECUTER(_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3))) 318 318 319 319 //! execute-macro for functions with five parameters 320 #define ShellCommandExecute5(t1,t2,t3,t4,t5) \320 #define CommandChainExecute5(t1,t2,t3,t4,t5) \ 321 321 else if (this->paramCount == 5 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM && this->parameters[4] == t5##_PARAM) \ 322 322 SHELLCOMMANDEXECUTER(_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3)), t5##_FUNC(sub.getString(4), t5##_DEFGRAB(4))) 323 323 324 324 325 //! keeps information about a ShellCommand326 template<class T> class ShellCommand : public ShellCommandBase325 //! keeps information about a CommandChain 326 template<class T> class CommandChain : public CommandChainBase 327 327 { 328 328 public: … … 333 333 #undef SHELLCOMMAND 334 334 #endif 335 #define SHELLCOMMAND ShellCommand335 #define SHELLCOMMAND CommandChain 336 336 #ifdef SHELLCOMMANDEXECUTER 337 337 #undef SHELLCOMMANDEXECUTER … … 345 345 #undef SHELLCOMMANDTYPE 346 346 #endif 347 #define SHELLCOMMANDTYPE ShellCommand_Objective347 #define SHELLCOMMANDTYPE CommandChain_Objective 348 348 //! FUNCTOR_LIST is the List of command-registerers 349 #define FUNCTOR_LIST(x) ShellCommandRegister ## x349 #define FUNCTOR_LIST(x) CommandChainRegister ## x 350 350 #include "functor_list.h" 351 351 #undef FUNCTOR_LIST … … 354 354 private: 355 355 //! FUNCTOR_LIST is the List of CommandConstructors 356 #define FUNCTOR_LIST(x) ShellCommandConstructor ## x356 #define FUNCTOR_LIST(x) CommandChainConstructor ## x 357 357 #include "functor_list.h" 358 358 #undef FUNCTOR_LIST … … 362 362 SubString sub(parameters, true); 363 363 //! FUNCTOR_LIST is the List of Executive Functions 364 #define FUNCTOR_LIST(x) ShellCommandExecute ## x364 #define FUNCTOR_LIST(x) CommandChainExecute ## x 365 365 #include "functor_list.h" 366 366 #undef FUNCTOR_LIST … … 368 368 }; 369 369 370 //! keeps information about a ShellCommand, that points to a Static Function371 template<class T> class ShellCommandStatic : public ShellCommandBase370 //! keeps information about a CommandChain, that points to a Static Function 371 template<class T> class CommandChainStatic : public CommandChainBase 372 372 { 373 373 public: … … 378 378 #undef SHELLCOMMAND 379 379 #endif 380 #define SHELLCOMMAND ShellCommandStatic380 #define SHELLCOMMAND CommandChainStatic 381 381 #ifdef SHELLCOMMANDEXECUTER 382 382 #undef SHELLCOMMANDEXECUTER … … 390 390 #undef SHELLCOMMANDTYPE 391 391 #endif 392 #define SHELLCOMMANDTYPE ShellCommand_Static392 #define SHELLCOMMANDTYPE CommandChain_Static 393 393 394 394 //! FUNCTOR_LIST is the List of command-registerers 395 #define FUNCTOR_LIST(x) ShellCommandRegister ## x395 #define FUNCTOR_LIST(x) CommandChainRegister ## x 396 396 #include "functor_list.h" 397 397 #undef FUNCTOR_LIST … … 399 399 private: 400 400 //! FUNCTOR_LIST is the List of CommandConstructors 401 #define FUNCTOR_LIST(x) ShellCommandConstructor ## x401 #define FUNCTOR_LIST(x) CommandChainConstructor ## x 402 402 #include "functor_list.h" 403 403 #undef FUNCTOR_LIST … … 407 407 SubString sub(parameters, true); 408 408 //! FUNCTOR_LIST is the List of Executive Functions 409 #define FUNCTOR_LIST(x) ShellCommandExecute ## x409 #define FUNCTOR_LIST(x) CommandChainExecute ## x 410 410 #include "functor_list.h" 411 411 #undef FUNCTOR_LIST … … 414 414 415 415 //! A Class, that handles aliases. 416 class ShellCommandAlias416 class CommandChainAlias 417 417 { 418 friend class ShellCommandBase;418 friend class CommandChainBase; 419 419 public: 420 420 /** @returns the Name of the Alias. */ 421 421 const char* getName() const { return this->aliasName; }; 422 422 /** @returns the Command, this Alias is asociated with */ 423 ShellCommandBase* getCommand() const { return this->command; };423 CommandChainBase* getCommand() const { return this->command; }; 424 424 425 425 private: 426 426 /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */ 427 ShellCommandAlias(const char* aliasName, ShellCommandBase* command) { this->aliasName = aliasName; this->command = command; };427 CommandChainAlias(const char* aliasName, CommandChainBase* command) { this->aliasName = aliasName; this->command = command; }; 428 428 429 429 private: 430 430 const char* aliasName; //!< the name of the Alias 431 ShellCommandBase* command; //!< a pointer to the command, this alias executes.431 CommandChainBase* command; //!< a pointer to the command, this alias executes. 432 432 }; 433 433 434 #endif /* _ SHELL_COMMAND_H */434 #endif /* _COMMAND_CHAIN_H */
Note: See TracChangeset
for help on using the changeset viewer.