Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7417 in orxonox.OLD for trunk


Ignore:
Timestamp:
Apr 28, 2006, 11:11:57 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ShellCommand with new Improved and more general Functionality

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

Legend:

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

    r7415 r7417  
    141141   * @returns: The ShellCommand if found.
    142142   */
    143   const ShellCommand* const ShellCommand::getCommandFromInput(const std::string& inputLine, unsigned int& paramBegin)
     143  const ShellCommand* const ShellCommand::getCommandFromInput(const std::string& inputLine, unsigned int& paramBegin, std::vector<BaseObject*>* boList)
    144144  {
    145145    ShellCommand::getCommandFromInput(SubString(inputLine, SubString::WhiteSpaces), paramBegin);
     
    152152   * @returns: The ShellCommand if found.
    153153   */
    154   const ShellCommand* const ShellCommand::getCommandFromInput(const SubString& strings, unsigned int& paramBegin)
     154  const ShellCommand* const ShellCommand::getCommandFromInput(const SubString& strings, unsigned int& paramBegin, std::vector<BaseObject*>* boList)
    155155  {
    156156    // no input, no Command.
     
    172172    }
    173173
     174    // CHECK FOR COMMAND_CLASS
    174175    const ShellCommandClass* cmdClass = ShellCommandClass::getCommandClass(strings[0]);
    175176    if (cmdClass != NULL)
    176177    {
    177178      const ShellCommand* retCmd;
     179      // Function/Command right after Class
    178180      if (strings.size() >= 1)
    179181      {
    180182        retCmd = ShellCommand::getCommand(strings[1], cmdClass);
    181         paramBegin = 2;
    182       }
     183        if (retCmd != NULL)
     184        {
     185          paramBegin = 2;
     186          return retCmd;
     187        }
     188      }
     189      // Function/Command after Class and 'Object'
    183190      if (retCmd == NULL && strings.size() >= 2)
    184191      {
    185192        retCmd = ShellCommand::getCommand(strings[2], cmdClass);
     193        if (retCmd != NULL)
     194        {
    186195          paramBegin = 3;
     196          return retCmd;
     197        }
    187198      }
    188199      if (retCmd != NULL) // check for the paramBegin.
    189200        return retCmd;
    190201    }
     202    // Nothing usefull found at all.
    191203    paramBegin = 0;
    192204    return NULL;
    193205  }
    194206
     207  bool ShellCommand::fillObjectList(const std::string& objectDescriptor, ShellCommand* cmd, std::vector<BaseObject*>* boList)
     208  {
     209    assert (cmd != NULL && cmd->shellClass != NULL && boList != NULL);
     210
     211    const std::list<BaseObject*>* objectList = ClassList::getList(cmd->shellClass->getName());
     212    if (objectList != NULL)
     213    {
     214      std::list<BaseObject*>::const_iterator bo;
     215
     216      // No Description given (only for speedup)
     217      if (objectDescriptor.empty())
     218      {
     219        for (bo = objectList->begin(); bo != objectList->end(); bo++)
     220          boList->push_back(*bo);
     221      }
     222      // some description
     223      else
     224      {
     225        for (bo = objectList->begin(); bo != objectList->end(); bo++)
     226          if ((*bo)->getName() != NULL && nocaseCmp(objectDescriptor, (*bo)->getName(), objectDescriptor.size()))
     227            boList->push_back(*bo);
     228      }
     229    }
     230  }
    195231
    196232  /**
  • trunk/src/lib/shell/shell_command.h

    r7414 r7417  
    7676    static const ShellCommand* const getCommand(const std::string& commandName, const ShellCommandClass* cmdClass);
    7777    static bool exists(const std::string& commandName, const std::string& className);
    78     static const ShellCommand* const getCommandFromInput(const std::string& inputLine, unsigned int& paramBegin);
    79     static const ShellCommand* const getCommandFromInput(const SubString& strings, unsigned int& paramBegin);
     78    static const ShellCommand* const getCommandFromInput(const std::string& inputLine, unsigned int& paramBegin, std::vector<BaseObject*>* boList = NULL);
     79    static const ShellCommand* const getCommandFromInput(const SubString& strings, unsigned int& paramBegin, std::vector<BaseObject*>* boList = NULL);
    8080
    8181    const ShellCommandClass* const getCommandClass() const { return this->shellClass; };
     
    9090    virtual ~ShellCommand();
    9191
     92    static bool fillObjectList(const std::string& objectDescriptor, ShellCommand* cmd, std::vector<BaseObject*>* boList);
    9293    static const std::string& paramToString(long parameter);
    9394
Note: See TracChangeset for help on using the changeset viewer.