本文整理汇总了C++中options类的典型用法代码示例。如果您正苦于以下问题:C++ options类的具体用法?C++ options怎么用?C++ options使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了options类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_config_option
options set_config_option(options const & opts, char const * in) {
if (!in) return opts;
while (*in && std::isspace(*in))
++in;
std::string in_str(in);
auto pos = in_str.find('=');
if (pos == std::string::npos)
throw lean::exception("invalid -D parameter, argument must contain '='");
lean::name opt = lean::string_to_name(in_str.substr(0, pos));
std::string val = in_str.substr(pos+1);
auto decls = lean::get_option_declarations();
auto it = decls.find(opt);
if (it != decls.end()) {
switch (it->second.kind()) {
case lean::BoolOption:
if (val == "true")
return opts.update(opt, true);
else if (val == "false")
return opts.update(opt, false);
else
throw lean::exception(lean::sstream() << "invalid -D parameter, invalid configuration option '" << opt
<< "' value, it must be true/false");
case lean::IntOption:
case lean::UnsignedOption:
return opts.update(opt, atoi(val.c_str()));
default:
throw lean::exception(lean::sstream() << "invalid -D parameter, configuration option '" << opt
<< "' cannot be set in the command line, use set_option command");
}
} else {
throw lean::exception(lean::sstream() << "invalid -D parameter, unknown configuration option '" << opt << "'");
}
}
示例2: has_show
static bool has_show(options const & opts, name const & kind, unsigned & line, unsigned & col) {
if (opts.get_bool(kind)) {
line = opts.get_unsigned("line", 0);
col = opts.get_unsigned("column", 0);
return true;
} else {
return false;
}
}
示例3: context
context(const benchmark_info& info, const options& opts)
: d_timer_on(false)
, d_start()
, d_duration()
, d_benchtime(std::chrono::seconds(opts.get_benchtime()))
, d_num_iterations(1)
, d_num_threads(opts.get_cpu())
, d_num_bytes(0)
, d_benchmark(info)
{}
示例4: display
void display(options& opt, spec::runner::result const& res)
{
// stdout is default so this is valid
std::ostream output( std::cout.rdbuf() );
bool file_output = false;
std::ofstream file_stream;
std::string const& format = opt.format();
std::string const& output_method = opt.output_method();
boost::shared_ptr<output_format::base> outformat;
std::string file_extension;
if( output_method == "stderr" )
output.rdbuf( std::cerr.rdbuf() );
else if( output_method == "file" )
file_output = true;
// Add you output format the same way as bellow DON'T FORGET TO ADD
// FILE EXTENSION
// ---------------------------------------------------------------------------
if( format == "compiler" )
{
outformat.reset( new output_format::compiler() );
file_extension = ".txt";
}
// ---------------------------------------------------------------------------
else if( format == "xml" )
{
outformat.reset( new output_format::xml() );
file_extension = ".xml";
}
// ---------------------------------------------------------------------------
else
{
throw std::runtime_error( "output format not supported" );
}
if( file_output )
{
std::string filename = opt.filename()+file_extension;
file_stream.open(filename.c_str(), std::ios_base::out|std::ios_base::trunc);
if( file_stream.is_open() )
output.rdbuf( file_stream.rdbuf() );
}
spec::output out( outformat, res, output );
out.display();
}
示例5: runTests
std::size_t TestFixture::runTests(const options& args)
{
std::string classname(args.which_test());
std::string testname("");
if (classname.find("::") != std::string::npos) {
testname = classname.substr(classname.find("::") + 2);
classname.erase(classname.find("::"));
}
countTests = 0;
errmsg.str("");
const std::list<TestFixture *> &tests = TestRegistry::theInstance().tests();
for (std::list<TestFixture *>::const_iterator it = tests.begin(); it != tests.end(); ++it) {
if (classname.empty() || (*it)->classname == classname) {
(*it)->processOptions(args);
(*it)->run(testname);
}
}
std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << std::endl;
std::cout << "Number of todos: " << todos_counter;
if (succeeded_todos_counter > 0)
std::cout << " (" << succeeded_todos_counter << " succeeded)";
std::cout << std::endl;
// calling flush here, to do all output before the error messages (in case the output is buffered)
std::cout.flush();
std::cerr << "Tests failed: " << fails_counter << std::endl << std::endl;
std::cerr << errmsg.str();
std::cerr.flush();
return fails_counter;
}
示例6: join
options join(options const & opts1, options const & opts2) {
sexpr r = opts2.m_value;
for_each(opts1.m_value, [&](sexpr const & p) {
if (!opts2.contains(to_name(car(p))))
r = cons(p, r);
});
return options(r);
}
示例7: run_benchmarks
/*
* The run_benchmarks function will run the registered benchmarks.
*/
void run_benchmarks(const options& opts) {
std::regex match_r(opts.get_bench());
auto benchmarks = registration::get_ptr()->get_benchmarks();
for (auto& info : benchmarks) {
if (std::regex_match(info.get_name(), match_r)) {
context c(info, opts);
auto r = c.run();
std::cout << std::setw(35) << std::left << info.get_name() << r.to_string() << std::endl;
}
}
}
示例8: parse_options
int parse_options(int argc, const char** argv, options& opts) {
eagine::program_args args(argc, argv);
for(auto a = args.first(); a; a = a.next()) {
if(a.is_help_arg()) {
opts.print_usage(std::cout);
return 1;
} else if(!parse_argument(a, opts)) {
opts.print_usage(std::cerr);
return 2;
}
}
if(!opts.check(std::cerr)) {
opts.print_usage(std::cerr);
return 3;
}
return 0;
}
示例9: parse_argument
bool parse_argument(eagine::program_arg& a, options& opts) {
if(!opts.parse(a, std::cerr)) {
std::cerr
<< "Failed to parse argument '"
<< a.get()
<< "'"
<< std::endl;
return false;
}
return true;
}
示例10:
bool options::operator==(const options &rhs)
{
// iterate over options in the first list
for (entry *curentry = m_entrylist.first(); curentry != nullptr; curentry = curentry->next())
if (!curentry->is_header())
{
// if the values differ, return false
if (strcmp(curentry->value(), rhs.value(curentry->name())) != 0)
return false;
}
return true;
}
示例11: display_pos
void display_pos(std::ostream & out, options const & o, char const * strm_name, unsigned line, unsigned pos) {
out << strm_name << ":";
if (o.get_bool("flycheck", false)) {
// generate valid line and column for flycheck mode
if (line == static_cast<unsigned>(-1))
line = 1;
if (pos == static_cast<unsigned>(-1))
pos = 0;
}
if (line != static_cast<unsigned>(-1))
out << line << ":";
if (pos != static_cast<unsigned>(-1))
out << pos << ":";
}
示例12: is
void
augd::createsslctxs(sslctxs& sslctxs, const options& options, char* frobpass)
{
const char* contexts = options.get("ssl.contexts", 0);
if (contexts) {
istringstream is(contexts);
string name;
while (is >> name)
sslctxs.insert(make_pair(name, createsslctx(name, options,
frobpass)));
}
}
示例13: get_elaborator_lift_coercions
bool get_elaborator_lift_coercions(options const & opts) {
return opts.get_bool(*g_elaborator_lift_coercions, LEAN_DEFAULT_ELABORATOR_LIFT_COERCIONS);
}
示例14: get_elaborator_fail_missing_field
bool get_elaborator_fail_missing_field(options const & opts) {
return opts.get_bool(*g_elaborator_fail_missing_field, LEAN_DEFAULT_ELABORATOR_FAIL_MISSING_FIELD);
}
示例15: get_elaborator_flycheck_goals
bool get_elaborator_flycheck_goals(options const & opts) {
return opts.get_bool(*g_elaborator_flycheck_goals, LEAN_DEFAULT_ELABORATOR_FLYCHECK_GOALS);
}