本文整理汇总了C++中Option::isSet方法的典型用法代码示例。如果您正苦于以下问题:C++ Option::isSet方法的具体用法?C++ Option::isSet怎么用?C++ Option::isSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option::isSet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: throw
bool
OptionsCont::isUsableFileList(const std::string &name) const throw(InvalidArgument) {
Option *o = getSecure(name);
// check whether the option is set
// return false i not
if (!o->isSet()) {
return false;
}
// check whether the list of files is valid
bool ok = true;
std::vector<std::string> files = getStringVector(name);
if (files.size()==0) {
MsgHandler::getErrorInstance()->inform("The file list for '" + name + "' is empty.");
ok = false;
}
for (std::vector<std::string>::const_iterator fileIt=files.begin(); fileIt!=files.end(); ++fileIt) {
if (!FileHelpers::exists(*fileIt)) {
if (*fileIt!="") {
MsgHandler::getErrorInstance()->inform("File '" + *fileIt + "' does not exist.");
ok = false;
} else {
MsgHandler::getWarningInstance()->inform("Empty file name given; ignoring.");
}
}
}
return ok;
}
示例2: getSecure
bool
OptionsCont::isUsableFileList(const std::string& name) const {
Option* o = getSecure(name);
// check whether the option is set
// return false i not
if (!o->isSet()) {
return false;
}
// check whether the list of files is valid
bool ok = true;
std::vector<std::string> files = getStringVector(name);
if (files.size() == 0) {
WRITE_ERROR("The file list for '" + name + "' is empty.");
ok = false;
}
for (std::vector<std::string>::const_iterator fileIt = files.begin(); fileIt != files.end(); ++fileIt) {
if (!FileHelpers::isReadable(*fileIt)) {
if (*fileIt != "") {
WRITE_ERROR("File '" + *fileIt + "' is not accessible (" + std::strerror(errno) + ").");
ok = false;
} else {
WRITE_WARNING("Empty file name given; ignoring.");
}
}
}
return ok;
}
示例3: parse
int OptionsList::parse(int &aArgc, const char **aArgv)
{
sort();
// This assumes that the first option (app name) has already been removed.
int order = 0, count = 0;
program_ = "agent";
Option *opt;
const char **argp = aArgv;
const char *cp;
while (aArgc > 0)
{
if (**argp == '-')
{
cp = (*argp) + 1;
bool next = false;
while (*cp != 0 && !next)
{
if (find(cp, opt))
{
count++;
if (opt->hasArgument())
{
getArg(argp, aArgc, opt, cp);
next = true;
}
else
{
if (opt->type_ != Option::eBoolean)
{
cerr << "Bad argument definition: " << opt->getName() << endl;
}
else if (opt->isSet_)
{
cerr << "Option " << opt->getName() << " is already specified" << endl;
usage();
}
else
{
*(opt->boolPtr_) = true;
}
cp += strlen(opt->getName());
}
opt->isSet_ = true;
}
else
{
cerr << "Bad argument:" << *argp << endl;
usage();
}
}
}
else
{
if (find(order, opt))
{
if (!opt->setValue(*argp))
usage();
count++;
}
else if (find(-1, opt))
{
if (!opt->setValue(*argp))
usage();
count++;
}
order++;
}
argp++;
aArgc--;
}
for (list<Option>::iterator iter = begin(); iter != end(); iter++)
{
opt = &(*iter);
if (opt->isRequired() && !opt->isSet())
{
if (opt->getName() != NULL)
cerr << "Required option -" << opt->getName() << " is not specified" << endl;
else
cerr << "Required option <" << opt->getArgDesc() << "> is not specified" << endl;
usage();
}
}
return count;
}