本文整理汇总了C++中Option::error方法的典型用法代码示例。如果您正苦于以下问题:C++ Option::error方法的具体用法?C++ Option::error怎么用?C++ Option::error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option::error方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// parser<unsigned long long> implementation
//
bool parser<unsigned long long>::parse(Option &O, StringRef ArgName,
StringRef Arg, unsigned long long &Value){
if (Arg.getAsInteger(0, Value))
return O.error("'" + Arg + "' value invalid for uint argument!");
return false;
}
示例2: parseDouble
// parser<double>/parser<float> implementation
//
static bool parseDouble(Option &O, const std::string &Arg, double &Value) {
const char *ArgStart = Arg.c_str();
char *End;
Value = strtod(ArgStart, &End);
if (*End != 0)
return O.error(": '" +Arg+ "' value invalid for floating point argument!");
return false;
}
示例3:
// parser<int> implementation
//
bool parser<int>::parse(Option &O, const char *ArgName,
const std::string &Arg, int &Value) {
char *End;
Value = (int)strtol(Arg.c_str(), &End, 0);
if (*End != 0)
return O.error(": '" + Arg + "' value invalid for integer argument!");
return false;
}
示例4: parseDouble
// parser<double>/parser<float> implementation
//
static bool parseDouble(Option &O, const string& Arg, double &Value) {
try {
Value = lexical_cast<double> (Arg);
} catch (bad_lexical_cast &) {
return O.error("'" + Arg
+ "' value invalid for floating point argument!");
}
return false;
}
示例5: parseDouble
// parser<double>/parser<float> implementation
//
static bool parseDouble(Option &O, StringRef Arg, double &Value) {
SmallString<32> TmpStr(Arg.begin(), Arg.end());
const char *ArgStart = TmpStr.c_str();
char *End;
Value = strtod(ArgStart, &End);
if (*End != 0)
return O.error("'" + Arg + "' value invalid for floating point argument!");
return false;
}
示例6: catch
// parser<unsigned> implementation
//
bool parser<unsigned>::parse(Option &O, const string& ArgName,
const string& Arg, unsigned &Value) {
try {
Value = lexical_cast<int> (Arg);
} catch (bad_lexical_cast &) {
return O.error("'" + Arg + "' value invalid for uint argument!");
}
return false;
}
示例7: strtoul
// parser<unsigned> implementation
//
bool parser<unsigned>::parse(Option &O, const char *ArgName,
const std::string &Arg, unsigned &Value) {
char *End;
errno = 0;
unsigned long V = strtoul(Arg.c_str(), &End, 0);
Value = (unsigned)V;
if (((V == ULONG_MAX) && (errno == ERANGE))
|| (*End != 0)
|| (Value != V))
return O.error(": '" + Arg + "' value invalid for uint argument!");
return false;
}
示例8: if
// parser<bool> implementation
//
bool parser<bool>::parse(Option &O, const char *ArgName,
const std::string &Arg, bool &Value) {
if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
Arg == "1") {
Value = true;
} else if (Arg == "false" || Arg == "FALSE" || Arg == "False" || Arg == "0") {
Value = false;
} else {
return O.error(": '" + Arg +
"' is invalid value for boolean argument! Try 0 or 1");
}
return false;
}
示例9: parse
/// Return true on error.
bool parse(Option &O, StringRef ArgName, StringRef Arg, OffsetOption &Val) {
if (Arg == "") {
Val.Val = 0;
Val.HasValue = false;
Val.IsRequested = true;
return false;
}
if (Arg.getAsInteger(0, Val.Val))
return O.error("'" + Arg + "' value invalid for integer argument!");
Val.HasValue = true;
Val.IsRequested = true;
return false;
}
示例10:
// parser<boolOrDefault> implementation
//
bool parser<boolOrDefault>::parse(Option &O, const string& ArgName,
const string& Arg, boolOrDefault &Value) {
if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
Arg == "1") {
Value = BOU_TRUE;
return false;
}
if (Arg == "false" || Arg == "FALSE" || Arg == "False" || Arg == "0") {
Value = BOU_FALSE;
return false;
}
return O.error("'" + Arg +
"' is invalid value for boolean argument! Try 0 or 1");
}
示例11: GetOptionInfo
/// GetOptionInfo - Scan the list of registered options, turning them into data
/// structures that are easier to handle.
static void GetOptionInfo(std::vector<Option*> &PositionalOpts,
std::vector<Option*> &SinkOpts,
std::map<std::string, Option*> &OptionsMap) {
std::vector<const char*> OptionNames;
Option *CAOpt = 0; // The ConsumeAfter option if it exists.
for (Option *O = RegisteredOptionList; O; O = O->getNextRegisteredOption()) {
// If this option wants to handle multiple option names, get the full set.
// This handles enum options like "-O1 -O2" etc.
O->getExtraOptionNames(OptionNames);
if (O->ArgStr[0])
OptionNames.push_back(O->ArgStr);
// Handle named options.
for (size_t i = 0, e = OptionNames.size(); i != e; ++i) {
// Add argument to the argument map!
if (!OptionsMap.insert(std::pair<std::string,Option*>(OptionNames[i],
O)).second) {
cerr << ProgramName << ": CommandLine Error: Argument '"
<< OptionNames[i] << "' defined more than once!\n";
}
}
OptionNames.clear();
// Remember information about positional options.
if (O->getFormattingFlag() == cl::Positional)
PositionalOpts.push_back(O);
else if (O->getMiscFlags() & cl::Sink) // Remember sink options
SinkOpts.push_back(O);
else if (O->getNumOccurrencesFlag() == cl::ConsumeAfter) {
if (CAOpt)
O->error("Cannot specify more than one option with cl::ConsumeAfter!");
CAOpt = O;
}
}
if (CAOpt)
PositionalOpts.push_back(CAOpt);
// Make sure that they are in order of registration not backwards.
std::reverse(PositionalOpts.begin(), PositionalOpts.end());
}
示例12: ParseCommandLineOptions
void cl::ParseCommandLineOptions(int argc, char **argv,
const char *Overview, bool ReadResponseFiles) {
// Process all registered options.
std::vector<Option*> PositionalOpts;
std::vector<Option*> SinkOpts;
std::map<std::string, Option*> Opts;
GetOptionInfo(PositionalOpts, SinkOpts, Opts);
assert((!Opts.empty() || !PositionalOpts.empty()) &&
"No options specified!");
// Expand response files.
std::vector<char*> newArgv;
if (ReadResponseFiles) {
newArgv.push_back(strdup(argv[0]));
ExpandResponseFiles(argc, argv, newArgv);
argv = &newArgv[0];
argc = static_cast<int>(newArgv.size());
}
// Copy the program name into ProgName, making sure not to overflow it.
std::string ProgName = sys::Path(argv[0]).getLast();
if (ProgName.size() > 79) ProgName.resize(79);
strcpy(ProgramName, ProgName.c_str());
ProgramOverview = Overview;
bool ErrorParsing = false;
// Check out the positional arguments to collect information about them.
unsigned NumPositionalRequired = 0;
// Determine whether or not there are an unlimited number of positionals
bool HasUnlimitedPositionals = false;
Option *ConsumeAfterOpt = 0;
if (!PositionalOpts.empty()) {
if (PositionalOpts[0]->getNumOccurrencesFlag() == cl::ConsumeAfter) {
assert(PositionalOpts.size() > 1 &&
"Cannot specify cl::ConsumeAfter without a positional argument!");
ConsumeAfterOpt = PositionalOpts[0];
}
// Calculate how many positional values are _required_.
bool UnboundedFound = false;
for (size_t i = ConsumeAfterOpt != 0, e = PositionalOpts.size();
i != e; ++i) {
Option *Opt = PositionalOpts[i];
if (RequiresValue(Opt))
++NumPositionalRequired;
else if (ConsumeAfterOpt) {
// ConsumeAfter cannot be combined with "optional" positional options
// unless there is only one positional argument...
if (PositionalOpts.size() > 2)
ErrorParsing |=
Opt->error(" error - this positional option will never be matched, "
"because it does not Require a value, and a "
"cl::ConsumeAfter option is active!");
} else if (UnboundedFound && !Opt->ArgStr[0]) {
// This option does not "require" a value... Make sure this option is
// not specified after an option that eats all extra arguments, or this
// one will never get any!
//
ErrorParsing |= Opt->error(" error - option can never match, because "
"another positional argument will match an "
"unbounded number of values, and this option"
" does not require a value!");
}
UnboundedFound |= EatsUnboundedNumberOfValues(Opt);
}
HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
}
// PositionalVals - A vector of "positional" arguments we accumulate into
// the process at the end...
//
std::vector<std::pair<std::string,unsigned> > PositionalVals;
// If the program has named positional arguments, and the name has been run
// across, keep track of which positional argument was named. Otherwise put
// the positional args into the PositionalVals list...
Option *ActivePositionalArg = 0;
// Loop over all of the arguments... processing them.
bool DashDashFound = false; // Have we read '--'?
for (int i = 1; i < argc; ++i) {
Option *Handler = 0;
const char *Value = 0;
const char *ArgName = "";
// If the option list changed, this means that some command line
// option has just been registered or deregistered. This can occur in
// response to things like -load, etc. If this happens, rescan the options.
if (OptionListChanged) {
PositionalOpts.clear();
SinkOpts.clear();
Opts.clear();
GetOptionInfo(PositionalOpts, SinkOpts, Opts);
OptionListChanged = false;
}
//.........这里部分代码省略.........