- Timestamp:
- Apr 27, 2006, 5:49:12 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/class_list.cc
r7396 r7403 249 249 if (cl != NULL) 250 250 { 251 std::list<BaseObject*>::const_iterator bo = find (cl->objectList.begin(), cl->objectList.end(), object);251 std::list<BaseObject*>::const_iterator bo = std::find (cl->objectList.begin(), cl->objectList.end(), object); 252 252 return (bo != cl->objectList.end()); 253 253 } … … 258 258 for (cl = ClassList::classList->begin(); cl != ClassList::classList->end(); cl++) 259 259 { 260 std::list<BaseObject*>::const_iterator bo = find ((*cl).objectList.begin(), (*cl).objectList.end(), object);260 std::list<BaseObject*>::const_iterator bo = std::find ((*cl).objectList.begin(), (*cl).objectList.end(), object); 261 261 if (bo != (*cl).objectList.end()) 262 262 return true; … … 265 265 return false; 266 266 } 267 268 bool ClassList::exists(const std::string& className, const std::string& objectName) 269 { 270 ClassList* cl = ClassList::getClassList(className); 271 if (likely(cl != NULL)) 272 { 273 std::list<BaseObject*>::iterator bo; 274 for (bo = cl->objectList.begin(); bo != cl->objectList.end(); bo++) 275 if ((*bo)->getName() != NULL && objectName == (*bo)->getName()) 276 return true; 277 } 278 return false; 279 } 280 267 281 268 282 /** -
trunk/src/lib/lang/class_list.h
r7221 r7403 47 47 static BaseObject* getObject(const std::string& name, ClassID classID = CL_NULL); 48 48 static bool exists(const BaseObject* object, ClassID classID = CL_NULL); 49 static bool exists(const std::string& className, const std::string& objectName); 49 50 50 51 void sendBack(std::list<BaseObject*>::const_iterator it); -
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 { -
trunk/src/lib/shell/shell_command.h
r7401 r7403 72 72 73 73 static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, const Executor& executor); 74 75 74 static void unregisterCommand(const std::string& commandName, const std::string& className); 75 static bool exists(const std::string& commandName, const std::string& className); 76 76 77 77 static void debug(); … … 81 81 virtual ~ShellCommand(); 82 82 83 static bool isRegistered(const std::string& commandName, const std::string& className);84 83 static const std::string& paramToString(long parameter); 85 84 -
trunk/src/lib/shell/shell_command_class.cc
r7399 r7403 110 110 * @returns the CommandClass if found, NULL otherwise 111 111 */ 112 const ShellCommandClass* ShellCommandClass:: isRegistered(const std::string& className)112 const ShellCommandClass* ShellCommandClass::exists(const std::string& className) 113 113 { 114 114 std::vector<ShellCommandClass*>::const_iterator classIT; -
trunk/src/lib/shell/shell_command_class.h
r7394 r7403 30 30 static ShellCommandClass* getCommandClass(const std::string& className); 31 31 static void unregisterAllCommands(); 32 static const ShellCommandClass* exists(const std::string& className); 32 33 33 34 static void help (const std::string& className); … … 37 38 virtual ~ShellCommandClass(); 38 39 39 static const ShellCommandClass* isRegistered(const std::string& className);40 40 41 41 void registerCommand(ShellCommand* command); -
trunk/src/lib/shell/shell_completion.cc
r7393 r7403 51 51 bool ShellCompletion::autoComplete(std::string& input) 52 52 { 53 long classID ;//< the classID retrieved from the Class.54 const std::list<BaseObject*>* objectList; //< the list of Objects stored in classID 53 long classID = CL_NULL; //< the classID retrieved from the Class. 54 const std::list<BaseObject*>* objectList; //< the list of Objects stored in classID's ClassList 55 55 bool emptyComplete = false; //< if the completion input is empty string. e.g "" 56 56 long completeType = NullCompletion; //< the Type we'd like to complete. 57 std::string completeString ;//< the string to complete.57 std::string completeString = ""; //< the string to complete. 58 58 59 59 … … 62 62 63 63 // Check if we are in a input. eg. the supplied string "class " and now we complete either function or object 64 if (input [input.size()-1] == ' ')64 if (input.empty() || input[input.size()-1] == ' ') 65 65 emptyComplete = true; 66 66 … … 69 69 70 70 // What String will be completed 71 if (emptyComplete == true) 72 completeString = ""; 73 else 71 if (!emptyComplete && inputSplits.size() >= 1) 74 72 completeString = inputSplits.getString(inputSplits.size()-1); 75 73 76 // CLASS COMPLETION77 if (inputSplits.size() == 0 )74 // CLASS/ALIAS COMPLETION (on first argument) 75 if (inputSplits.size() == 0 || (!emptyComplete && inputSplits.size() == 1)) 78 76 { 79 77 completeType |= ClassCompletion; 80 78 completeType |= AliasCompletion; 81 79 } 82 else if (inputSplits.size() == 1 && emptyComplete == false)83 {84 completeType |= ClassCompletion;85 completeType |= AliasCompletion;86 }87 80 88 81 // OBJECT/FUNCTION COMPLETIONS 89 else if (( inputSplits.size() == 1 && emptyComplete == true) ||90 (inputSplits.size() == 2 && emptyComplete == false))82 else if ((emptyComplete && inputSplits.size() == 1) || 83 (!emptyComplete && inputSplits.size() == 2)) 91 84 { 92 85 classID = ClassList::StringToID(inputSplits.getString(0)); … … 94 87 if (classID != CL_NULL) 95 88 completeType |= ObjectCompletion; 96 //if (objectList != NULL && objectList->getSize() == 1)97 89 completeType |= FunctionCompletion; 98 90 } 99 else if ((inputSplits.size() == 2 && emptyComplete == true) || 100 (inputSplits.size() == 3 && emptyComplete == false)) 101 { 102 classID = ClassList::StringToID(inputSplits.getString(0)); 103 if (classID == CL_NULL) 104 return false; 105 else 91 else if ((emptyComplete && inputSplits.size() == 2 ) || 92 (!emptyComplete && inputSplits.size() == 3)) 93 { 94 if (ClassList::exists(inputSplits[0], inputSplits[1])) 106 95 completeType |= FunctionCompletion; 107 96 } -
trunk/src/lib/shell/shell_completion.h
r7393 r7403 22 22 class ShellCompletion 23 23 { 24 //! an enumerator for different types the Shell can complete.25 typedef enum {26 NullCompletion = 0,27 ClassCompletion = 1,28 ObjectCompletion = 2,29 FunctionCompletion = 4,30 AliasCompletion = 8,24 //! an enumerator for different types the Shell can complete. 25 typedef enum { 26 NullCompletion = 0, 27 ClassCompletion = 1, 28 ObjectCompletion = 2, 29 FunctionCompletion = 4, 30 AliasCompletion = 8, 31 31 } CompletionType; 32 32 33 //! A struct for ShellElements (these are used as containers to identify an Input for what it is)34 struct CompletionElement35 {36 std::string name; //!< the Name of the Element to be completed.37 CompletionType type; //!< the type of the Element38 };33 //! A struct for ShellElements (these are used as containers to identify an Input for what it is) 34 struct CompletionElement 35 { 36 std::string name; //!< the Name of the Element to be completed. 37 CompletionType type; //!< the type of the Element 38 }; 39 39 40 public:41 ShellCompletion();42 virtual ~ShellCompletion();40 public: 41 ShellCompletion(); 42 virtual ~ShellCompletion(); 43 43 44 44 45 // Functions to produce the Complete Lists. 46 bool autoComplete(std::string& input); 47 // long classMatch(const char* input, unsigned int* length); 48 bool objectComplete(const std::string& objectBegin, long classID); 49 // bool objectMatch(const char* objectBegin, long classID, unsigned int* length); 50 bool commandComplete(const std::string& commandBegin, const std::string& className); 51 // bool functionMatch(const char* functionBegin, long classID, unsigned int* length); 52 bool aliasComplete(const std::string& aliasBegin); 45 // Functions to produce the Complete Lists. 46 bool autoComplete(std::string& input); 53 47 54 // Generally Completes. 55 bool generalComplete(std::string& input, 56 const std::string& begin, const std::string& displayAs = "%s", 57 const std::string& addBack = "", const std::string& addFront = ""); 48 static const std::string& ShellCompletion::typeToString(ShellCompletion::CompletionType type); 49 50 private: 51 // long classMatch(const char* input, unsigned int* length); 52 bool objectComplete(const std::string& objectBegin, long classID); 53 // bool objectMatch(const char* objectBegin, long classID, unsigned int* length); 54 bool commandComplete(const std::string& commandBegin, const std::string& className); 55 // bool functionMatch(const char* functionBegin, long classID, unsigned int* length); 56 bool aliasComplete(const std::string& aliasBegin); 57 58 // Generally Completes. 59 bool generalComplete(std::string& input, 60 const std::string& begin, const std::string& displayAs = "%s", 61 const std::string& addBack = "", const std::string& addFront = ""); 58 62 59 63 60 bool addToCompleteList(const std::list<std::string>& inputList, const std::string& completionBegin, ShellCompletion::CompletionType type);61 bool addToCompleteList(const std::list<BaseObject*>& inputList, const std::string& completionBegin, ShellCompletion::CompletionType type);64 bool addToCompleteList(const std::list<std::string>& inputList, const std::string& completionBegin, ShellCompletion::CompletionType type); 65 bool addToCompleteList(const std::list<BaseObject*>& inputList, const std::string& completionBegin, ShellCompletion::CompletionType type); 62 66 67 // Helpers. 68 void clearCompletionList(); 63 69 64 // Helpers. 65 void clearCompletionList(); 66 static const std::string& ShellCompletion::typeToString(ShellCompletion::CompletionType type); 70 private: 71 std::vector<CompletionElement> completionList; //!< A list of completions, that are io. 67 72 68 private: 69 std::vector<CompletionElement> completionList; //!< A list of completions, that are io. 70 71 static const std::string typeNames[]; //!< A list of Completion-Type-Names. 73 static const std::string typeNames[]; //!< A list of Completion-Type-Names. 72 74 }; 73 75 -
trunk/src/lib/shell/shell_input.h
r7393 r7403 39 39 40 40 // InputLine 41 void flush();42 41 void setInputText(const std::string& text); 43 42 void addCharacter(char character); 44 43 void addCharacters(const std::string& characters); 45 44 void removeCharacters(unsigned int characterCount = 1); 45 void flush(); 46 46 47 void setRepeatDelay(float repeatDelay, float repeatRate); 47 48
Note: See TracChangeset
for help on using the changeset viewer.