示例#1
0
    /**
     * Constructor.
     * @param of Whether or not this command requires an argument
     * @param ot The type of option (string, number, any, etc.)
     * @param shOpt The one character command line option.  Set to 0
     * if unused.
     * @param loOpt The long command option.  Set to std::string() 
     * if unused.
     * @param desc A string describing what this option does.
     * @param req Set to true if this is a required option.
     * @param optVectorList Use this to create your own 
     * command option list if you want to use an alternate method
     * of parsing the command options.
     */
 CommandOption(const CommandOptionFlag of, 
               const CommandOptionType ot,
               const char shOpt, 
               const std::string& loOpt, 
               const std::string& desc,
               const bool req = false,
               CommandOptionVec& optVectorList =  
                  defaultCommandOptionList)
       : optFlag(of),  optType(ot),
         shortOpt(shOpt), longOpt(loOpt), description(desc),
         required(req), count(0), maxCount(0), order(0)
    {optVectorList.push_back(this);}
示例#2
0
 CommandOption::CommandOption(
    const CommandOption::CommandOptionFlag of, 
    const CommandOption::CommandOptionType ot,
    const char shOpt, 
    const std::string& loOpt, 
    const std::string& desc,
    const bool req,
    CommandOptionVec& optVectorList)
       : optFlag(of),  optType(ot),
         shortOpt(shOpt), longOpt(loOpt), description(desc),
         required(req), count(0), maxCount(0), order(0)
 {
    if (ot == CommandOption::stdType)
    {
       if ( (shOpt == 0) && (loOpt.size() == 0) )
       {
          InvalidParameter  exc("A short or long command option must be specified");
          GPSTK_THROW(exc);
       }
          // if short option is specified, allow only printable, non-space characters
       if ( (shOpt != 0) && !isgraph(shOpt) )
       {
          InvalidParameter  exc("Invalid short command option character");
          GPSTK_THROW(exc);
       }
          // if long option is specified, allow only printable, non-space characters
       for ( size_t i = longOpt.size(); i > 0; --i )
       {
          if ( !isgraph(longOpt[i - 1]) )
          {
             InvalidParameter  exc("Invalid long command option character");
             GPSTK_THROW(exc);
          }
       }
    }
    optVectorList.push_back(this);
 }