Changeset 7216 in orxonox.OLD for branches/std/src/lib/shell
- Timestamp:
- Mar 12, 2006, 8:54:30 AM (19 years ago)
- Location:
- branches/std/src/lib/shell
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/std/src/lib/shell/shell.cc
r7198 r7216 85 85 this->lineSpacing = 0; 86 86 this->bActive = true; 87 this->fontFile = new char[strlen(SHELL_DEFAULT_FONT)+1]; 88 strcpy(this->fontFile, SHELL_DEFAULT_FONT); 87 this->fontFile = SHELL_DEFAULT_FONT; 89 88 90 89 … … 110 109 delete this->bufferText[i]; 111 110 delete[] this->bufferText; 112 delete[] this->fontFile;113 111 // delete the inputLine 114 112 delete this->shellInput; … … 139 137 if (!top) 140 138 { 141 this->bufferText[i]->setText((*textLine) , true);139 this->bufferText[i]->setText((*textLine)); 142 140 if (textLine != ShellBuffer::getInstance()->getBuffer()->begin()) 143 141 top = true; … … 167 165 if (textLine != ShellBuffer::getInstance()->getBuffer()->begin()) 168 166 { 169 this->bufferText[i]->setText((*textLine) , false);167 this->bufferText[i]->setText((*textLine)); 170 168 textLine--; 171 169 } … … 181 179 * (be aware that within orxonox fontFile is relative to the Data-Dir) 182 180 */ 183 void Shell::setFont(const char*fontFile)181 void Shell::setFont(const std::string& fontFile) 184 182 { 185 183 // if (!ResourceManager::isInDataDir(fontFile)) 186 184 // return false; 187 185 188 if (this->fontFile != NULL) 189 delete[] this->fontFile; 190 191 this->fontFile = new char[strlen(fontFile)+1]; 192 strcpy(this->fontFile, fontFile); 186 this->fontFile = fontFile; 193 187 194 188 this->rebuildText(); … … 245 239 * @param fileName the filename of the Image to load 246 240 */ 247 void Shell::setBackgroundImage(const char*fileName)241 void Shell::setBackgroundImage(const std::string& fileName) 248 242 { 249 243 this->backgroundMaterial->setDiffuseMap(fileName); … … 340 334 for (int i = 0; i < this->bufferDisplaySize; i++) 341 335 { 342 this->bufferText[i]->setText( NULL, true);336 this->bufferText[i]->setText(""); 343 337 } 344 338 … … 351 345 * @param text the text to output. 352 346 */ 353 void Shell::printToDisplayBuffer(const char*text)347 void Shell::printToDisplayBuffer(const std::string& text) 354 348 { 355 349 if(likely(bufferText != NULL)) … … 382 376 this->bufferText[0] = lastText; 383 377 384 this->bufferText[0]->setText(text , true);378 this->bufferText[0]->setText(text); 385 379 } 386 380 } … … 427 421 for (unsigned int i = 0; i < this->bufferDisplaySize; i++) 428 422 { 429 this->bufferText[i]->setText((*it) , false);423 this->bufferText[i]->setText((*it)); 430 424 it--; 431 425 } -
branches/std/src/lib/shell/shell.h
r5784 r7216 53 53 inline bool isActive() const { return this->bActive; }; 54 54 55 void setFont(const char*fontFile);55 void setFont(const std::string& fontFile); 56 56 void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); 57 57 void setTextColor(float r, float g, float b, float a); 58 58 void setBackgroundColor(float r, float g, float b, float a); 59 void setBackgroundImage(const char*fileName);59 void setBackgroundImage(const std::string& fileName); 60 60 61 61 void resetValues(); … … 64 64 // BUFFERS 65 65 void setBufferDisplaySize(unsigned int bufferDisplaySize); 66 void printToDisplayBuffer(const char*text);66 void printToDisplayBuffer(const std::string& text); 67 67 void moveDisplayBuffer(int lineCount); 68 68 … … 83 83 84 84 // void testI (int i); 85 // void testS (const char*s);85 // void testS (const std::string& s); 86 86 // void testB (bool b); 87 87 // void testF (float f); 88 // void testSF (const char*s, float f);88 // void testSF (const std::string& s, float f); 89 89 90 90 private: … … 95 95 unsigned int textSize; //!< The size of the text. 96 96 float textColor[4]; //!< The text's color [r,g,b,a]. 97 char*fontFile; //!< The file containing the font.97 std::string fontFile; //!< The file containing the font. 98 98 Material* backgroundMaterial; //!< A material for the background. 99 99 -
branches/std/src/lib/shell/shell_command.cc
r7211 r7216 153 153 * @return true on success, false otherwise. 154 154 */ 155 bool ShellCommand::execute(const char*executionString)155 bool ShellCommand::execute(const std::string& executionString) 156 156 { 157 157 if (ShellCommandClass::commandClassList == NULL) … … 184 184 { 185 185 if (inputSplits.getCount() > 1) 186 (*alias)->getCommand()->executor->execute(objectList->front(), executionString+inputSplits.getOffset(1)); 186 { 187 188 (*alias)->getCommand()->executor->execute(objectList->front(), executionString.substr(inputSplits.getOffset(1), executionString.size())); /// TODO CHECK IF OK 189 } 187 190 else 188 191 (*alias)->getCommand()->executor->execute(objectList->front(), ""); … … 240 243 return false; 241 244 if (inputSplits.getCount() > fktPos+1) 242 (*cmdIT)->executor->execute(objectPointer, executionString +inputSplits.getOffset(fktPos +1));245 (*cmdIT)->executor->execute(objectPointer, executionString.substr(inputSplits.getOffset(fktPos +1), executionString.size())); /// TODO CHECK IF OK 243 246 else 244 247 (*cmdIT)->executor->execute(objectPointer, ""); … … 326 329 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 327 330 { 328 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className , (*classIT)->commandList.size());331 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size()); 329 332 330 333 list<ShellCommand*>::iterator cmdIT; -
branches/std/src/lib/shell/shell_command.h
r7201 r7216 61 61 friend class ShellCommandClass; 62 62 public: 63 static bool execute (const char*executionString);63 static bool execute (const std::string& executionString); 64 64 65 65 ShellCommand* describe(const char* description); -
branches/std/src/lib/shell/shell_command_class.cc
r5780 r7216 36 36 * @param className the Name of the command-class to create 37 37 */ 38 ShellCommandClass::ShellCommandClass(const char* className) 38 ShellCommandClass::ShellCommandClass(const std::string& className) 39 : className(className) 39 40 { 40 41 this->setClassID(CL_SHELL_COMMAND_CLASS, "ShellCommandClass"); 41 42 this->setName(className); 42 43 43 this->className = className;44 44 this->classID = CL_NULL; 45 45 … … 65 65 * @returns true on success, false otherwise 66 66 */ 67 bool ShellCommandClass::getCommandListOfClass(const char* className, std::list<const char*>* stringList)68 { 69 if (stringList == NULL || className == NULL)67 bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>* stringList) 68 { 69 if (stringList == NULL) 70 70 return false; 71 71 … … 73 73 for(elem = ShellCommandClass::commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++) 74 74 { 75 if ( !strcmp ((*elem)->getName(), className))75 if (className == (*elem)->getName()) 76 76 { 77 77 list<ShellCommand*>::iterator command; … … 88 88 * @returns true on success, false otherwise 89 89 */ 90 bool ShellCommandClass::getCommandListOfAlias(std::list< const char*>* stringList)90 bool ShellCommandClass::getCommandListOfAlias(std::list<std::string>* stringList) 91 91 { 92 92 if (stringList == NULL || ShellCommandClass::aliasList == NULL) … … 138 138 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 139 139 { 140 if ( !strcmp(className, (*classIT)->className))140 if (className == (*classIT)->className) 141 141 { 142 142 if ((*classIT)->classID == CL_NULL) … … 154 154 * @returns the CommandClass if found, or a new CommandClass if not 155 155 */ 156 ShellCommandClass* ShellCommandClass::getCommandClass(const char*className)156 ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className) 157 157 { 158 158 if (ShellCommandClass::commandClassList == NULL) … … 162 162 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 163 163 { 164 if ( !strcmp(className, (*classIT)->className))164 if (className == (*classIT)->className) 165 165 { 166 166 return (*classIT); … … 186 186 * @param className: the Class of Commands to show help about 187 187 */ 188 void ShellCommandClass::help(const char* className) 189 { 190 if (className == NULL) 191 return; 188 void ShellCommandClass::help(const std::string& className) 189 { 192 190 if (likely(ShellCommandClass::commandClassList != NULL)) 193 191 { … … 195 193 for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++) 196 194 { 197 if ( (*classIT)->className && !strcasecmp(className, (*classIT)->className))195 if (className == (*classIT)->className) 198 196 { 199 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className , (*classIT)->commandList.size());197 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size()); 200 198 list<ShellCommand*>::const_iterator cmdIT; 201 199 for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++) … … 212 210 } 213 211 } 214 PRINTF(3)("Class %s not found in Command's classes\n", className );212 PRINTF(3)("Class %s not found in Command's classes\n", className.c_str()); 215 213 } 216 214 else -
branches/std/src/lib/shell/shell_command_class.h
r6981 r7216 27 27 /** @returns the CommandClassList */ 28 28 static const std::list<ShellCommandClass*>* getCommandClassList() { return ShellCommandClass::commandClassList; }; 29 static bool getCommandListOfClass(const char* className, std::list<const char*>* stringList);30 static bool getCommandListOfAlias(std::list< const char*>* aliasList);29 static bool getCommandListOfClass(const std::string& className, std::list<std::string>* stringList); 30 static bool getCommandListOfAlias(std::list<std::string>* aliasList); 31 31 32 static ShellCommandClass* getCommandClass(const char*className);32 static ShellCommandClass* getCommandClass(const std::string& className); 33 33 static void unregisterAllCommands(); 34 34 35 static void help (const char*className);35 static void help (const std::string& className); 36 36 37 37 private: 38 ShellCommandClass(const char*className);38 ShellCommandClass(const std::string& className); 39 39 virtual ~ShellCommandClass(); 40 40 … … 43 43 44 44 private: 45 const char*className; //!< The Name of the Class. This should match the ClassName of the Commands Class.45 const std::string className; //!< The Name of the Class. This should match the ClassName of the Commands Class. 46 46 long classID; //!< The classID of this Class 47 47 std::list<ShellCommand*> commandList; //!< A list of Commands from this Class -
branches/std/src/lib/shell/shell_completion.cc
r7211 r7216 76 76 77 77 // Check if we are in a input. eg. the supplied string "class " and now we complete either function or object 78 if (this->input->getInput() != NULL && 79 strrchr(this->input->getInput(), ' ') >= this->input->getInput() + strlen(this->input->getInput())-1) 78 if (this->input->getInput()[this->input->getInput().size()-1] == ' ') 80 79 { 81 80 emptyComplete = true; … … 83 82 84 83 // CREATE INPUTS 85 if (this->input->getInput() == NULL) 86 completionLine = ""; 87 else 88 completionLine = this->input->getInput() + strspn(this->input->getInput(), " \t\n"); 89 SubString inputSplits(completionLine, " \t\n,"); 84 SubString inputSplits(this->input->getInput(), " \t\n,"); 90 85 91 86 // What String will be completed … … 151 146 if (unlikely(classBegin == NULL)) 152 147 return false; 153 const std::list< const char*>* clList = ClassList::getClassNames();148 const std::list<std::string>* clList = ClassList::getClassNames(); 154 149 if (clList != NULL) 155 150 { … … 195 190 if (unlikely(functionBegin == NULL)) 196 191 return false; 197 std::list< const char*> fktList;192 std::list<std::string> fktList; 198 193 ShellCommandClass::getCommandListOfClass(className, &fktList); 199 194 //printf("%s\n", boList->firstElement()->getName()); … … 212 207 if (unlikely(aliasBegin == NULL)) 213 208 return false; 214 std::list< const char*> aliasList;209 std::list<std::string> aliasList; 215 210 ShellCommandClass::getCommandListOfAlias(&aliasList); 216 211 //printf("%s\n", boList->firstElement()->getName()); … … 295 290 * !! The strings MUST NOT be deleted !! 296 291 */ 297 bool ShellCompletion::addToCompleteList(const std::list< const char*>* inputList, const char* completionBegin, SHELLC_TYPE type)292 bool ShellCompletion::addToCompleteList(const std::list<std::string>* inputList, const char* completionBegin, SHELLC_TYPE type) 298 293 { 299 294 if (inputList == NULL || completionBegin == NULL) … … 301 296 unsigned int searchLength = strlen(completionBegin); 302 297 303 list< const char*>::const_iterator string;298 list<std::string>::const_iterator string; 304 299 for (string = inputList->begin(); string != inputList->end(); string++) 305 300 { 306 if ( strlen(*string) >= searchLength &&307 !strncasecmp(*string, completionBegin, searchLength))301 if ((*string).size() >= searchLength && 302 !strncasecmp((*string).c_str(), completionBegin, searchLength)) 308 303 { 309 304 ShellC_Element newElem; 310 newElem.name = *string;305 newElem.name = (*string).c_str(); 311 306 newElem.type = type; 312 307 this->completionList.push_back(newElem); -
branches/std/src/lib/shell/shell_completion.h
r5784 r7216 52 52 bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); 53 53 54 bool addToCompleteList(const std::list< const char*>* inputList, const char* completionBegin, SHELLC_TYPE type);54 bool addToCompleteList(const std::list<std::string>* inputList, const char* completionBegin, SHELLC_TYPE type); 55 55 bool addToCompleteList(const std::list<BaseObject*>* inputList, const char* completionBegin, SHELLC_TYPE type); 56 56 void emptyCompletionList(); -
branches/std/src/lib/shell/shell_input.cc
r7207 r7216 46 46 this->setClassID(CL_SHELL_INPUT, "ShellInput"); 47 47 48 this->inputLine = new char[1]; 49 this->inputLine[0] = '\0'; 48 this->inputLine = ""; 50 49 this->historyIT = this->history.begin(); 51 50 this->setHistoryLength(50); … … 70 69 { 71 70 // delete what has to be deleted here 72 delete[] this->inputLine;73 71 delete this->completion; 74 72 75 73 while (!this->history.empty()) 76 74 { 77 delete[] this->history.front();78 75 this->history.pop_front(); 79 76 } … … 96 93 void ShellInput::flush() 97 94 { 98 if (likely(this->inputLine != NULL)) 99 { 100 delete[] this->inputLine; 101 } 102 this->inputLine = new char[1]; 103 *this->inputLine = '\0'; 104 this->setText(this->inputLine, true); 95 this->inputLine.clear(); 96 this->setText(this->inputLine); 105 97 } 106 98 … … 109 101 * @param text the new Text to set as InputLine 110 102 */ 111 void ShellInput::setInputText(const char* text) 112 { 113 delete[] this->inputLine; 114 if (text == NULL) 115 { 116 this->inputLine = new char[1]; 117 this->inputLine[0] = '\0'; 118 } 119 else 120 { 121 this->inputLine = new char[strlen(text)+1]; 122 strcpy(this->inputLine, text); 123 } 124 this->setText(this->inputLine, true); 103 void ShellInput::setInputText(const std::string& text) 104 { 105 this->inputLine = text; 106 this->setText(this->inputLine); 125 107 } 126 108 … … 134 116 if (this->historyScrolling) 135 117 { 136 delete[] this->history.back();137 118 this->history.pop_back(); 138 119 this->historyScrolling = false; 139 120 } 140 121 141 char* addCharLine = new char[strlen(this->inputLine)+2]; 142 143 sprintf(addCharLine, "%s%c", this->inputLine, character); 144 delete[] this->inputLine; 145 this->inputLine = addCharLine; 146 this->setText(this->inputLine, true); 122 this->inputLine += character; 123 this->setText(this->inputLine); 147 124 } 148 125 … … 151 128 * @param characters a \\0 terminated char-array to add to the InputLine 152 129 */ 153 void ShellInput::addCharacters(const char*characters)130 void ShellInput::addCharacters(const std::string& characters) 154 131 { 155 132 if (this->historyScrolling) 156 133 { 157 delete[] this->history.back();158 134 this->history.pop_back(); 159 135 this->historyScrolling = false; 160 136 } 161 137 162 char* addCharLine = new char[strlen(this->inputLine)+strlen(characters)+1]; 163 164 sprintf(addCharLine, "%s%s", this->inputLine, characters); 165 delete[] this->inputLine; 166 this->inputLine = addCharLine; 167 this->setText(this->inputLine, true); 138 this->inputLine += characters; 139 this->setText(this->inputLine); 168 140 } 169 141 … … 176 148 if (this->historyScrolling) 177 149 { 178 delete[] this->history.back();179 150 this->history.pop_back(); 180 151 this->historyScrolling = false; 181 152 } 182 183 if (strlen(this->inputLine) == 0) 184 return; 185 186 if (characterCount > strlen(this->inputLine)) 187 characterCount = strlen(this->inputLine); 188 189 char* removeCharLine = new char[strlen(this->inputLine)-characterCount+1]; 190 191 strncpy(removeCharLine, this->inputLine, strlen(this->inputLine)-characterCount); 192 removeCharLine[strlen(this->inputLine)-characterCount] = '\0'; 193 delete[] this->inputLine; 194 this->inputLine = removeCharLine; 195 this->setText(this->inputLine, true); 153 if (this->inputLine.size() < characterCount) 154 characterCount = this->inputLine.size(); 155 156 this->inputLine.erase(this->inputLine.size() - characterCount, this->inputLine.size()); 157 this->setText(this->inputLine); 196 158 } 197 159 … … 202 164 bool ShellInput::executeCommand() 203 165 { 204 ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine );205 206 if ( strlen(this->inputLine) == 0)166 ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str()); 167 168 if (this->inputLine.empty()) 207 169 return false; 208 170 209 char* newCommand = new char[strlen(this->inputLine)+1]; 210 strcpy(newCommand, this->inputLine); 211 212 ShellCommand::execute(newCommand); 171 ShellCommand::execute(this->inputLine); 213 172 214 173 // removing the eventually added Entry (from scrolling) to the List 215 174 if (this->historyScrolling) 216 175 { 217 delete[] this->history.back();218 176 this->history.pop_back(); 219 177 this->historyScrolling = false; … … 221 179 222 180 // adding the new Command to the History 223 this->history.push_back( newCommand);181 this->history.push_back(this->inputLine); 224 182 if (this->history.size() > this->historyLength) 225 183 { 226 delete[] this->history.front();227 184 this->history.pop_front(); 228 185 } … … 241 198 if (!this->historyScrolling) 242 199 { 243 char* currentText = new char[strlen(this->inputLine)+1]; 244 strcpy(currentText, this->inputLine); 245 this->history.push_back(currentText); 200 this->history.push_back(this->inputLine); 246 201 this->historyScrolling = true; 247 202 this->historyIT = --this->history.end(); … … 250 205 if(this->historyIT != this->history.begin()) 251 206 { 252 char*prevElem = *(--this->historyIT);253 if (prevElem == NULL)207 std::string prevElem = *(--this->historyIT); 208 /*if (prevElem == NULL) /// TODO STD 254 209 return; 255 else 210 else */ 256 211 { 257 212 this->flush(); … … 270 225 if (this->historyIT != this->history.end()) 271 226 { 272 char*nextElem = *(++this->historyIT);273 if (nextElem == NULL)227 std::string nextElem = *(++this->historyIT); 228 /* if (nextElem == NULL) /// TODO FIX STD 274 229 return; 275 else 230 else */ 276 231 { 277 232 this->flush(); … … 285 240 * prints out some nice help about the Shell 286 241 */ 287 void ShellInput::help(const char* className, const char*functionName)288 { 289 printf("%s::%s\n", className , functionName);290 291 if ( strlen(className) == 0)242 void ShellInput::help(const std::string& className, const std::string& functionName) 243 { 244 printf("%s::%s\n", className.c_str(), functionName.c_str()); 245 246 if (className.empty()) 292 247 { 293 248 PRINT(0)("Help for the most important Shell-commands\n"); … … 298 253 PRINT(0)("- Also try 'help className'"); 299 254 } 300 else if ( strlen (className) > 0 && strlen (functionName) == 0)255 else if (!className.empty() && functionName.empty()) 301 256 { 302 257 ShellCommandClass::help(className); -
branches/std/src/lib/shell/shell_input.h
r5786 r7216 31 31 32 32 /** @returns the inputLine */ 33 const char*getInput() const { return this->inputLine; };33 const std::string& getInput() const { return this->inputLine; }; 34 34 35 35 // InputLine 36 36 void flush(); 37 void setInputText(const char*text);37 void setInputText(const std::string& text); 38 38 void addCharacter(char character); 39 void addCharacters(const char*characters);39 void addCharacters(const std::string& characters); 40 40 void removeCharacters(unsigned int characterCount = 1); 41 41 void setRepeatDelay(float repeatDelay, float repeatRate); … … 47 47 void historyMoveDown(); 48 48 49 void help(const char* className = "", const char*function = "");49 void help(const std::string& className = "", const std::string& function = ""); 50 50 51 51 virtual void tick(float dt); … … 54 54 private: 55 55 // HANDLING TEXT INPUT 56 ShellCompletion* completion;//!< The Completion Interface.56 ShellCompletion* completion; //!< The Completion Interface. 57 57 58 char* inputLine;//!< the Char-Array of the Buffer59 float repeatRate;//!< The Repeat-Delay.60 float repeatDelay;//!< The delay of the first Character of a given Character.61 float delayed;//!< how much of the delay is remaining.62 Uint16 pressedKey;//!< the pressed key that will be repeated.58 std::string inputLine; //!< the Char-Array of the Buffer 59 float repeatRate; //!< The Repeat-Delay. 60 float repeatDelay; //!< The delay of the first Character of a given Character. 61 float delayed; //!< how much of the delay is remaining. 62 Uint16 pressedKey; //!< the pressed key that will be repeated. 63 63 64 std::list< char*> history;//!< The history of given commands.65 std::list< char*>::iterator historyIT;66 unsigned int historyLength;//!< The maximum length of the InputHistory.67 bool historyScrolling;//!< true if we are scrolling through the history.64 std::list<std::string> history; //!< The history of given commands. 65 std::list<std::string>::iterator historyIT; //!< The locator that tells us, where we are in the history. 66 unsigned int historyLength; //!< The maximum length of the InputHistory. 67 bool historyScrolling; //!< true if we are scrolling through the history. 68 68 }; 69 69
Note: See TracChangeset
for help on using the changeset viewer.