- Timestamp:
- Aug 19, 2005, 12:59:46 AM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine.cc
r4857 r5072 95 95 if (this->text) 96 96 delete []this->text; 97 this->text = new char[strlen(text)+1]; 98 strcpy(this->text, text); 97 if (text != NULL) 98 { 99 this->text = new char[strlen(text)+1]; 100 strcpy(this->text, text); 101 } 102 else 103 { 104 this->text = new char[1]; 105 strcpy(this->text, ""); 106 } 99 107 100 108 -
trunk/src/orxonox.cc
r5037 r5072 49 49 #include "class_list.h" 50 50 #include "substring.h" 51 #include "shell.h" 51 52 52 53 #include <string.h> … … 93 94 delete GarbageCollector::getInstance(); 94 95 FastFactory::deleteAll(); 96 delete Shell::getInstance(); 95 97 96 98 delete EventHandler::getInstance(); … … 247 249 248 250 CDEngine::getInstance(); 251 Shell::getInstance(); 249 252 250 253 return 0; -
trunk/src/util/shell.cc
r5069 r5072 18 18 #include "shell.h" 19 19 20 #include "text_engine.h" 21 #include "list.h" 22 20 23 using namespace std; 21 24 … … 26 29 Shell::Shell () 27 30 { 28 this->setClassID(CL_SHELL, "Shell"); 31 this->setClassID(CL_SHELL, "Shell"); 32 this->setName("Shell"); 33 34 this->bufferText = new tList<Text>; 35 this->buffer = new tList<char>; 36 37 this->setBufferSize(100); 38 this->setBufferDisplaySize(5); 29 39 } 30 40 … … 42 52 } 43 53 44 45 46 47 void setBufferDisplaySize(unsigned int bufferDisplaySize); 54 void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize) 55 { 56 this->bufferDisplaySize = bufferDisplaySize; 57 58 while (bufferDisplaySize < this->bufferText->getSize()) 59 { 60 delete this->bufferText->lastElement(); 61 this->bufferText->removeLast(); 62 } 63 while(bufferDisplaySize > this->bufferText->getSize()) 64 { 65 Text* newText = TextEngine::getInstance()->createText("fonts/earth.ttf", 30, TEXT_DYNAMIC, 0, 255, 0); 66 this->bufferText->add(newText); 67 // add the Text here 68 } 69 } 48 70 49 71 /** … … 52 74 void Shell::flushBuffers() 53 75 { 54 76 // remove all chars from the BufferTexts. 77 tIterator<Text>* textIterator = this->bufferText->getIterator(); 78 Text* textElem = textIterator->nextElement(); 79 80 while (textElem != NULL) 81 { 82 textElem->setText(NULL); 83 84 textElem = textIterator->nextElement(); 85 } 86 delete textIterator; 87 88 89 // delete all the Chars in the Buffers 90 tIterator<char>* charIterator = this->buffer->getIterator(); 91 char* charElem = charIterator->nextElement(); 92 93 while (charElem != NULL) 94 { 95 delete charElem; 96 97 charElem = charIterator->nextElement(); 98 } 99 delete charIterator; 55 100 } 56 101 … … 59 104 * @param line the Line as in the first argument in printf 60 105 * @param args the arguments as a va_list 106 * 107 * @todo optimize 61 108 */ 62 109 void Shell::addBufferLine(const char* line, va_list args) 63 110 { 111 char tmp[1024];// = new char* 112 vsprintf(tmp, line, args); 113 114 char* newLine = new char[strlen(tmp)+1]; 115 strcpy(newLine, tmp); 116 117 this->buffer->add(newLine); 118 119 if (this->buffer->getSize() > this->bufferSize) 120 { 121 delete this->buffer->firstElement(); 122 this->buffer->remove(this->buffer->firstElement()); 123 } 64 124 } 65 125 … … 67 127 * moves the buffer around lineCount lines upwards (negative values move down) 68 128 * @param lineCount the Count of lines to move upwards 129 * 130 * @todo 69 131 */ 70 132 void Shell::moveBuffer(int lineCount) … … 78 140 const char* Shell::getBufferLine(unsigned int lineNumber) 79 141 { 142 tIterator<char>* charIterator = this->buffer->getIterator(); 143 char* charElem = charIterator->nextElement(); 144 145 int i = 1; 146 while (charElem != NULL) 147 { 148 if (i++ < lineNumber) 149 { 150 delete charIterator; 151 return charElem; 152 } 153 154 charElem = charIterator->nextElement(); 155 } 156 delete charIterator; 80 157 } 81 158 … … 86 163 void Shell::flushInputLine() 87 164 { 165 if (likely(this->inputLine != NULL)) 166 { 167 delete [] this->inputLine; 168 } 169 this->inputLine = new char[1]; 170 *this->inputLine = '\0'; 171 88 172 } 89 173 … … 94 178 void Shell::addCharacter(char character) 95 179 { 180 char* addCharLine = new char[strlen(inputLine)+2]; 181 182 sprintf(addCharLine, "%s%c", this->inputLine, character); 183 delete this->inputLine; 184 this->inputLine = addCharLine; 96 185 } 97 186 … … 102 191 void Shell::addCharacters(const char* characters) 103 192 { 193 char* addCharLine = new char[strlen(inputLine)+strlen(characters)+1]; 194 195 sprintf(addCharLine, "%s%s", this->inputLine, characters); 196 delete this->inputLine; 197 this->inputLine = addCharLine; 104 198 } 105 199 … … 110 204 void Shell::removeCharacters(unsigned int characterCount) 111 205 { 206 if (characterCount > strlen(this->inputLine)) 207 characterCount = strlen(this->inputLine); 208 209 char* removeCharLine = new char[strlen(inputLine)-characterCount+1]; 210 211 strncpy(removeCharLine, this->inputLine, strlen(inputLine)-characterCount); 212 delete this->inputLine; 213 this->inputLine = removeCharLine; 112 214 } 113 215 -
trunk/src/util/shell.h
r5069 r5072 35 35 virtual ~Shell(); 36 36 /** @returns a Pointer to the only object of this Class */ 37 inline static Shell* getInstance( void) { if (!Shell::singletonRef) Shell::singletonRef = new Shell(); return Shell::singletonRef; };37 inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell(); return Shell::singletonRef; }; 38 38 39 39 … … 70 70 private: 71 71 Shell(); 72 static Shell* singletonRef; 72 static Shell* singletonRef; //!< The singleton-reference to the only memeber of this class. 73 73 74 unsigned int bufferSize; 75 unsigned int bufferDisplaySize; 74 unsigned int bufferSize; //!< The Size of the buffer 75 unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters) 76 76 77 char* inputLine; 77 char* inputLine; //!< the Char-Array of the Buffer 78 78 79 tList<char>* buffer; 79 tList<char>* buffer; //!< A list of stored char-arrays(strings) to store the history 80 80 81 tList<Text>* bufferText; //!< A list of s ored bufferLines of the Shell81 tList<Text>* bufferText; //!< A list of stored bufferTexts for the display of the buffer 82 82 Text* inputLineText; //!< The inputLine of the Shell 83 83 };
Note: See TracChangeset
for help on using the changeset viewer.