本文整理汇总了C++中Option::getFormattingFlag方法的典型用法代码示例。如果您正苦于以下问题:C++ Option::getFormattingFlag方法的具体用法?C++ Option::getFormattingFlag怎么用?C++ Option::getFormattingFlag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option::getFormattingFlag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getOptionPred
/// HandlePrefixedOrGroupedOption - The specified argument string (which started
/// with at least one '-') does not fully match an available option. Check to
/// see if this is a prefix or grouped option. If so, split arg into output an
/// Arg/Value pair and return the Option to parse it with.
static Option *HandlePrefixedOrGroupedOption(string& Arg, string &Value,
bool &ErrorParsing,
const unordered_map<string, Option*> &OptionsMap) {
if (Arg.size() == 1) return 0;
// Do the lookup!
size_t Length = 0;
Option *PGOpt = getOptionPred(Arg, Length, isPrefixedOrGrouping, OptionsMap);
if (PGOpt == 0) return 0;
// If the option is a prefixed option, then the value is simply the
// rest of the name... so fall through to later processing, by
// setting up the argument name flags and value fields.
if (PGOpt->getFormattingFlag() == cl::Prefix) {
Value = Arg.substr(Length);
Arg = Arg.substr(0, Length);
assert(OptionsMap.count(Arg) && OptionsMap.find(Arg)->second == PGOpt);
return PGOpt;
}
// This must be a grouped option... handle them now. Grouping options can't
// have values.
assert(isGrouping(PGOpt) && "Broken getOptionPred!");
do {
// Move current arg name out of Arg into OneArgName.
string OneArgName = Arg.substr(0, Length);
Arg = Arg.substr(Length);
// Because ValueRequired is an invalid flag for grouped arguments,
// we don't need to pass argc/argv in.
assert(PGOpt->getValueExpectedFlag() != cl::ValueRequired &&
"Option can not be cl::Grouping AND cl::ValueRequired!");
int Dummy = 0;
string dummystr;
ErrorParsing |= ProvideOption(PGOpt, OneArgName,
dummystr, 0, 0, Dummy);
// Get the next grouping option.
PGOpt = getOptionPred(Arg, Length, isGrouping, OptionsMap);
} while (PGOpt && Length != Arg.size());
// Return the last option with Arg cut down to just the last one.
return PGOpt;
}
示例2: 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());
}
示例3: ParseCommandLineOptions
//.........这里部分代码省略.........
//
if (argv[i][0] != '-' || argv[i][1] == 0 || DashDashFound) {
// Positional argument!
if (ActivePositionalArg) {
ProvidePositionalOption(ActivePositionalArg, argv[i], i);
continue; // We are done!
} else if (!PositionalOpts.empty()) {
PositionalVals.push_back(std::make_pair(argv[i],i));
// All of the positional arguments have been fulfulled, give the rest to
// the consume after option... if it's specified...
//
if (PositionalVals.size() >= NumPositionalRequired &&
ConsumeAfterOpt != 0) {
for (++i; i < argc; ++i)
PositionalVals.push_back(std::make_pair(argv[i],i));
break; // Handle outside of the argument processing loop...
}
// Delay processing positional arguments until the end...
continue;
}
} else if (argv[i][0] == '-' && argv[i][1] == '-' && argv[i][2] == 0 &&
!DashDashFound) {
DashDashFound = true; // This is the mythical "--"?
continue; // Don't try to process it as an argument itself.
} else if (ActivePositionalArg &&
(ActivePositionalArg->getMiscFlags() & PositionalEatsArgs)) {
// If there is a positional argument eating options, check to see if this
// option is another positional argument. If so, treat it as an argument,
// otherwise feed it to the eating positional.
ArgName = argv[i]+1;
Handler = LookupOption(ArgName, Value, Opts);
if (!Handler || Handler->getFormattingFlag() != cl::Positional) {
ProvidePositionalOption(ActivePositionalArg, argv[i], i);
continue; // We are done!
}
} else { // We start with a '-', must be an argument...
ArgName = argv[i]+1;
Handler = LookupOption(ArgName, Value, Opts);
// Check to see if this "option" is really a prefixed or grouped argument.
if (Handler == 0) {
std::string RealName(ArgName);
if (RealName.size() > 1) {
size_t Length = 0;
Option *PGOpt = getOptionPred(RealName, Length, isPrefixedOrGrouping,
Opts);
// If the option is a prefixed option, then the value is simply the
// rest of the name... so fall through to later processing, by
// setting up the argument name flags and value fields.
//
if (PGOpt && PGOpt->getFormattingFlag() == cl::Prefix) {
Value = ArgName+Length;
assert(Opts.find(std::string(ArgName, Value)) != Opts.end() &&
Opts.find(std::string(ArgName, Value))->second == PGOpt);
Handler = PGOpt;
} else if (PGOpt) {
// This must be a grouped option... handle them now.
assert(isGrouping(PGOpt) && "Broken getOptionPred!");
do {
// Move current arg name out of RealName into RealArgName...
std::string RealArgName(RealName.begin(),