Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

Location:
trunk/src/lib/shell
Files:
2 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/Makefile.am

    r7428 r9869  
    66libORXshell_a_SOURCES = \
    77                shell.cc \
    8                 shell_buffer.cc \
    98                shell_input.cc \
    109                shell_command.cc \
     
    1615noinst_HEADERS= \
    1716                shell.h \
    18                 shell_buffer.h \
    1917                shell_input.h \
     18                shell_command_class.h \
    2019                shell_command.h \
    21                 shell_command_class.h \
    2220                shell_completion.h \
    2321                shell_completion_plugin.h
  • trunk/src/lib/shell/shell.cc

    r8362 r9869  
    1818#include "shell.h"
    1919#include "shell_command.h"
    20 #include "shell_buffer.h"
     20#include "debug_buffer.h"
    2121#include "shell_input.h"
    2222
     
    5454  ->completionPlugin(0, OrxShell::CompletorFileSystem(".ttf", "fonts/"));
    5555
     56  ObjectListDefinition(Shell);
    5657
    5758  /**
     
    6061  Shell::Shell ()
    6162  {
    62     this->setClassID(CL_SHELL, "Shell");
     63    this->registerObject(this, Shell::_objectList);
     64
    6365    this->setName("Shell");
    6466
    65     this->shellBuffer = ShellBuffer::getInstance();
     67    this->shellBuffer = DebugBuffer::getInstance();
    6668
    6769    // EVENT-Handler subscription of '`' to all States.
     
    246248    this->setSizeX2D(width);
    247249    for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
    248     {
    249250      (*textIt)->setLineWidth(width);
    250     }
    251251  }
    252252
     
    444444  {
    445445    this->flush();
    446     ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);
     446    DebugBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);
    447447  }
    448448
     
    470470        this->moveDisplayBuffer(-this->bufferDisplaySize+1);
    471471      }
    472       else if (event.type == EV_VIDEO_RESIZE)
    473       {
    474         this->updateResolution(event.resize.w);
    475         this->repositionText();
    476       }
     472    }
     473    else if (event.type == EV_VIDEO_RESIZE)
     474    {
     475      this->updateResolution(event.resize.w);
     476      this->repositionText();
    477477    }
    478478  }
  • trunk/src/lib/shell/shell.h

    r7762 r9869  
    1414
    1515#include "shell_input.h"
    16 #include "shell_buffer.h"
     16#include "debug_buffer.h"
    1717#include "material.h"
    1818
     
    4848  class Shell : public Element2D, public EventListener
    4949  {
    50 
     50    ObjectListDeclaration(Shell);
    5151  public:
    5252    Shell();
     
    9393  private:
    9494    // GENERAL
    95     ShellBuffer*                shellBuffer;            //!< The local ShellBuffer.
     95    DebugBuffer*                shellBuffer;            //!< The local ShellBuffer.
    9696
    9797    bool                        bActive;                //!< If the shell is active.
  • trunk/src/lib/shell/shell_command.cc

    r9406 r9869  
    2020
    2121#include "compiler.h"
     22#include "helper_functions.h"
    2223#include "debug.h"
    23 #include "class_list.h"
    2424
    2525#include "key_names.h"
     
    2727namespace OrxShell
    2828{
     29  ObjectListDefinition(ShellCommand);
    2930  SHELL_COMMAND(debug, ShellCommandClass, help);
    3031
     
    3637   * @param paramCount the count of parameters this command takes
    3738   */
    38   ShellCommand::ShellCommand(const std::string& commandName, const std::string& className, Executor* executor)
    39   {
    40     this->setClassID(CL_SHELL_COMMAND, "ShellCommand");
     39  ShellCommand::ShellCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor)
     40  {
     41    this->registerObject(this, ShellCommand::_objectList);
    4142    PRINTF(4)("create shellcommand '%s' for class '%s'\n", commandName.c_str(), className.c_str());
    4243    this->setName(commandName);
     
    4445    // copy the executor:
    4546    this->executor = executor;
    46     this->executor->setName(commandName);
    4747
    4848    for (unsigned int i = 0; i < this->executor->getParamCount(); i++)
     
    7575   * @brief registers a new ShellCommand
    7676   */
    77   ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, Executor* executor)
     77  ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor)
    7878  {
    7979    if (ShellCommand::exists(commandName, className))
     
    9494  void ShellCommand::unregisterCommand(const std::string& commandName, const std::string& className)
    9595  {
    96 
    9796    ShellCommandClass* cmdClass = ShellCommandClass::acquireCommandClass(className);
    9897    if (cmdClass != NULL)
    9998    {
    10099      CmdList::iterator cmd;
    101       for (cmd = cmdClass->commandList.begin(); cmd != cmdClass->commandList.end(); cmd++)
     100      for (cmd = cmdClass->_commandList.begin(); cmd != cmdClass->_commandList.end(); cmd++)
    102101        if (commandName == (*cmd)->getName())
    103102        {
     
    119118
    120119    CmdList::const_iterator elem;
    121     for (unsigned int i = 0; i < cmdClass->commandList.size(); i++)
    122     {
    123       if (commandName == cmdClass->commandList[i]->getName())
    124         return (cmdClass->commandList[i]);
     120    for (unsigned int i = 0; i < cmdClass->_commandList.size(); i++)
     121    {
     122      if (commandName == cmdClass->_commandList[i]->getName())
     123        return (cmdClass->_commandList[i]);
    125124    }
    126125    return NULL;
     
    242241      return false;
    243242
    244     const std::list<BaseObject*>* objectList = ClassList::getList(cmd->shellClass->getName());
     243    const ObjectListBase* const objectList = ObjectListBase::getObjectList(cmd->shellClass->getName());
    245244    if (objectList != NULL)
    246245    {
    247       std::list<BaseObject*>::const_iterator bo;
     246      ObjectListBase::base_list list;
     247      objectList->getBaseObjectList(&list);
     248      ObjectListBase::base_iterator it;
    248249
    249250      // No Description given (only for speedup)
    250251      if (objectDescriptor.empty())
    251252      {
    252         for (bo = objectList->begin(); bo != objectList->end(); bo++)
    253           boList->push_back(*bo);
     253        for (it = list.begin(); it != list.end(); it++)
     254          boList->push_back(*it);
    254255      }
    255256      // some description
    256257      else
    257258      {
    258         for (bo = objectList->begin(); bo != objectList->end(); bo++)
    259           if (!nocaseCmp(objectDescriptor, (*bo)->getName(), objectDescriptor.size()))
    260             boList->push_back(*bo);
     259        for (it = list.begin(); it != list.end(); it++)
     260          if (!nocaseCmp(objectDescriptor, (*it)->getName(), objectDescriptor.size()))
     261            boList->push_back(*it);
    261262      }
    262263    }
     
    299300    if (sc != NULL)
    300301    {
    301       for(std::vector<BaseObject*>::const_iterator bo = boList.begin(); bo != boList.end(); ++bo)
    302       {
    303         PRINT(0)("Command '%s' on '%s::%s'\n", sc->getCName(), (*bo)->getClassCName(), (*bo)->getCName());
    304         (*sc->executor)((*bo), inputSplits.subSet(paramBegin));
    305       }
     302
     303      if(sc->executor->getType() == Executor<const SubString>::FunctionStatic )
     304      {
     305        PRINT(0)("Static Command '%s' of Class '%s' with parameters\n", sc->getCName(), sc->shellClass->getCName());
     306        (*sc->executor)(NULL, inputSplits.subSet(paramBegin));
     307      }
     308      else
     309        for(std::vector<BaseObject*>::const_iterator bo = boList.begin(); bo != boList.end(); ++bo)
     310        {
     311          PRINT(0)("Command '%s' on '%s::%s'\n", sc->getCName(), (*bo)->getClassCName(), (*bo)->getCName());
     312          (*sc->executor)((*bo), inputSplits.subSet(paramBegin));
     313        }
    306314      return true;
    307315    }
     
    376384    else
    377385    {
    378 //       if(this->completors[parameter] == NULL)
    379 //       delete this->completors[parameter];
    380 //       this->completors[parameter] = completorPlugin.clone();
     386      //       if(this->completors[parameter] == NULL)
     387      //       delete this->completors[parameter];
     388      //       this->completors[parameter] = completorPlugin.clone();
    381389    }
    382390    return this;
  • trunk/src/lib/shell/shell_command.h

    r8145 r9869  
    99#include "base_object.h"
    1010
    11 #include "executor/executor.h"
     11/// THIS IS USED TO LOAD CONSTANT AND STATIC FUNCTIONS EASILY.
     12#include "executor/executor_substring.h"
     13#include "executor/functor_member.h"
     14#include "executor/functor_const_member.h"
     15#include "executor/functor_static.h"
     16
    1217#include "shell_completion_plugin.h"
    1318
     
    3540   */
    3641#define SHELL_COMMAND(command, class, function) \
    37            OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class>(&class::function))
     42           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class, BaseObject>(&class::function))
    3843
    3944  /**
     
    5156   */
    5257#define SHELL_COMMAND_STATIC(command, class, function) \
    53            OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class>(function))
     58           OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class, BaseObject>(function))
    5459
    5560
     
    5863  class ShellCommand : public BaseObject
    5964  {
     65    ObjectListDeclaration(ShellCommand);
     66
    6067    friend class ShellCommandClass;
    6168  public:
     
    6976    ShellCommand* completionPlugin(unsigned int parameter, const CompletorPlugin& completorPlugin);
    7077
    71     static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, Executor* executor);
     78    static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor);
    7279    static void unregisterCommand(const std::string& commandName, const std::string& className);
    7380    static const ShellCommand* const getCommand(const std::string& commandName, const std::string& className);
     
    8592
    8693  protected:
    87     ShellCommand(const std::string& commandName, const std::string& className, Executor* executor);
     94    ShellCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor);
    8895    virtual ~ShellCommand();
    8996
     
    97104    std::string                      description;           //!< A description for this commnand. (initially ""). Assigned with (create)->describe("blablabla");
    98105    std::vector<CompletorPlugin*>    completors;            //!< Completors for the Parameters
    99     Executor*                        executor;              //!< The Executor, that really executes the Function.
     106    Executor<const SubString>*       executor;              //!< The Executor, that really executes the Function.
    100107  };
    101108
  • trunk/src/lib/shell/shell_command_class.cc

    r9406 r9869  
    2121
    2222#include "debug.h"
    23 #include "class_list.h"
    2423#include "compiler.h"
    2524
     
    2827namespace OrxShell
    2928{
    30   CmdClassList* ShellCommandClass::commandClassList = NULL;
     29  ObjectListDefinition(ShellCommandClass);
     30
     31  CmdClassList* ShellCommandClass::_commandClassList = NULL;
    3132
    3233  /**
     
    3536   */
    3637  ShellCommandClass::ShellCommandClass(const std::string& className)
    37       : className(className)
    38   {
    39     this->setClassID(CL_SHELL_COMMAND_CLASS, "ShellCommandClass");
     38      : _className(className)
     39  {
     40    this->registerObject(this, ShellCommandClass::_objectList);
    4041    this->setName(className);
    4142
    42     this->classID = CL_NULL;
    43 
    44     if (ShellCommandClass::commandClassList == NULL)
    45       ShellCommandClass::commandClassList = new CmdClassList;
    46     ShellCommandClass::commandClassList->push_back(this);
     43    if (ShellCommandClass::_commandClassList == NULL)
     44      ShellCommandClass::_commandClassList = new CmdClassList;
     45    ShellCommandClass::_commandClassList->push_back(this);
    4746  }
    4847
     
    5251  ShellCommandClass::~ShellCommandClass()
    5352  {
    54     while(!this->commandList.empty())
    55       delete this->commandList.back();
    56 
    57     if (ShellCommandClass::commandClassList != NULL)
    58     {
    59       CmdClassList::iterator delClass = std::find(ShellCommandClass::commandClassList->begin(), ShellCommandClass::commandClassList->end(), this);
    60       if (delClass != ShellCommandClass::commandClassList->end())
    61         ShellCommandClass::commandClassList->erase(delClass);
     53    while(!this->_commandList.empty())
     54      delete this->_commandList.back();
     55
     56    if (ShellCommandClass::_commandClassList != NULL)
     57    {
     58      CmdClassList::iterator delClass = std::find(ShellCommandClass::_commandClassList->begin(), ShellCommandClass::_commandClassList->end(), this);
     59      if (delClass != ShellCommandClass::_commandClassList->end())
     60        ShellCommandClass::_commandClassList->erase(delClass);
    6261    }
    6362  }
     
    6867  void ShellCommandClass::registerCommand(ShellCommand* command)
    6968  {
    70     this->commandList.push_back(command);
     69    this->_commandList.push_back(command);
    7170  }
    7271
     
    7776  void ShellCommandClass::unregisterCommand(ShellCommand* command)
    7877  {
    79     CmdList::iterator delC = std::find(this->commandList.begin(), this->commandList.end(), command);
    80     if (delC != this->commandList.end())
    81       this->commandList.erase(delC);
     78    CmdList::iterator delC = std::find(this->_commandList.begin(), this->_commandList.end(), command);
     79    if (delC != this->_commandList.end())
     80      this->_commandList.erase(delC);
    8281  }
    8382
     
    8988    // unregister all commands and Classes
    9089    CmdClassList::iterator classIT;
    91     if (ShellCommandClass::commandClassList == NULL)
     90    if (ShellCommandClass::_commandClassList == NULL)
    9291      return;
    9392
    94     while (!ShellCommandClass::commandClassList->empty())
    95       delete ShellCommandClass::commandClassList->back();
    96     delete ShellCommandClass::commandClassList;
    97     ShellCommandClass::commandClassList = NULL;
     93    while (!ShellCommandClass::_commandClassList->empty())
     94      delete ShellCommandClass::_commandClassList->back();
     95    delete ShellCommandClass::_commandClassList;
     96    ShellCommandClass::_commandClassList = NULL;
    9897  }
    9998
     
    107106  bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>& stringList)
    108107  {
    109     if (ShellCommandClass::commandClassList == NULL)
     108    if (ShellCommandClass::_commandClassList == NULL)
    110109      return false;
    111110
    112111
    113112    CmdClassList::const_iterator elem;
    114     for(elem = ShellCommandClass::commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++)
     113    for(elem = ShellCommandClass::_commandClassList->begin(); elem != ShellCommandClass::_commandClassList->end(); elem++)
    115114    {
    116115      if (className == (*elem)->getName())
    117116      {
    118117        CmdList::iterator command;
    119         for(command = (*elem)->commandList.begin(); command != (*elem)->commandList.end(); command++)
     118        for(command = (*elem)->_commandList.begin(); command != (*elem)->_commandList.end(); command++)
    120119          stringList.push_back((*command)->getName());
    121120        return true;
     
    133132  ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className)
    134133  {
    135     if (ShellCommandClass::commandClassList == NULL)
     134    if (ShellCommandClass::_commandClassList == NULL)
    136135      return false;
    137136
    138137
    139138    CmdClassList::const_iterator classIT;
    140     for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    141       if (className == (*classIT)->className)
     139    for (classIT = ShellCommandClass::_commandClassList->begin(); classIT != ShellCommandClass::_commandClassList->end(); classIT++)
     140      if (className == (*classIT)->_className)
    142141        return (*classIT);
    143142    return NULL;
     
    152151  {
    153152    return (ShellCommandClass::getCommandClass(className) != NULL);
    154   }
    155 
    156   ClassID ShellCommandClass::getClassID()
    157   {
    158     if (this->classID == CL_NULL)
    159       this->classID = ClassList::StringToID(this->className);
    160     return this->classID;
    161153  }
    162154
     
    181173  void ShellCommandClass::help(const std::string& className)
    182174  {
    183     if (ShellCommandClass::commandClassList == NULL)
     175    if (ShellCommandClass::_commandClassList == NULL)
    184176    {
    185177      PRINT(0)("No Commands Registered\n");
     
    187179    }
    188180    if (className.empty())
    189       PRINT(0)("===== Displaying %d registered Classes:\n", ShellCommandClass::commandClassList->size());
     181      PRINT(0)("===== Displaying %d registered Classes:\n", ShellCommandClass::_commandClassList->size());
    190182
    191183
    192184    CmdClassList::iterator classIT;
    193     for (classIT = ShellCommandClass::commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)
    194     {
    195       if (className.empty() || className == (*classIT)->className)
     185    for (classIT = ShellCommandClass::_commandClassList->begin(); classIT != ShellCommandClass::_commandClassList->end(); classIT++)
     186    {
     187      if (className.empty() || className == (*classIT)->_className)
    196188      {
    197         PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->className.c_str(), (*classIT)->commandList.size());
     189        PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->_className.c_str(), (*classIT)->_commandList.size());
    198190        CmdList::const_iterator cmdIT;
    199         for (cmdIT = (*classIT)->commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)
     191        for (cmdIT = (*classIT)->_commandList.begin(); cmdIT != (*classIT)->_commandList.end(); cmdIT++)
    200192        {
    201193          PRINT(0)("  command:'%s' : params:%d: ", (*cmdIT)->getCName(), (*cmdIT)->executor->getParamCount());
  • trunk/src/lib/shell/shell_command_class.h

    r8362 r9869  
    2525  class ShellCommandClass : public BaseObject
    2626  {
     27    ObjectListDeclaration(ShellCommandClass);
     28
    2729    friend class ShellCommand;
    2830  public:
    2931    /** @returns the CommandClassList */
    30     static const CmdClassList& getCommandClassList() { return *ShellCommandClass::commandClassList; };
     32    static const CmdClassList& getCommandClassList() { return *ShellCommandClass::_commandClassList; };
    3133
    3234    static bool getCommandListOfClass(const std::string& className, std::list<std::string>& stringList);
     
    5153
    5254  private:
    53     const std::string                      className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
    54     ClassID                                classID;                   //!< The classID of this Class
    55     CmdList                                commandList;               //!< A list of Commands from this Class
     55    const std::string                      _className;                 //!< The Name of the Class. This should match the ClassName of the Commands Class.
     56    CmdList                                _commandList;               //!< A list of Commands from this Class
    5657
    57     static CmdClassList*                   commandClassList;          //!< A list of Classes
     58    static CmdClassList*                   _commandClassList;          //!< A list of Classes
    5859  };
    5960}
  • trunk/src/lib/shell/shell_completion.cc

    r9406 r9869  
    2222#include "shell_command.h"
    2323
    24 #include "substring.h"
    25 #include "class_list.h"
     24#include "helper_functions.h"
    2625#include "debug.h"
    2726
     
    5150  bool ShellCompletion::autoComplete(std::string& input)
    5251  {
    53     long classID = CL_NULL;                          //< the classID retrieved from the Class.
    54     const std::list<BaseObject*>* objectList = NULL; //< the list of Objects stored in classID's ClassList
     52    ClassID classID;
     53    const ObjectListBase* objectList = NULL;      //< the list of Objects stored in classID's ClassList
    5554    bool emptyComplete = false;                      //< if the completion input is empty string. e.g ""
    5655    long completeType = NullCompletion;              //< the Type we'd like to complete.
     
    8584             (!emptyComplete && inputSplits.size() == 2))
    8685    {
    87       classID = ClassList::StringToID(inputSplits.getString(0));
    88       objectList = ClassList::getList((ClassID)classID);
    89       if (classID != CL_NULL)
     86      objectList = ObjectListBase::getObjectList(inputSplits[0]);
     87      if (objectList != NULL)
     88        classID = objectList->identity();
     89      if (classID != NullClass::staticClassID())
    9090        completeType |= ObjectCompletion;
    9191      completeType |= FunctionCompletion;
     
    9595             (!emptyComplete && inputSplits.size() == 3))
    9696    {
    97       if (ClassList::exists(inputSplits[0], inputSplits[1]))
     97      if (ObjectListBase::getBaseObject(inputSplits[0], inputSplits[1]))
    9898        completeType |= FunctionCompletion;
    9999    }
     
    113113
    114114    if (completeType & ClassCompletion)
    115       this->objectComplete(completeString, CL_SHELL_COMMAND_CLASS);
     115      this->objectComplete(completeString, &ShellCommandClass::objectList());
    116116    if (completeType & ObjectCompletion)
    117       this->objectComplete(completeString, classID);
     117      this->objectComplete(completeString, objectList);
    118118    if (completeType & FunctionCompletion)
    119119      this->commandComplete(completeString, inputSplits[0]);
     
    133133   * @return true on success, false otherwise
    134134   */
    135   bool ShellCompletion::objectComplete(const std::string& objectBegin, long classID)
    136   {
    137     const std::list<BaseObject*>* boList = ClassList::getList((ClassID)classID);
    138     if (boList != NULL)
    139     {
    140       CompletionType type = ObjectCompletion;
    141       if (classID == CL_SHELL_COMMAND_CLASS)
    142         type = ClassCompletion;
    143       if (!this->addToCompleteList(*boList, objectBegin, type))
    144         return false;
    145     }
    146     else
    147       return false;
     135  bool ShellCompletion::objectComplete(const std::string& objectBegin, const ObjectListBase* objectList)
     136  {
     137    assert (objectList != NULL);
     138
     139    CompletionType type = ObjectCompletion;
     140    if (objectList == &ShellCommandClass::objectList())
     141      type = ClassCompletion;
     142
     143    ObjectListBase::base_list list;
     144    objectList->getBaseObjectList(&list);
     145
     146    if (!this->addToCompleteList(list, objectBegin, type))
     147     return false;
     148
    148149    return true;
    149150  }
     
    321322    switch (type)
    322323    {
    323         default:// SHELLC_NONE
    324         return typeNames[0];
    325         case  ClassCompletion:
    326         return typeNames[1];
    327         case ObjectCompletion:
    328         return typeNames[2];
    329         case FunctionCompletion:
    330         return typeNames[3];
    331         case AliasCompletion:
    332         return typeNames[4];
    333         case ParamCompletion:
    334         return typeNames[5];
     324      default:// SHELLC_NONE
     325      return typeNames[0];
     326      case  ClassCompletion:
     327      return typeNames[1];
     328      case ObjectCompletion:
     329      return typeNames[2];
     330      case FunctionCompletion:
     331      return typeNames[3];
     332      case AliasCompletion:
     333      return typeNames[4];
     334      case ParamCompletion:
     335      return typeNames[5];
    335336    }
    336337  }
  • trunk/src/lib/shell/shell_completion.h

    r7415 r9869  
    1616// FORWARD DECLARATION
    1717class BaseObject;
     18class ObjectListBase;
    1819
    1920namespace OrxShell
     
    5051      bool autoComplete(std::string& input);
    5152
    52       static const std::string& ShellCompletion::typeToString(ShellCompletion::CompletionType type);
     53      static const std::string& typeToString(ShellCompletion::CompletionType type);
    5354
    5455    private:
    55       bool objectComplete(const std::string& objectBegin, long classID);
     56      bool objectComplete(const std::string& objectBegin, const ObjectListBase* const objectList);
    5657      bool commandComplete(const std::string& commandBegin, const std::string& className);
    5758      bool aliasComplete(const std::string& aliasBegin);
  • trunk/src/lib/shell/shell_completion_plugin.cc

    r8330 r9869  
    2121#include "shell_command.h"
    2222
    23 #include "substring.h"
    24 #include "class_list.h"
     23#include "helper_functions.h"
    2524#include "loading/resource_manager.h"
    2625
     
    9897    if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir.
    9998    {
    100       dir.setFileName(ResourceManager::getInstance()->getDataDir() + this->_subDir);
     99      dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + this->_subDir);
    101100      dir.open();
    102101      for(unsigned int i = 0; i < dir.fileCount(); i++ )
     
    113112        directoryName = completionBegin.substr(0, pos);
    114113
    115       dir.setFileName(ResourceManager::getInstance()->getDataDir() + directoryName);
     114      dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + directoryName);
    116115      dir.open();
    117116
     
    136135          continue;
    137136        }
    138         printf("%s\n", (ResourceManager::getInstance()->getDataDir() + fileName).c_str());
     137        printf("%s\n", (Resources::ResourceManager::getInstance()->mainGlobalPath().name() + fileName).c_str());
    139138        if (!nocaseCmp(completionBegin, fileName, completionBegin.size()) &&
    140              ResourceManager::isInDataDir(fileName))
     139             Resources::ResourceManager::getInstance()->checkFileInMainPath(fileName))
    141140        {
    142141          printf("Dir %s\n", fileName.c_str());
  • trunk/src/lib/shell/shell_input.cc

    r8339 r9869  
    2424#include "compiler.h"
    2525#include "key_names.h"
     26
    2627
    2728namespace OrxShell
     
    3132  ->setAlias("help");
    3233
     34  ObjectListDefinition(ShellInput);
    3335
    3436  /**
     
    3941      : Text ("")
    4042  {
     43    this->registerObject(this, ShellInput::_objectList);
     44
    4145    this->pressedKey = SDLK_FIRST;
    42     this->setClassID(CL_SHELL_INPUT, "ShellInput");
    43 
    44     this->inputLine = "";
     46
    4547    this->historyIT = ShellInput::history.begin();
    4648    this->setHistoryLength(50);
     
    5355    {
    5456      //if (!this->isEventSubscribed(ES_SHELL, i))
    55         this->subscribeEvent(ES_SHELL, i);
     57      this->subscribeEvent(ES_SHELL, i);
    5658    }
    5759    // unsubscribe unused TODO improve.
     
    6062    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEUP);
    6163    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEDOWN);
    62 
    6364  }
    6465
     
    8788  void ShellInput::flush()
    8889  {
    89     this->inputLine.clear();
    90     this->setText(this->inputLine);
     90    this->inputLineBegin.clear();
     91    this->inputLineEnd.clear();
     92    this->clear();
    9193  }
    9294
     
    9799  void ShellInput::setInputText(const std::string& text)
    98100  {
    99     this->inputLine = text;
    100     this->setText(this->inputLine);
     101    this->inputLineBegin = text;
     102    this->inputLineEnd.clear();
     103    this->setText(text);
    101104  }
    102105
     
    114117    }
    115118
    116     this->inputLine += character;
    117     this->setText(this->inputLine);
     119    this->inputLineBegin += character;
     120    this->setText(this->inputLineBegin + this->inputLineEnd);
    118121  }
    119122
     
    130133    }
    131134
    132     this->inputLine += characters;
    133     this->setText(this->inputLine);
     135    this->inputLineBegin += characters;
     136    this->setText(this->inputLineBegin + this->inputLineEnd);
    134137  }
    135138
     
    145148      this->historyScrolling = false;
    146149    }
    147     if (this->inputLine.size() < characterCount)
    148       characterCount = this->inputLine.size();
    149 
    150     this->inputLine.erase(this->inputLine.size() - characterCount, this->inputLine.size());
    151     this->setText(this->inputLine);
     150    if (this->inputLineBegin.size() < characterCount)
     151      characterCount = this->inputLineBegin.size();
     152
     153    this->inputLineBegin.erase(this->inputLineBegin.size() - characterCount, this->inputLineBegin.size());
     154    this->setText(this->inputLineBegin + this->inputLineEnd);
    152155  }
    153156
     
    158161  bool ShellInput::executeCommand()
    159162  {
    160     ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str());
    161 
    162     if (this->inputLine.empty())
     163    if (this->getInput().empty())
    163164      return false;
    164 
    165     ShellCommand::execute(this->inputLine);
     165    DebugBuffer::addBufferLineStatic("Execute Command: %s\n", this->getInput().c_str());
     166
     167    ShellCommand::execute(this->getInput());
    166168
    167169    // removing the eventually added Entry (from scrolling) to the List
     
    173175
    174176    // adding the new Command to the History
    175     if (history.empty() || history.back() != this->inputLine)
    176       this->history.push_back(this->inputLine);
     177    if (history.empty() || history.back() != this->getInput())
     178      this->history.push_back(this->getInput());
    177179    if (this->history.size() > this->historyLength)
    178180    {
     
    193195    if (!this->historyScrolling)
    194196    {
    195       this->history.push_back(this->inputLine);
     197      this->history.push_back(this->getInput());
    196198      this->historyScrolling = true;
    197199      this->historyIT = --this->history.end();
     
    231233  }
    232234
     235  /**
     236   * @brief moves the cursor chars Characters to the right.
     237   * @param chars how much to move the cursor.
     238   */
     239  void ShellInput::moveCursor(int chars)
     240  {
     241    if (chars > 0)
     242    {
     243      PRINTF(5)("move cursor %d to the right\n", chars);
     244      if (chars >= (int) this->inputLineEnd.size())
     245        chars = inputLineEnd.size();
     246      this->inputLineBegin += this->inputLineEnd.substr(0, chars);
     247      this->inputLineEnd.erase(0, chars);
     248    }
     249    else if (chars < 0)
     250    {
     251      chars = -chars;
     252      PRINTF(5)("move cursor %d to the left\n", chars);
     253
     254      if (chars >= (int) this->inputLineBegin.size())
     255        chars = inputLineBegin.size();
     256      this->inputLineEnd = this->inputLineBegin.substr(this->inputLineBegin.size() - chars) + this->inputLineEnd;
     257      this->inputLineBegin.erase(this->inputLineBegin.size() - chars);
     258    }
     259  }
     260
    233261
    234262  /**
     
    237265  void ShellInput::help(const std::string& className, const std::string& functionName)
    238266  {
    239     printf("%s::%s\n", className.c_str(), functionName.c_str());
    240 
    241267    if (className.empty())
    242268    {
    243       PRINT(0)("Help for the most important Shell-commands\n");
    244       PRINT(0)("F1 - HELP; F2 - DEBUG; '`' - open/close shell\n");
    245       PRINT(0)("input order:\n");
    246       PRINT(0)("ClassName [objectName] function [parameter1, [parameter2 ...]]  or\n");
    247       PRINT(0)("Alias [parameter]\n");
    248       PRINT(0)("- Also try 'help className'");
     269      PRINT(0)("== Help for the most important Shell-commands\n");
     270      PRINT(0)("  F1 - HELP; F2 - DEBUG; '`' - open/close shell\n");
     271      PRINT(0)("  input order:\n");
     272      PRINT(0)("   ClassName [objectName] function [parameter1, [parameter2 ...]]  or\n");
     273      PRINT(0)("   Alias [parameter]\n");
     274      PRINT(0)("- Also try 'help className' or pushing 'TAB'\n");
    249275    }
    250276    else if (!className.empty() && functionName.empty())
     
    269295      {
    270296        case SDLK_BACKSPACE:
    271           this->removeCharacters(1);
    272           break;
     297        this->removeCharacters(1);
     298        break;
    273299        case SDLK_UP:
    274           this->historyMoveUp();
    275           break;
     300        this->historyMoveUp();
     301        break;
    276302        case SDLK_DOWN:
    277           this->historyMoveDown();
    278           break;
     303        this->historyMoveDown();
     304        break;
    279305        default:
    280           {
    281             if (likely(pressedKey < 127))
    282               this->addCharacter(this->pressedKey);
    283           }
     306        {
     307          if (likely(pressedKey < 127))
     308            this->addCharacter(this->pressedKey);
     309        }
    284310      }
    285311    }
     
    313339        this->pressedEvent = event.type;
    314340      }
     341      else if (event.type == SDLK_LEFT)
     342      {
     343        this->moveCursor(-1);
     344        this->pressedKey = event.type;
     345        this->pressedEvent = event.type;
     346      }
     347      else if (event.type == SDLK_RIGHT)
     348      {
     349        this->moveCursor(+1);
     350        this->pressedKey = event.type;
     351        this->pressedEvent = event.type;
     352      }
    315353      else if (event.type == SDLK_TAB)
    316354      {
    317         this->completion.autoComplete(this->inputLine);
    318         this->setText(this->inputLine);
     355        this->completion.autoComplete(this->inputLineBegin);
     356        this->setText(this->getInput());
    319357      }
    320358      else if (event.type == SDLK_BACKSPACE)
     
    325363        this->removeCharacters(1);
    326364      }
     365      else if (event.type == SDLK_DELETE)
     366      {
     367        if (!this->inputLineEnd.empty())
     368        {
     369          this->inputLineEnd.erase(0, 1);
     370          this->setText(this->getInput());
     371        }
     372      }
    327373      else if (event.type == SDLK_RETURN)
    328374      {
  • trunk/src/lib/shell/shell_input.h

    r7858 r9869  
    3030  class ShellInput : public Text,  public EventListener
    3131  {
     32    ObjectListDeclaration(ShellInput);
    3233
    3334  public:
     
    3637
    3738    /** @returns the inputLine */
    38     const std::string& getInput() const { return this->inputLine; };
     39    std::string getInput() const { return this->inputLineBegin + this->inputLineEnd; };
    3940
    4041    // InputLine
     
    5455    void historyMoveDown();
    5556
     57    void moveCursor(int chars);
     58
    5659    void help(const std::string& className = "", const std::string& function = "");
    5760
     
    6366    ShellCompletion                   completion;       //!< The Completion Interface.
    6467
    65     std::string                       inputLine;        //!< the Char-Array of the Buffer
     68    std::string                       inputLineBegin;   //!< The Line up to the cursor.
     69    std::string                       inputLineEnd;     //!< The Line from the cursor on
     70
    6671    float                             repeatRate;       //!< The Repeat-Delay.
    6772    float                             repeatDelay;      //!< The delay of the first Character of a given Character.
  • trunk/src/lib/shell/some_shell_commands.cc

    r8623 r9869  
    2929
    3030#include "network_game_rules.h"
    31   SHELL_COMMAND(say, NetworkGameRules, shellSay)->setAlias("say");
     31SHELL_COMMAND(say, NetworkGameRules, shellSay)->setAlias("say");
    3232
    3333#include "player_stats.h"
    34   SHELL_COMMAND(nick, PlayerStats, shellNick)->setAlias("nick");
     34SHELL_COMMAND(nick, PlayerStats, shellNick)->setAlias("nick");
    3535
    36 #include "class_list.h"
    37   SHELL_COMMAND(debug, ClassList, ClassList::debugS)
    38       ->describe("Shows all registered classes, if param1: is a valid ClassName only values of this class are shown. param2: how much output")
    39       ->defaultValues(MT_NULL, 1);
     36// #include "class_list.h"
     37//   SHELL_COMMAND(debug, ClassList, ClassList::debugS)
     38//       ->describe("Shows all registered classes, if param1: is a valid ClassName only values of this class are shown. param2: how much output")
     39//       ->defaultValues(MT_NULL, 1);
    4040
    4141#include "p_node.h"
    42   SHELL_COMMAND(debugNode, PNode, debugNode);
    43   SHELL_COMMAND(setPosition, PNode, setAbsCoor);
     42SHELL_COMMAND(debugNode, PNode, debugNode);
     43SHELL_COMMAND(setPosition, PNode, setAbsCoor);
    4444
    4545#include "render_2d.h"
    46   SHELL_COMMAND(toggleNodeVisibility, Render2D, toggleNodesVisibility);
     46SHELL_COMMAND(toggleNodeVisibility, Render2D, toggleNodesVisibility);
    4747
    4848
    4949#include "material.h"
    50   SHELL_COMMAND(setDiffuseTexture, Material, setDiffuseMap)
    51       ->defaultValues(MT_NULL, (int)GL_TEXTURE_2D)
    52       ->completionPlugin(0, CompletorFileSystem());
     50SHELL_COMMAND(setDiffuseTexture, Material, setDiffuseMap)
     51->defaultValues(MT_NULL, (int)GL_TEXTURE_2D)
     52->completionPlugin(0, CompletorFileSystem());
    5353
     54#include "loading/resource_manager.h"
     55namespace Resources {
     56  SHELL_COMMAND(debug, ResourceManager, debug);
     57  SHELL_COMMAND(load, ResourceManager, loadFromLoadStringHACK);
     58  SHELL_COMMAND(unload, ResourceManager, unloadAllBelowKeepLevelINT);
     59}
     60
     61#include "loading/load_param_class_description.h"
     62SHELL_COMMAND_STATIC(printAll, LoadParamClassDescription, &LoadParamClassDescription::printAll)
     63->defaultValues(MT_NULL, true);
     64SHELL_COMMAND_STATIC(capture, LoadParamClassDescription, &LoadParamClassDescription::captureDescriptions)
     65    ->defaultValues(true);
     66
     67#include "loading/game_loader.h"
     68SHELL_COMMAND(quit, GameLoader, stop)
     69    ->describe("quits the game")
     70    ->setAlias("orxoquit");
     71
     72#include "object_list.h"
     73SHELL_COMMAND_STATIC(debugAll, ObjectListBase, &ObjectListBase::debugAll);
Note: See TracChangeset for help on using the changeset viewer.