Changeset 7403 in orxonox.OLD for trunk/src/lib/shell/shell_command.cc
- Timestamp:
- Apr 27, 2006, 5:49:12 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command.cc
r7401 r7403 70 70 ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, const Executor& executor) 71 71 { 72 if (ShellCommand:: isRegistered(commandName, className))72 if (ShellCommand::exists(commandName, className)) 73 73 return NULL; 74 74 else … … 104 104 * This is checked in the registerCommand-function. 105 105 */ 106 bool ShellCommand:: isRegistered(const std::string& commandName, const std::string& className)107 { 108 const ShellCommandClass* checkClass = ShellCommandClass:: isRegistered(className);109 if ( checkClass != NULL)106 bool ShellCommand::exists(const std::string& commandName, const std::string& className) 107 { 108 const ShellCommandClass* checkClass = ShellCommandClass::exists(className); 109 if (likely(checkClass != NULL)) 110 110 { 111 111 std::vector<ShellCommand*>::const_iterator elem; … … 139 139 bool emptyComplete = false; //< if the completion input is empty string. e.g "" 140 140 // long completeType = SHELLC_NONE; //< the Type we'd like to complete. 141 141 142 SubString inputSplits(executionString, SubString::WhiteSpacesWithComma); 142 143 … … 147 148 148 149 // if we only have one input (!MUST BE AN ALIAS) 149 if (inputSplits.size() >= 1) 150 { 151 // CHECK FOR ALIAS 152 std::vector<ShellCommandAlias*>::const_iterator alias; 153 for (alias = ShellCommandAlias::getAliases().begin(); alias != ShellCommandAlias::getAliases().end(); alias++ ) 154 { 155 if (inputSplits.getString(0) == (*alias)->getName() && (*alias)->getCommand() != NULL && 156 (*alias)->getCommand()->shellClass != NULL ) 150 // CHECK FOR ALIAS 151 std::vector<ShellCommandAlias*>::const_iterator alias; 152 for (alias = ShellCommandAlias::getAliases().begin(); alias != ShellCommandAlias::getAliases().end(); alias++ ) 153 { 154 if (inputSplits.getString(0) == (*alias)->getName() && (*alias)->getCommand() != NULL && 155 (*alias)->getCommand()->shellClass != NULL ) 156 { 157 objectList = ClassList::getList((*alias)->getCommand()->shellClass->getName()); 158 if (objectList != NULL) 157 159 { 158 objectList = ClassList::getList((*alias)->getCommand()->shellClass->getName()); 159 if (objectList != NULL) 160 (*(*alias)->getCommand()->executor)(objectList->front(), inputSplits.getSubSet(1).join()); 161 return true; 162 } 163 } 164 } 165 166 // looking for a Matching Class (in the First Argument) 167 std::vector<ShellCommandClass*>::iterator commandClassIT; 168 for (commandClassIT = ShellCommandClass::commandClassList.begin(); commandClassIT != ShellCommandClass::commandClassList.end(); commandClassIT++) 169 { 170 if (inputSplits[0] == (*commandClassIT)->getName()) 171 { 172 //elemCL->getName(); 173 classID = ClassList::StringToID((*commandClassIT)->getName()); 174 commandClass = (*commandClassIT); 175 objectList = ClassList::getList((ClassID)classID); 176 break; 177 } 178 } 179 180 // Second Agument. (either Object, or Function) 181 if (commandClass != NULL && inputSplits.size() >= 2) 182 { 183 int fktPos = 1; // The position of the Function (either at pos 1(if object given), or 2) 184 // If we have an ObjectList. 185 if (objectList != NULL) 186 { 187 // Checking for a Match in the Objects of classID (else take the first) 188 std::list<BaseObject*>::const_iterator object; 189 for (object = objectList->begin(); object != objectList->end(); object++) 190 { 191 if ((*object)->getName() != NULL && inputSplits[1] == (*object)->getName()) 160 192 { 161 (*(*alias)->getCommand()->executor)(objectList->front(), inputSplits.getSubSet(1).join()); 162 return true; 193 /// TODO make this work for multiple Objects at once. 194 objectPointer = (*object); 195 fktPos = 2; 196 break; 163 197 } 164 198 } 165 } 166 167 // looking for a Matching Class 168 std::vector<ShellCommandClass*>::iterator commandClassIT; 169 for (commandClassIT = ShellCommandClass::commandClassList.begin(); commandClassIT != ShellCommandClass::commandClassList.end(); commandClassIT++) 170 { 171 if ((*commandClassIT)->getName() && inputSplits[0] == (*commandClassIT)->getName()) 199 200 // if we did not find an Object with matching name, take the first. 201 if (objectPointer == NULL) 202 objectPointer = objectList->front(); 203 } 204 205 // match a function. 206 if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.size() >= 3))) 207 { 208 std::vector<ShellCommand*>::iterator cmdIT; 209 for (cmdIT = commandClass->commandList.begin(); cmdIT != commandClass->commandList.end(); cmdIT++) 172 210 { 173 //elemCL->getName(); 174 classID = ClassList::StringToID((*commandClassIT)->getName()); 175 commandClass = (*commandClassIT); 176 objectList = ClassList::getList((ClassID)classID); 177 break; 178 } 179 } 180 181 // Second Agument. (either Object, or Function) 182 if (commandClass != NULL && inputSplits.size() >= 2) 183 { 184 int fktPos = 1; // The position of the Function (either at pos 1, or 2) 185 // If we have an ObjectList. 186 if (objectList != NULL) 187 { 188 // Checking for a Match in the Objects of classID (else take the first) 189 std::list<BaseObject*>::const_iterator object; 190 for (object = objectList->begin(); object != objectList->end(); object++) 211 if (inputSplits[fktPos] == (*cmdIT)->getName()) 191 212 { 192 if ((*object)->getName() != NULL && inputSplits[1] == (*object)->getName()) 213 if (objectPointer == NULL && (*cmdIT)->executor->getType() & Executor_Objective) 214 return false; 215 else 193 216 { 194 objectPointer = (*object); 195 fktPos = 2; 196 break; 197 } 198 } 199 200 // if we did not find an Object with matching name, take the first. 201 if (objectPointer == NULL) 202 objectPointer = objectList->front(); 203 } 204 205 // match a function. 206 if (commandClass != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.size() >= 3))) 207 { 208 std::vector<ShellCommand*>::iterator cmdIT; 209 for (cmdIT = commandClass->commandList.begin(); cmdIT != commandClass->commandList.end(); cmdIT++) 210 { 211 if (inputSplits[fktPos] == (*cmdIT)->getName()) 212 { 213 if (objectPointer == NULL && (*cmdIT)->executor->getType() & Executor_Objective) 214 return false; 215 else 216 { 217 (*(*cmdIT)->executor)(objectPointer, inputSplits.getSubSet(fktPos+1).join()); /// TODO CHECK IF OK 218 return true; 219 } 217 (*(*cmdIT)->executor)(objectPointer, inputSplits.getSubSet(fktPos+1).join()); /// TODO CHECK IF OK 218 return true; 220 219 } 221 220 } … … 234 233 if (this == NULL) 235 234 return NULL; 236 else 237 { 238 this->description = description; 239 return this; 240 } 235 this->description = description; 236 return this; 241 237 } 242 238 … … 344 340 * @returns true on success, false otherwise 345 341 */ 342 346 343 bool ShellCommandAlias::getCommandListOfAlias(std::list<std::string>& stringList) 347 344 {
Note: See TracChangeset
for help on using the changeset viewer.