Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7343 in orxonox.OLD for trunk/src/lib/shell


Ignore:
Timestamp:
Apr 19, 2006, 4:26:27 AM (19 years ago)
Author:
bensch
Message:

oroxnox/trunk: ShellInput and ShellCompletion more c++-like

Location:
trunk/src/lib/shell
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_completion.cc

    r7319 r7343  
    3232
    3333/**
    34  * standard constructor
    35  */
    36 ShellCompletion::ShellCompletion(ShellInput* input)
    37 {
    38   this->input = input;
    39 }
    40 
    41 
    42 /**
    43  * standard deconstructor
     34 * @brief standard constructor
     35 */
     36ShellCompletion::ShellCompletion()
     37{ }
     38
     39
     40/**
     41 * @brief standard deconstructor
    4442 */
    4543ShellCompletion::~ShellCompletion ()
    46 {
    47 }
    48 
    49 
    50 
    51 /**
    52  * autocompletes the Shell's inputLine
     44{ }
     45
     46
     47
     48/**
     49 * @brief autocompletes the Shell's inputLine
    5350 * @returns true, if a result was found, false otherwise
    5451 */
    55 bool ShellCompletion::autoComplete(ShellInput* input)
     52bool ShellCompletion::autoComplete(std::string& input)
    5653{
    5754  const char* completionLine;           //< the inputLine we complete.
     
    6764  this->emptyCompletionList();
    6865
    69   if (input != NULL)
    70     this->input = input;
    71   if (this->input == NULL)
    72   {
    73     PRINTF(2)("No ShellInput supplied\n");
    74     return false;
    75   }
    76 
    7766  // 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()[this->input->getInput().size()-1] == ' ')
     67  if (input[input.size()-1] == ' ')
    7968  {
    8069    emptyComplete = true;
     
    8271
    8372  // CREATE INPUTS
    84   SubString inputSplits(this->input->getInput(), " \t\n,");
     73  SubString inputSplits(input, " \t\n,");
    8574
    8675  // What String will be completed
     
    133122
    134123
    135   this->generalComplete(completeString);
    136   return true;
    137 }
    138 
    139 /**
    140  * autocompletes a className
     124  this->generalComplete(input, completeString);
     125  return true;
     126}
     127
     128/**
     129 * @brief autocompletes a className
    141130 * @param classBegin the Beginning of a String to autoComplete
    142131 * @return true on success, false otherwise
     
    156145
    157146/**
    158  * autocompletes an ObjectName
     147 * @brief autocompletes an ObjectName
    159148 * @param objectBegin the beginning string of a Object
    160149 * @param classID the ID of the Class to search for.
     
    178167
    179168/**
    180  * completes a Function
     169 * @brief completes a Function
    181170 * @param functionBegin the beginning of the function String
    182171 * @param classID the class' ID to complete the function of
     
    193182
    194183/**
    195  * completes an Alias
     184 * @brief completes an Alias
    196185 * @param aliasBegin the beginning of the Alias-String to complete
    197186 * @returns true on succes, false if something went wrong
     
    209198
    210199/**
    211  * completes the inputline on grounds of an inputList
     200 * @brief completes the inputline on grounds of an inputList
    212201 * @param begin the String to search in the inputList, and to extend with it.
    213202 * @param displayAs how to display the found value to the user, printf-style, !!with only one %s!! ex.: "::%s::"
     
    216205 * @return true if ok, false otherwise
    217206 */
    218 bool ShellCompletion::generalComplete(const std::string& begin, const std::string& displayAs, const std::string& addBack, const std::string& addFront)
    219 {
    220   if (this->input == NULL )
    221     return false;
     207bool ShellCompletion::generalComplete(std::string& input,
     208                                      const std::string& begin, const std::string& displayAs,
     209                                      const std::string& addBack, const std::string& addFront)
     210{
    222211  if (completionList.size() == 0)
    223212    return false;
     
    257246    adder.resize(addLength);
    258247
    259     if (this->input)
     248    input.resize(input.size()-inputLenght);
     249    input += adder;
     250
     251    if (completionList.size() == 1)
    260252    {
    261      this->input->removeCharacters(inputLenght);
    262      this->input->addCharacters(adder);
    263 
    264       if (completionList.size() == 1)
    265       {
    266         if ( addBack != "")
    267          this->input->addCharacters(addBack);
    268         this->input->addCharacter(' ');
    269       }
     253      if ( addBack != "")
     254       input += addBack;
     255      input += ' ';
    270256    }
    271257  }
     
    301287
    302288/**
    303  * searches for classes, which beginn with completionBegin
     289 * @brief searches for classes, which beginn with completionBegin
    304290 * @param inputList the List to parse through
    305291 * @param completionBegin the beginning string
     
    330316
    331317/**
    332  * deletes the Completion List.
     318 * @brief deletes the Completion List.
    333319 *
    334320 * This is done at the beginning of each completion-run
  • trunk/src/lib/shell/shell_completion.h

    r7225 r7343  
    3939
    4040 public:
    41   ShellCompletion(ShellInput* input = NULL);
     41  ShellCompletion();
    4242  virtual ~ShellCompletion();
    4343
    44   bool autoComplete(ShellInput* input = NULL);
     44  bool autoComplete(std::string& input);
    4545  bool classComplete(const std::string& classBegin);
    4646//  long classMatch(const char* input, unsigned int* length);
     
    5151  bool aliasComplete(const std::string& aliasBegin);
    5252
    53   bool generalComplete(const std::string& begin, const std::string& displayAs = "%s",
     53  bool generalComplete(std::string& input,
     54                       const std::string& begin, const std::string& displayAs = "%s",
    5455                       const std::string& addBack = "", const std::string& addFront = "");
    5556
     
    6263 private:
    6364   std::list<ShellC_Element>    completionList;          //!< A list of completions, that are io.
    64    ShellInput*                  input;                   //!< the input this completion works on.
    6565};
    6666
  • trunk/src/lib/shell/shell_input.cc

    r7342 r7343  
    4141 * this also generates a ShellCompletion automatically.
    4242*/
    43 ShellInput::ShellInput () : Text ("")
     43ShellInput::ShellInput ()
     44  : Text ("")
    4445{
    4546  this->pressedKey = SDLK_FIRST;
     
    6667  evh->unsubscribe(ES_SHELL, SDLK_PAGEDOWN);
    6768
    68   this->completion = new ShellCompletion(this);
    69 }
    70 
    71 /**
    72  * standard deconstructor
    73 */
     69}
     70
     71/**
     72 * @brief standard deconstructor
     73 */
    7474ShellInput::~ShellInput ()
    7575{
    76   // delete what has to be deleted here
    77   delete this->completion;
    78 
    79   while (!this->history.empty())
    80   {
    81     this->history.pop_front();
    82   }
    83 }
    84 
    85 /**
    86  * sets the Repeate-delay and rate
     76}
     77
     78/**
     79 * @brief sets the Repeate-delay and rate
    8780 * @param repeatDelay the Delay it takes, to repeate a key
    8881 * @param repeatRate the rate to repeate a pressed key
     
    9588
    9689/**
    97  * deletes the InputLine
     90 * @brief deletes the InputLine
    9891 */
    9992void ShellInput::flush()
     
    10497
    10598/**
    106  * sets the entire text of the InputLine to text
     99 * @brief sets the entire text of the InputLine to text
    107100 * @param text the new Text to set as InputLine
    108101 */
     
    115108
    116109/**
    117  * adds one character to the inputLine
     110 * @brief adds one character to the inputLine
    118111 * @param character the character to add to the inputLine
    119112 */
     
    131124
    132125/**
    133  * adds multiple Characters to thr inputLine
     126 * @brief adds multiple Characters to thr inputLine
    134127 * @param characters a \\0 terminated char-array to add to the InputLine
    135128 */
     
    147140
    148141/**
    149  * removes characterCount characters from the InputLine
     142 * @brief removes characterCount characters from the InputLine
    150143 * @param characterCount the count of Characters to remove from the input Line
    151144 */
     
    165158
    166159/**
    167  * executes the command stored in the inputLine
     160 * @brief executes the command stored in the inputLine
    168161 * @return true if the command was commited successfully, false otherwise
    169162 */
     
    198191
    199192/**
    200  * moves one entry up in the history.
     193 * @brief moves one entry up in the history.
    201194 */
    202195void ShellInput::historyMoveUp()
     
    223216
    224217/**
    225  * moves one entry down in the history
     218 * @brief moves one entry down in the history
    226219 */
    227220void ShellInput::historyMoveDown()
     
    244237
    245238/**
    246  * prints out some nice help about the Shell
     239 * @brief prints out some nice help about the Shell
    247240 */
    248241void ShellInput::help(const std::string& className, const std::string& functionName)
     
    267260
    268261/**
    269  * ticks the ShellInput
     262 * @brief ticks the ShellInput
    270263 * @param dt the time passed since the last update
    271264 */
     
    298291
    299292/**
    300  * listens for some event
     293 * @brief listens for some event
    301294 * @param event the Event happened
    302295 */
     
    323316    }
    324317    else if (event.type == SDLK_TAB)
    325       this->completion->autoComplete();
     318    {
     319      this->completion.autoComplete(this->inputLine);
     320      this->setText(this->inputLine);
     321    }
    326322    else if (event.type == SDLK_BACKSPACE)
    327323    {
  • trunk/src/lib/shell/shell_input.h

    r7221 r7343  
    1212#include "text.h"
    1313#include "event_listener.h"
     14#include "shell_completion.h"
     15
    1416#include <list>
    1517
     
    5456 private:
    5557    // HANDLING TEXT INPUT
    56    ShellCompletion*                  completion;       //!< The Completion Interface.
     58   ShellCompletion                   completion;       //!< The Completion Interface.
    5759
    5860   std::string                       inputLine;        //!< the Char-Array of the Buffer
Note: See TracChangeset for help on using the changeset viewer.