当前位置: 首页>>代码示例>>C++>>正文


C++ Option::next方法代码示例

本文整理汇总了C++中Option::next方法的典型用法代码示例。如果您正苦于以下问题:C++ Option::next方法的具体用法?C++ Option::next怎么用?C++ Option::next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Option的用法示例。


在下文中一共展示了Option::next方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
  {
    Stats stats(empty_usage, -1, empty_args);
    stats.add(empty_usage, 0, empty_args);
    assert(stats.buffer_max == 1);
    assert(stats.options_max == 1);
    Option buffer[stats.buffer_max];
    Option options[stats.options_max];
    Parser parse(empty_usage, 99, empty_args, options, buffer);
    parse.parse(empty_usage, -1, empty_args, options, buffer);
    assert(parse.optionsCount() == 0);
    assert(parse.nonOptionsCount() == 0);
    assert(!buffer[0]);
    assert(!options[0]);
    assert(buffer[0].count()==0);
    assert(parse.nonOptions()==0);

    stats.add(empty_usage, 3, non_options);
    assert(stats.buffer_max == 1);
    assert(stats.options_max == 1);
    parse.parse(empty_usage, 3, non_options, options, buffer);
    assert(parse.optionsCount() == 0);
    assert(parse.nonOptionsCount() == 3);
    assert(!buffer[0]);
    assert(!options[0]);
    assert(parse.nonOptions()==&non_options[0]);

    stats.add(minimal_usage, -1, unknown_option);
    assert(stats.buffer_max == 1);
    assert(stats.options_max == 2);
    parse.parse(minimal_usage, -1, unknown_option, options, buffer);
    assert(parse.optionsCount() == 0);
    assert(parse.nonOptionsCount() == 1);
    assert(!buffer[0]);
    assert(!options[0]);
    assert(parse.nonOptions()==&unknown_option[1]);
  }
  {
    Stats stats(gettext_usage, -1, lone_minus);
    Stats stats2;
    stats2.add(gettext_usage, -1, lone_minus);
    assert(stats.buffer_max == 2);
    assert(stats.options_max == 2);
    assert(stats2.buffer_max == 2);
    assert(stats2.options_max == 2);
    Option buffer[stats.buffer_max];
    Option options[stats.options_max];
    Parser parse;
    parse.parse(gettext_usage, -1, lone_minus, options, buffer);
    assert(parse.optionsCount() == 1);
    assert(parse.nonOptionsCount() == 1);
    assert(parse.nonOptions()==&lone_minus[2]);
    assert(options[0]);
    assert(buffer[0]);
    assert(options[0].count()==1);
    assert(options[0].isFirst());
    assert(options[0].isLast());
    assert(options[0].first() == options[0]);
    assert(options[0].last() == options[0]);
    assert(options[0].prevwrap() == &options[0]);
    assert(options[0].nextwrap() == &options[0]);
    assert(options[0].prev() == 0);
    assert(options[0].next() == 0);
    assert(options[0].desc == &gettext_usage[0]);
    assert(eq(options[0].name, "f"));
    assert(eq(options[0].arg, "-"));
  }
  {
    Stats stats(optional_usage, -1, lone_minus);
    Stats stats2;
    stats2.add(optional_usage, -1, lone_minus);
    assert(stats.buffer_max == 2);
    assert(stats.options_max == 2);
    assert(stats2.buffer_max == 2);
    assert(stats2.options_max == 2);
    Option buffer[stats.buffer_max];
    Option options[stats.options_max];
    Parser parse;
    parse.parse(optional_usage, -1, lone_minus, options, buffer);
    assert(parse.optionsCount() == 1);
    assert(parse.nonOptionsCount() == 1);
    assert(parse.nonOptions()==&lone_minus[2]);
    assert(options[0]);
    assert(buffer[0]);
    assert(options[0].count()==1);
    assert(options[0].isFirst());
    assert(options[0].isLast());
    assert(options[0].first() == options[0]);
    assert(options[0].last() == options[0]);
    assert(options[0].prevwrap() == &options[0]);
    assert(options[0].nextwrap() == &options[0]);
    assert(options[0].prev() == 0);
    assert(options[0].next() == 0);
    assert(options[0].desc == &optional_usage[0]);
    assert(eq(options[0].name, "f"));
    assert(eq(options[0].arg, "-"));
  }
  {
    Stats stats;
//.........这里部分代码省略.........
开发者ID:cbutakoff,项目名称:tools,代码行数:101,代码来源:testparse.cpp

示例2: configureFromInput

int32_t Configurator::configureFromInput(int argc, char* argv[]) {
    if (__configured) { //If this object was already configured, cannot override from user inputs. This is to prevent an invalid state.
        std::cerr << "WARNING: Something bad happened when configuring X-Mem. This is probably not your fault." << std::endl;
        return -2;
    }

    //Throw out first argument which is usually the program name.
    argc -= (argc > 0);
    argv += (argc > 0);

    //Set up optionparser
    Stats stats(usage, argc, argv);
    Option* options = new Option[stats.options_max];
    Option* buffer = new Option[stats.buffer_max];
    Parser parse(usage, argc, argv, options, buffer); //Parse input

    //Check for parser error
    if (parse.error()) {
        std::cerr << "ERROR: Argument parsing failed. You could try running \"xmem --help\" for usage information." << std::endl;
        goto error;
    }

    //X-Mem doesn't have any non-option arguments, so we will presume the user wants a help message.
    if (parse.nonOptionsCount() > 0) {
        std::cerr << "ERROR: X-Mem does not support any non-option arguments." << std::endl;
        goto error;
    }

    //Check for any unknown options
    for (Option* unknown_opt = options[UNKNOWN]; unknown_opt != NULL; unknown_opt = unknown_opt->next()) {
        std::cerr << "ERROR: Unknown option: " << std::string(unknown_opt->name, unknown_opt->namelen) << std::endl;
        goto error;
    }
    
    //Verbosity
    if (options[VERBOSE]) {
        __verbose = true; //What the user configuration is.
        g_verbose = true; //What rest of X-Mem actually uses.
    }

    //Check runtime modes
    if (options[MEAS_LATENCY] || options[MEAS_THROUGHPUT] || options[EXTENSION]) { //User explicitly picked at least one mode, so override default selection
        __runLatency = false;
        __runThroughput = false;
        __runExtensions = false;
    }
    
    if (options[MEAS_LATENCY])
        __runLatency = true;

    if (options[MEAS_THROUGHPUT])
        __runThroughput = true;

    //Check extensions
    if (options[EXTENSION]) {
        if (NUM_EXTENSIONS <= 0) { //no compiled-in extensions, this must fail.
            std::cerr << "ERROR: No X-Mem extensions were included at build time." << std::endl;
            goto error;
        }

        __runExtensions = true;
        
        //Init... override default values
#ifdef EXT_DELAY_INJECTED_LATENCY_BENCHMARK
        __run_ext_delay_injected_loaded_latency_benchmark = false;
#endif
#ifdef EXT_STREAM_BENCHMARK
        __run_ext_stream_benchmark = false;
#endif
        
        Option* curr = options[EXTENSION];
        while (curr) { //EXTENSION may occur more than once, this is perfectly OK.
            char* endptr = NULL;
            uint32_t ext_num = static_cast<uint32_t>(strtoul(curr->arg, &endptr, 10));
            switch (ext_num) {
#ifdef EXT_DELAY_INJECTED_LOADED_LATENCY_BENCHMARK
                case EXT_NUM_DELAY_INJECTED_LOADED_LATENCY_BENCHMARK:
                    __run_ext_delay_injected_loaded_latency_benchmark = true;
                    break;
#endif
#ifdef EXT_STREAM_BENCHMARK
                case EXT_NUM_STREAM_BENCHMARK:
                    __run_ext_stream_benchmark = true;
                    break;
#endif
                default:
                    //If no extensions are enabled, then we should not have reached this point anyway.
                    std::cerr << "ERROR: Invalid extension number " << ext_num << ". Allowed values: " << std::endl 
#ifdef EXT_DELAY_INJECTED_LOADED_LATENCY_BENCHMARK
                    << "---> Delay-injected latency benchmark: " << EXT_NUM_DELAY_INJECTED_LOADED_LATENCY_BENCHMARK
#endif
#ifdef EXT_STREAM_BENCHMARK
                    << "---> STREAM-like benchmark: " << EXT_NUM_STREAM_BENCHMARK
#endif
                    << std::endl;
                    goto error;
            }
            curr = curr->next();
        }
    }
//.........这里部分代码省略.........
开发者ID:chubbymaggie,项目名称:X-Mem,代码行数:101,代码来源:Configurator.cpp


注:本文中的Option::next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。