本文整理汇总了C++中Parse::setSimulate方法的典型用法代码示例。如果您正苦于以下问题:C++ Parse::setSimulate方法的具体用法?C++ Parse::setSimulate怎么用?C++ Parse::setSimulate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parse
的用法示例。
在下文中一共展示了Parse::setSimulate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
case 'r':
params.resource = optarg;
break;
case 'u':
params.idUser = atol(optarg);
break;
case 'o':
params.idOwner = atol(optarg);
break;
case 't':
params.test = true;
break;
case 'v':
displayVersion();
return EXIT_SUCCESS;
break;
case 'h':
case '?':
displayHelp();
return EXIT_SUCCESS;
break;
/* длинная опция без короткого эквивалента */
case 0:
break;
}
opt = getopt_long(argc, argv, optString, longOpts, &longIndex);
}
if (argc == 1) {
displayHelp();
return EXIT_SUCCESS;
}
if (params.config == NULL) {
std::cout << "Please, put path to configuration file -c" << std::endl;
return EXIT_FAILURE;
}
if (!params.test &&
(params.group == NULL || params.resource == NULL) ) {
std::cout << "Please, put group -g or resource -r" << std::endl;
return EXIT_FAILURE;
}
Parse * parse = NULL;
try {
parse = new Parse();
parse->setSimulate(params.test);
parse->setFile(new std::ifstream(params.config));
parse->load();
if (!params.test) {
bool allow;
if (!parse->getGroups().count(params.group)) {
throw ParseException(
"Group " + ( (std::string) params.group ) + " not found in configuration file.");
}
allow =
parse->getGroups().at(params.group)
->getRules()
->isAllow(
params.resource,
params.idUser,
params.idOwner);
if (allow) {
std::cout << "Access allow" << std::endl;
} else {
std::cout << "Access denied" << std::endl;
}
}
} catch (ParseException &e) {
std::cout << "Error: " << e.what() << std::endl;
} catch (...) {
std::cout << "Error: unknown. Please, report about this to developers. "
<< std::endl;
}
if (NULL != parse) {
delete parse;
}
return EXIT_SUCCESS;
}