本文整理汇总了C++中AppConfig::is_valid方法的典型用法代码示例。如果您正苦于以下问题:C++ AppConfig::is_valid方法的具体用法?C++ AppConfig::is_valid怎么用?C++ AppConfig::is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppConfig
的用法示例。
在下文中一共展示了AppConfig::is_valid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_options
static
void parse_options(int argc, char* argv[], AppConfig &conf)
{
static struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"config", required_argument, 0, 'c'},
{0, 0, 0, 0}
};
// Set default values TODO - make a member function?
conf.blynk_server = BLYNK_DEFAULT_DOMAIN;
conf.blynk_port = TOSTRING(BLYNK_DEFAULT_PORT);
conf.mqtt_port = 1883;
conf.mqtt_server = MQTT_DEFAULT_DOMAIN;
const char* usage =
"Usage: %s [options]\n"
"\n"
"Options:\n"
" -h, --help Print this help\n"
" -c config.json, --config=configfile.json JSON Configuration file.\n"
"\n"
"Defaults:\n"
" Unless specified in the config file, the following defaults are used:"
" blynk.server: " BLYNK_DEFAULT_DOMAIN "\n"
" blynk.port" TOSTRING(BLYNK_DEFAULT_PORT) "\n"
" mqtt.server: " MQTT_DEFAULT_DOMAIN "\n"
" outputs: empty list"
"\n";
int rez;
while (-1 != (rez = getopt_long(argc, argv, "hc:", long_options, NULL))) {
switch (rez) {
case 'c':
if (conf.parse(optarg)) {
printf("Config successfully loaded from: %s\n", optarg);
} else {
printf("Failed to parse config from: %s: %s\n", optarg, conf.failure());
}
break;
case 'h':
default:
printf(usage, argv[0]);
exit(0);
};
};
// Allowed to load extra settings here.
// Check mandatory options
if (!conf.is_valid()) {
printf("Final configuraton is invalid: %s\n", conf.failure());
exit(1);
}
conf.dump();
}