Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

File:
1 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/**
Note: See TracChangeset for help on using the changeset viewer.