本文整理汇总了C++中Args::SetArguments方法的典型用法代码示例。如果您正苦于以下问题:C++ Args::SetArguments方法的具体用法?C++ Args::SetArguments怎么用?C++ Args::SetArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Args
的用法示例。
在下文中一共展示了Args::SetArguments方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetArgs
size_t OptionValueArray::GetArgs(Args &args) const {
const uint32_t size = m_values.size();
std::vector<const char *> argv;
for (uint32_t i = 0; i < size; ++i) {
const char *string_value = m_values[i]->GetStringValue();
if (string_value)
argv.push_back(string_value);
}
if (argv.empty())
args.Clear();
else
args.SetArguments(argv.size(), &argv[0]);
return args.GetArgumentCount();
}
示例2: new_args
void
CommandInterpreter::BuildAliasCommandArgs
(
CommandObject *alias_cmd_obj,
const char *alias_name,
Args &cmd_args,
CommandReturnObject &result
)
{
OptionArgVectorSP option_arg_vector_sp = GetAliasOptions (alias_name);
if (option_arg_vector_sp.get())
{
// Make sure that the alias name is the 0th element in cmd_args
std::string alias_name_str = alias_name;
if (alias_name_str.compare (cmd_args.GetArgumentAtIndex(0)) != 0)
cmd_args.Unshift (alias_name);
Args new_args (alias_cmd_obj->GetCommandName());
if (new_args.GetArgumentCount() == 2)
new_args.Shift();
OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
int old_size = cmd_args.GetArgumentCount();
int *used = (int *) malloc ((old_size + 1) * sizeof (int));
memset (used, 0, (old_size + 1) * sizeof (int));
used[0] = 1;
for (int i = 0; i < option_arg_vector->size(); ++i)
{
OptionArgPair option_pair = (*option_arg_vector)[i];
std::string option = option_pair.first;
std::string value = option_pair.second;
if (option.compare ("<argument>") == 0)
new_args.AppendArgument (value.c_str());
else
{
new_args.AppendArgument (option.c_str());
if (value.compare ("<no-argument>") != 0)
{
int index = GetOptionArgumentPosition (value.c_str());
if (index == 0)
// value was NOT a positional argument; must be a real value
new_args.AppendArgument (value.c_str());
else if (index >= cmd_args.GetArgumentCount())
{
result.AppendErrorWithFormat
("Not enough arguments provided; you need at least %d arguments to use this alias.\n",
index);
result.SetStatus (eReturnStatusFailed);
return;
}
else
{
new_args.AppendArgument (cmd_args.GetArgumentAtIndex (index));
used[index] = 1;
}
}
}
}
for (int j = 0; j < cmd_args.GetArgumentCount(); ++j)
{
if (!used[j])
new_args.AppendArgument (cmd_args.GetArgumentAtIndex (j));
}
cmd_args.Clear();
cmd_args.SetArguments (new_args.GetArgumentCount(), (const char **) new_args.GetArgumentVector());
}
else
{
result.SetStatus (eReturnStatusSuccessFinishNoResult);
// This alias was not created with any options; nothing further needs to be done.
return;
}
result.SetStatus (eReturnStatusSuccessFinishNoResult);
return;
}