Changeset 7742 in orxonox.OLD for trunk/src/lib/shell/shell_command_class.cc
- Timestamp:
- May 20, 2006, 3:53:37 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command_class.cc
r7411 r7742 24 24 #include "compiler.h" 25 25 26 27 26 28 namespace OrxShell 27 29 { 28 std::vector<ShellCommandClass*>ShellCommandClass::commandClassList;30 CmdClassList ShellCommandClass::commandClassList; 29 31 30 32 /** … … 40 42 this->classID = CL_NULL; 41 43 44 printf("::: %d\n", commandClassList.size()); 42 45 ShellCommandClass::commandClassList.push_back(this); 46 printf("::: %d\n", commandClassList.size()); 43 47 } 44 48 … … 50 54 while(!this->commandList.empty()) 51 55 delete this->commandList.back(); 56 CmdClassList::iterator delClass = std::find(ShellCommandClass::commandClassList.begin(), ShellCommandClass::commandClassList.end(), this); 57 if (delClass != ShellCommandClass::commandClassList.end()) 58 ShellCommandClass::commandClassList.erase(delClass); 52 59 } 53 60 … … 57 64 void ShellCommandClass::registerCommand(ShellCommand* command) 58 65 { 66 printf("::::::::::: ADDED COMMAND:: '%s'\n", command->getName()); 59 67 this->commandList.push_back(command); 60 } 61 62 /** 63 * @brief unregister command. 68 this->help(); 69 } 70 71 /** 72 * @brief Unregisters a command. 64 73 * @param command the Command to unregister. 65 74 */ 66 75 void ShellCommandClass::unregisterCommand(ShellCommand* command) 67 76 { 68 std::vector<ShellCommand*>::iterator delC = std::find(this->commandList.begin(), this->commandList.end(), command);77 CmdList::iterator delC = std::find(this->commandList.begin(), this->commandList.end(), command); 69 78 if (delC != this->commandList.end()) 70 79 this->commandList.erase(delC); … … 77 86 { 78 87 // unregister all commands and Classes 79 std::vector<ShellCommandClass*>::iterator classIT; 80 for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++) 81 delete (*classIT); 88 CmdClassList::iterator classIT; 89 90 while (!ShellCommandClass::commandClassList.empty()) 91 delete ShellCommandClass::commandClassList.back(); 82 92 } 83 93 … … 91 101 bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>& stringList) 92 102 { 93 std::vector<ShellCommandClass*>::iterator elem;103 CmdClassList::const_iterator elem; 94 104 for(elem = ShellCommandClass::commandClassList.begin(); elem != ShellCommandClass::commandClassList.end(); elem++) 95 105 { 96 106 if (className == (*elem)->getName()) 97 107 { 98 std::vector<ShellCommand*>::iterator command;108 CmdList::iterator command; 99 109 for(command = (*elem)->commandList.begin(); command != (*elem)->commandList.end(); command++) 100 110 stringList.push_back((*command)->getName()); 111 return true; 101 112 } 102 113 } 103 return true;114 return false; 104 115 } 105 116 … … 110 121 * @returns the CommandClass if found, NULL otherwise 111 122 */ 112 constShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className)113 { 114 std::vector<ShellCommandClass*>::const_iterator classIT;123 ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className) 124 { 125 CmdClassList::const_iterator classIT; 115 126 for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++) 116 127 if (className == (*classIT)->className) … … 144 155 ShellCommandClass* ShellCommandClass::acquireCommandClass(const std::string& className) 145 156 { 146 std::vector<ShellCommandClass*>::iterator classIT; 147 for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++) 148 if (className == (*classIT)->className) 149 return (*classIT); 157 ShellCommandClass* cmdClass = ShellCommandClass::getCommandClass(className); 158 if (cmdClass != NULL) 159 return (cmdClass); 150 160 return new ShellCommandClass(className); 151 161 } … … 157 167 void ShellCommandClass::help(const std::string& className) 158 168 { 159 std::vector<ShellCommandClass*>::iterator classIT; 169 if (className.empty()) 170 PRINT(0)("===== Displaying %d registered Classes:\n", ShellCommandClass::commandClassList.size()); 171 172 173 CmdClassList::iterator classIT; 160 174 for (classIT = ShellCommandClass::commandClassList.begin(); classIT != ShellCommandClass::commandClassList.end(); classIT++) 161 175 { 162 if (className == (*classIT)->className)176 if (className.empty() || className == (*classIT)->className) 163 177 { 164 178 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size()); 165 std::vector<ShellCommand*>::const_iterator cmdIT;179 CmdList::const_iterator cmdIT; 166 180 for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++) 167 181 { … … 174 188 PRINT(0)("\n"); 175 189 } 176 return; 190 if (likely(!className.empty())) 191 return; 177 192 } 178 193 } 179 PRINTF(3)("Class %s not found in Command's classes\n", className.c_str()); 180 } 181 194 PRINTF(3)("Class '%s' not found in Command's classes\n", className.c_str()); 195 } 182 196 } 183 197
Note: See TracChangeset
for help on using the changeset viewer.