Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Sep 19, 2005, 10:00:45 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: default value can now be supplied as aditional arg of the SHELL_COMMAND-macro

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

Legend:

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

    r5204 r5207  
    572572  return this;
    573573}
     574
     575/**
     576 * sets default Values of the Commands
     577 * @param count how many default Values to set.
     578 * @param ... the default Values in order. They will be cast to the right type
     579 * @returns itself
     580 *
     581 * Be aware, that when you use this Function, you !!MUST!! match the input as
     582 * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS]
     583 */
     584ShellCommandBase* ShellCommandBase::defaultValues(unsigned int count, ...)
     585{
     586  if (this == NULL)
     587    return NULL;
     588  if (count == 0)
     589    return this;
     590  if (count > this->paramCount)
     591    count = this->paramCount;
     592
     593  va_list defaultList;
     594  va_start(defaultList, count);
     595
     596  for (unsigned int i = 0; i < count; i++)
     597  {
     598    switch (this->parameters[i])
     599    {
     600      case ParameterBool:
     601        this->defaultBools[i] = va_arg(defaultList, int);
     602        break;
     603      case ParameterChar:
     604        this->defaultStrings[i] = new char[2];
     605        sprintf(this->defaultStrings[0], "%c",  va_arg(defaultList, int));
     606        break;
     607      case ParameterString:
     608        this->defaultStrings[i] = va_arg(defaultList, char*);
     609        break;
     610      case ParameterInt:
     611        this->defaultInts[i] = va_arg(defaultList, int);
     612        break;
     613      case ParameterUInt:
     614        this->defaultInts[i] = va_arg(defaultList, unsigned int);
     615        break;
     616      case ParameterFloat:
     617        this->defaultFloats[i] = va_arg(defaultList, double);
     618        break;
     619      case ParameterLong:
     620        this->defaultInts[i] = va_arg(defaultList, long);
     621        break;
     622      default:
     623        break;
     624    }
     625  }
     626
     627  return this;
     628}
     629
    574630
    575631/**
  • trunk/src/lib/shell/shell_command.h

    r5204 r5207  
    22 * @file shell_command.h
    33 * Definition of a on-screen-shell
    4  * @todo simple way to supply Default Values with the macro.
    54*/
    65
     
    8786    ShellCommandBase* describe(const char* description);
    8887    ShellCommandBase* setAlias(const char* alias);
     88    ShellCommandBase* defaultValues(unsigned int count, ...);
    8989
    9090    /** @returns the CommandList of the Shell */
  • trunk/src/lib/shell/shell_input.cc

    r5204 r5207  
    3636    ->describe("retrieve some help about the input mode")
    3737    ->setAlias("help");
    38 
    3938/**
    4039 * standard constructor
     
    179178void ShellInput::help(const char* className, const char* functionName)
    180179{
     180  printf("%s::%s\n", className, functionName);
     181
    181182  if (strlen(className) == 0)
    182183  {
Note: See TracChangeset for help on using the changeset viewer.