Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7372 in orxonox.OLD


Ignore:
Timestamp:
Apr 26, 2006, 2:23:53 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: Typenames as std::string better now

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

Legend:

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

    r7371 r7372  
    5858  const std::list<BaseObject*>* objectList;   //< the list of Objects stored in classID
    5959  bool emptyComplete = false;           //< if the completion input is empty string. e.g ""
    60   long completeType = SHELLC_NONE;      //< the Type we'd like to complete.
     60  long completeType = NullCompletion;   //< the Type we'd like to complete.
    6161  std::string completeString;           //< the string to complete.
    6262
     
    8181  if (inputSplits.size() == 0)
    8282  {
    83     completeType |= SHELLC_CLASS;
    84     completeType |= SHELLC_ALIAS;
     83    completeType |= ClassCompletion;
     84    completeType |= AliasCompletion;
    8585  }
    8686  else if (inputSplits.size() == 1 && emptyComplete == false)
    8787  {
    88     completeType |= SHELLC_CLASS;
    89     completeType |= SHELLC_ALIAS;
     88    completeType |= ClassCompletion;
     89    completeType |= AliasCompletion;
    9090  }
    9191
     
    9797    objectList = ClassList::getList((ClassID)classID);
    9898    if (classID != CL_NULL)
    99       completeType |= SHELLC_OBJECT;
     99      completeType |= ObjectCompletion;
    100100    //if (objectList != NULL && objectList->getSize() == 1)
    101       completeType |= SHELLC_FUNCTION;
     101      completeType |= FunctionCompletion;
    102102  }
    103103  else if ((inputSplits.size() == 2 && emptyComplete == true) ||
     
    108108      return false;
    109109    else
    110      completeType |= SHELLC_FUNCTION;
    111   }
    112 
    113   if (completeType & SHELLC_CLASS)
     110     completeType |= FunctionCompletion;
     111  }
     112
     113  if (completeType & ClassCompletion)
    114114    this->objectComplete(completeString, CL_SHELL_COMMAND_CLASS);
    115   if (completeType & SHELLC_OBJECT)
     115  if (completeType & ObjectCompletion)
    116116    this->objectComplete(completeString, classID);
    117   if (completeType & SHELLC_FUNCTION)
     117  if (completeType & FunctionCompletion)
    118118    this->functionComplete(completeString, inputSplits.getString(0));
    119   if (completeType & SHELLC_ALIAS)
     119  if (completeType & AliasCompletion)
    120120    this->aliasComplete(completeString);
    121121
     
    135135  if (clList != NULL)
    136136  {
    137     if (!this->addToCompleteList(*clList, classBegin, SHELLC_CLASS))
     137    if (!this->addToCompleteList(*clList, classBegin, ClassCompletion))
    138138      return false;
    139139  }
     
    154154  if (boList != NULL)
    155155  {
    156     SHELLC_TYPE type = SHELLC_OBJECT;
     156    CompletionType type = ObjectCompletion;
    157157    if (classID == CL_SHELL_COMMAND_CLASS)
    158       type = SHELLC_CLASS;
     158      type = ClassCompletion;
    159159    if (!this->addToCompleteList(*boList, objectBegin, type))
    160160      return false;
     
    175175  ShellCommandClass::getCommandListOfClass(className, &fktList);
    176176  //printf("%s\n", boList->firstElement()->getName());
    177   if (!this->addToCompleteList(fktList, functionBegin, SHELLC_FUNCTION))
     177  if (!this->addToCompleteList(fktList, functionBegin, FunctionCompletion))
    178178    return false;
    179179  return true;
     
    190190  ShellCommandClass::getCommandListOfAlias(&aliasList);
    191191  //printf("%s\n", boList->firstElement()->getName());
    192   if (!this->addToCompleteList(aliasList, aliasBegin, SHELLC_ALIAS))
     192  if (!this->addToCompleteList(aliasList, aliasBegin, AliasCompletion))
    193193    return false;
    194194  return true;
     
    212212    return false;
    213213
    214   ShellC_Element addElem = completionList.front();
     214  CompletionElement addElem = completionList.front();
    215215  const std::string& addString = addElem.name;
    216216  unsigned int addLength = 0;
     
    220220  addLength = addString.size();
    221221
    222   SHELLC_TYPE changeType = SHELLC_NONE;
    223   list<ShellC_Element>::iterator charIT;
     222  CompletionType changeType = NullCompletion;
     223  list<CompletionElement>::iterator charIT;
    224224  for (charIT = completionList.begin(); charIT != completionList.end(); charIT++)
    225225  {
    226226    if ((*charIT).type != changeType)
    227227    {
    228       if (changeType != SHELLC_NONE)
     228      if (changeType != NullCompletion)
    229229        PRINT(0)("\n");
    230       PRINT(0)("%s: ", ShellCompletion::typeToString((*charIT).type));
     230      PRINT(0)("%s: ", ShellCompletion::typeToString((*charIT).type).c_str());
    231231      changeType = (*charIT).type;
    232232    }
     
    265265 * !! The strings MUST NOT be deleted !!
    266266 */
    267 bool ShellCompletion::addToCompleteList(const std::list<std::string>& inputList, const std::string& completionBegin, SHELLC_TYPE type)
     267bool ShellCompletion::addToCompleteList(const std::list<std::string>& inputList, const std::string& completionBegin, CompletionType type)
    268268{
    269269  unsigned int searchLength = completionBegin.size();
     
    276276    {
    277277      printf ("%s\n", (*string).c_str());
    278       ShellC_Element newElem;
     278      CompletionElement newElem;
    279279      newElem.name = (*string);
    280280      newElem.type = type;
     
    291291 * !! The strings MUST NOT be deleted !!
    292292 */
    293 bool ShellCompletion::addToCompleteList(const std::list<BaseObject*>& inputList, const std::string& completionBegin, SHELLC_TYPE type)
     293bool ShellCompletion::addToCompleteList(const std::list<BaseObject*>& inputList, const std::string& completionBegin, CompletionType type)
    294294{
    295295  unsigned int searchLength = completionBegin.size();
     
    302302          !nocaseCmp((*bo)->getName(), completionBegin, searchLength))
    303303    {
    304       ShellC_Element newElem;
     304      CompletionElement newElem;
    305305      newElem.name = (*bo)->getName();
    306306      newElem.type = type;
     
    322322}
    323323
    324 const char* ShellCompletion::typeToString(SHELLC_TYPE type)
     324const std::string& ShellCompletion::typeToString(CompletionType type)
    325325{
    326326  switch (type)
    327327  {
    328328    default:// SHELLC_NONE
    329       return "error";
    330     case  SHELLC_CLASS:
    331       return "class";
    332     case SHELLC_OBJECT:
    333       return "object";
    334     case SHELLC_FUNCTION:
    335       return "function";
    336     case SHELLC_ALIAS:
    337       return "alias";
    338   }
    339 }
     329      return typeNames[0];
     330    case  ClassCompletion:
     331      return typeNames[1];
     332    case ObjectCompletion:
     333      return typeNames[2];
     334    case FunctionCompletion:
     335      return typeNames[3];
     336    case AliasCompletion:
     337      return typeNames[4];
     338  }
     339}
     340
     341
     342const std::string ShellCompletion::typeNames[] =
     343{
     344  "error",
     345  "class",
     346  "object",
     347  "function",
     348  "alias"
     349};
  • trunk/src/lib/shell/shell_completion.h

    r7371 r7372  
    2626  //! an enumerator for different types the Shell can complete.
    2727  typedef enum {
    28     SHELLC_NONE        = 0,
    29     SHELLC_CLASS       = 1,
    30     SHELLC_OBJECT      = 2,
    31     SHELLC_FUNCTION    = 4,
    32     SHELLC_ALIAS       = 8,
    33   } SHELLC_TYPE;
     28    NullCompletion         = 0,
     29    ClassCompletion        = 1,
     30    ObjectCompletion       = 2,
     31    FunctionCompletion     = 4,
     32    AliasCompletion        = 8,
     33  } CompletionType;
    3434
    3535//! A struct for ShellElements (these are used as containers to identify an Input for what it is)
    36   struct ShellC_Element{
     36  struct CompletionElement{
    3737    std::string     name;     //!< the Name of the Element to be completed.
    38     SHELLC_TYPE    type;     //!< the type of the Element
     38    CompletionType type;     //!< the type of the Element
    3939  };
    4040
     
    5757
    5858
    59   bool addToCompleteList(const std::list<std::string>& inputList, const std::string& completionBegin, SHELLC_TYPE type);
    60   bool addToCompleteList(const std::list<BaseObject*>& inputList, const std::string& completionBegin, SHELLC_TYPE type);
     59  bool addToCompleteList(const std::list<std::string>& inputList, const std::string& completionBegin, ShellCompletion::CompletionType type);
     60  bool addToCompleteList(const std::list<BaseObject*>& inputList, const std::string& completionBegin, ShellCompletion::CompletionType type);
    6161  void clearCompletionList();
    6262
    63   static const char* ShellCompletion::typeToString(SHELLC_TYPE type);
     63  static const std::string& ShellCompletion::typeToString(ShellCompletion::CompletionType type);
    6464
    6565 private:
    66    std::list<ShellC_Element>    completionList;          //!< A list of completions, that are io.
     66   std::list<CompletionElement>    completionList;          //!< A list of completions, that are io.
     67
     68
     69   static const std::string        typeNames[];             //!< A list of Completion-Type-Names.
    6770};
    6871
Note: See TracChangeset for help on using the changeset viewer.