Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7216 in orxonox.OLD for branches/std/src/lib/shell/shell_input.cc


Ignore:
Timestamp:
Mar 12, 2006, 8:54:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/std:: compile and run again, with many more std::strings….

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/std/src/lib/shell/shell_input.cc

    r7207 r7216  
    4646  this->setClassID(CL_SHELL_INPUT, "ShellInput");
    4747
    48   this->inputLine = new char[1];
    49   this->inputLine[0] = '\0';
     48  this->inputLine = "";
    5049  this->historyIT = this->history.begin();
    5150  this->setHistoryLength(50);
     
    7069{
    7170  // delete what has to be deleted here
    72   delete[] this->inputLine;
    7371  delete this->completion;
    7472
    7573  while (!this->history.empty())
    7674  {
    77     delete[] this->history.front();
    7875    this->history.pop_front();
    7976  }
     
    9693void ShellInput::flush()
    9794{
    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);
    10597}
    10698
     
    109101 * @param text the new Text to set as InputLine
    110102 */
    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);
     103void ShellInput::setInputText(const std::string& text)
     104{
     105  this->inputLine = text;
     106  this->setText(this->inputLine);
    125107}
    126108
     
    134116  if (this->historyScrolling)
    135117  {
    136     delete[] this->history.back();
    137118    this->history.pop_back();
    138119    this->historyScrolling = false;
    139120  }
    140121
    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);
    147124}
    148125
     
    151128 * @param characters a \\0 terminated char-array to add to the InputLine
    152129 */
    153 void ShellInput::addCharacters(const char* characters)
     130void ShellInput::addCharacters(const std::string& characters)
    154131{
    155132  if (this->historyScrolling)
    156133  {
    157     delete[] this->history.back();
    158134    this->history.pop_back();
    159135    this->historyScrolling = false;
    160136  }
    161137
    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);
    168140}
    169141
     
    176148  if (this->historyScrolling)
    177149  {
    178     delete[] this->history.back();
    179150    this->history.pop_back();
    180151    this->historyScrolling = false;
    181152  }
    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);
    196158}
    197159
     
    202164bool ShellInput::executeCommand()
    203165{
    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())
    207169    return false;
    208170
    209   char* newCommand = new char[strlen(this->inputLine)+1];
    210   strcpy(newCommand, this->inputLine);
    211 
    212   ShellCommand::execute(newCommand);
     171  ShellCommand::execute(this->inputLine);
    213172
    214173  // removing the eventually added Entry (from scrolling) to the List
    215174  if (this->historyScrolling)
    216175  {
    217     delete[] this->history.back();
    218176    this->history.pop_back();
    219177    this->historyScrolling = false;
     
    221179
    222180  // adding the new Command to the History
    223   this->history.push_back(newCommand);
     181  this->history.push_back(this->inputLine);
    224182  if (this->history.size() > this->historyLength)
    225183  {
    226     delete[] this->history.front();
    227184    this->history.pop_front();
    228185  }
     
    241198  if (!this->historyScrolling)
    242199  {
    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);
    246201    this->historyScrolling = true;
    247202    this->historyIT = --this->history.end();
     
    250205  if(this->historyIT != this->history.begin())
    251206  {
    252     char* prevElem = *(--this->historyIT);
    253     if (prevElem == NULL)
     207    std::string prevElem = *(--this->historyIT);
     208    /*if (prevElem == NULL) /// TODO STD
    254209      return;
    255     else
     210    else */
    256211    {
    257212      this->flush();
     
    270225  if (this->historyIT != this->history.end())
    271226  {
    272     char* nextElem = *(++this->historyIT);
    273     if (nextElem == NULL)
     227    std::string nextElem = *(++this->historyIT);
     228    /*    if (nextElem == NULL) /// TODO FIX STD
    274229      return;
    275     else
     230    else */
    276231    {
    277232      this->flush();
     
    285240 * prints out some nice help about the Shell
    286241 */
    287 void ShellInput::help(const char* className, const char* functionName)
    288 {
    289   printf("%s::%s\n", className, functionName);
    290 
    291   if (strlen(className) == 0)
     242void 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())
    292247  {
    293248    PRINT(0)("Help for the most important Shell-commands\n");
     
    298253    PRINT(0)("- Also try 'help className'");
    299254  }
    300   else if (strlen (className) > 0 && strlen (functionName) == 0)
     255  else if (!className.empty() && functionName.empty())
    301256  {
    302257    ShellCommandClass::help(className);
Note: See TracChangeset for help on using the changeset viewer.