Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Apr 27, 2006, 8:42:16 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: cloning the Completors

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

Legend:

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

    r7403 r7407  
    4646    this->executor->setName(commandName);
    4747
     48    for (unsigned int i = 0; i < this->executor->getParamCount(); i++)
     49      this->completors.push_back(new CompletorDefault(&this->executor->getDefaultValue(i)));
    4850    this->alias = NULL;
    4951
     
    6264    if (this->alias != NULL)
    6365      delete this->alias;
     66    while (!this->completors.empty())
     67    {
     68      delete this->completors.back();
     69      this->completors.pop_back();
     70    }
    6471    delete this->executor;
    6572  }
  • trunk/src/lib/shell/shell_command.h

    r7403 r7407  
    1010
    1111#include "executor/executor.h"
    12 #include <stdarg.h>
     12#include "shell_completion_plugin.h"
    1313
    1414#define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
    15 
    16 
    1715
    1816namespace OrxShell
     
    2119  class ShellCommandClass;
    2220  class ShellCommandAlias;
     21  class CompletorPlugin;
    2322
    2423  /**
     
    7574    static bool exists(const std::string& commandName, const std::string& className);
    7675
     76    unsigned int getParamCount() const { return this->executor->getParamCount(); }
     77    const CompletorPlugin* const getCompletorPlugin(unsigned int i) const { return this->completors[i]; };
     78
    7779    static void debug();
    7880
     
    8890
    8991    std::string                      description;           //!< A description for this commnand. (initially ""). Assigned with (create)->describe("blablabla");
     92    std::vector<CompletorPlugin*>    completors;            //!< Completors for the Parameters
    9093    Executor*                        executor;              //!< The Executor, that really executes the Function.
    9194  };
  • trunk/src/lib/shell/shell_command_class.cc

    r7403 r7407  
    2929
    3030  /**
    31    * creates a new ShellCommandClass
     31   * @brief creates a new ShellCommandClass
    3232   * @param className the Name of the command-class to create
    3333   */
  • trunk/src/lib/shell/shell_completion_plugin.cc

    r7388 r7407  
    2727namespace OrxShell
    2828{
    29   void CompletorStringArray::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin)
     29  CompletorDefault::CompletorDefault(const MultiType* value)
     30  :_value(value)
     31  { }
     32
     33  void CompletorDefault::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
     34  {
     35    PRINT(0)("%s", MultiType::MultiTypeToString(this->_value->getType()).c_str());
     36  }
     37
     38  CompletorPlugin* CompletorDefault::clone() const
     39  {
     40    return new CompletorDefault(this->_value);
     41  }
     42
     43
     44
     45
     46
     47  void CompletorStringArray::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
    3048  {
    3149    unsigned int inputLen = completionBegin.size();
     
    3553  }
    3654
     55  CompletorPlugin* CompletorStringArray::clone() const
     56  {
     57    return new CompletorStringArray(this->_stringArray, this->_size);
     58  }
    3759
    3860
     
    4264  }
    4365
    44   void CompletorList::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin)
     66  void CompletorList::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
    4567  {
    4668    unsigned int inputLen = completionBegin.size();
     
    5173  }
    5274
     75  CompletorPlugin* CompletorList::clone() const
     76  {
     77    return new CompletorList(this->_list);
     78  }
    5379
    5480
     
    6086
    6187
    62   void CompletorFileSystem::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin)
     88  void CompletorFileSystem::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
    6389  {
    6490    if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir.
     
    6894    }
    6995  }
     96  CompletorPlugin* CompletorFileSystem::clone() const
     97  {
     98    return new CompletorFileSystem(this->_fileExtension, this->_startDir, this->_subDir);
     99  }
     100
    70101
    71102}
  • trunk/src/lib/shell/shell_completion_plugin.h

    r7406 r7407  
    1010#include <vector>
    1111#include <string>
     12#include "multi_type.h"
    1213
    1314namespace OrxShell
    1415{
    1516  //! The Base of All Completors
    16   class Completor
     17  class CompletorPlugin
    1718  {
    18     public:
    19       virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) = 0;
    20       virtual ~Completor() { };
    21     protected:
    22       Completor();
     19  public:
     20    virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const = 0;
     21    virtual ~CompletorPlugin() { };
     22
     23    virtual CompletorPlugin* clone() const = 0;
     24  protected:
     25    CompletorPlugin() {};
     26  };
     27
     28  class CompletorDefault : public CompletorPlugin
     29  {
     30  public:
     31    CompletorDefault(const MultiType* value);
     32    virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
     33
     34    virtual CompletorPlugin* clone() const;
     35  private:
     36    const MultiType*    _value;
    2337  };
    2438
    2539
     40  //! Completor that completes static Arrays of Strings.
     41  class CompletorStringArray : public CompletorPlugin
     42  {
     43  public:
     44    CompletorStringArray(const std::string* stringArray, unsigned int size)
     45        : _stringArray(stringArray), _size(size) {};
     46    virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
    2647
    27 
    28   //! Completor that completes static Arrays of Strings.
    29   class CompletorStringArray : public Completor
    30   {
    31     public:
    32       CompletorStringArray(const std::string* stringArray, unsigned int size)
    33           : _stringArray(stringArray), _size(size) {};
    34       virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin);
    35 
    36     private:
    37       const std::string*   _stringArray;
    38       unsigned int         _size;
     48    virtual CompletorPlugin* clone() const;
     49  private:
     50    const std::string*   _stringArray;
     51    unsigned int         _size;
    3952  };
    4053
    4154
    42   class CompletorList : public Completor
     55  class CompletorList : public CompletorPlugin
    4356  {
    44     public:
    45       CompletorList(const std::list<std::string>* list);
    46       virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin);
    47     private:
    48       const std::list<std::string>* _list;
     57  public:
     58    CompletorList(const std::list<std::string>* list);
     59    virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
     60    virtual CompletorPlugin* clone() const;
     61
     62  private:
     63    const std::list<std::string>* _list;
    4964  };
    5065
     
    5267
    5368  //! Completor that completes FileSystem Entries.
    54   class CompletorFileSystem : public Completor
     69  class CompletorFileSystem : public CompletorPlugin
    5570  {
    56 
    57     public:
    58       // Where to search if the completionString is empty.
    59       typedef enum
    60       {
    61         StartAtRoot,
    62         StartAtHome,
    63         StartAtDataDir,
     71  public:
     72    // Where to search if the completionString is empty.
     73    typedef enum
     74    {
     75      StartAtRoot,
     76      StartAtHome,
     77      StartAtDataDir,
    6478    } StartDirectory;
    6579
    66       CompletorFileSystem(const std::string& fileExtension = "",
    67                           StartDirectory startDir = StartAtDataDir,
    68                           const std::string& subDir = "");
    69       virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin);
     80    CompletorFileSystem(const std::string& fileExtension = "",
     81                        StartDirectory startDir = StartAtDataDir,
     82                        const std::string& subDir = "");
     83    virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
     84    virtual CompletorPlugin* clone() const;
    7085
    71     private:
    72       std::string             _fileExtension;
    73       std::string             _subDir;
    74       StartDirectory          _startDir;
     86  private:
     87    std::string             _fileExtension;
     88    std::string             _subDir;
     89    StartDirectory          _startDir;
    7590  };
    7691
     
    7994
    8095  //! A Templated Completor
    81   template<typename CLASS> class CompletorTList : public Completor
     96  template<typename CLASS> class CompletorTList : public CompletorPlugin
    8297  {
    83     public:
    84       CompletorTList(const std::list<CLASS*>& completionList);
    85       virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin)
    86       {};
     98  public:
     99    CompletorTList(const std::list<CLASS*>& completionList);
     100    virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin)
     101    {};
     102    virtual CompletorPlugin* clone() const;
    87103  };
    88104
Note: See TracChangeset for help on using the changeset viewer.