本文整理汇总了C++中Stream::Indent方法的典型用法代码示例。如果您正苦于以下问题:C++ Stream::Indent方法的具体用法?C++ Stream::Indent怎么用?C++ Stream::Indent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream::Indent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void StructuredData::Dictionary::Dump(Stream &s, bool pretty_print) const {
bool first = true;
s << "{";
if (pretty_print) {
s << "\n";
s.IndentMore();
}
for (const auto &pair : m_dict) {
if (first)
first = false;
else {
s << ",";
if (pretty_print)
s << "\n";
}
if (pretty_print)
s.Indent();
s << "\"" << pair.first.AsCString() << "\" : ";
pair.second->Dump(s, pretty_print);
}
if (pretty_print) {
s.IndentLess();
s.EOL();
s.Indent();
}
s << "}";
}
示例2: OutputFormattedUsageText
void Options::OutputFormattedUsageText(Stream &strm,
const OptionDefinition &option_def,
uint32_t output_max_columns) {
std::string actual_text;
if (option_def.validator) {
const char *condition = option_def.validator->ShortConditionString();
if (condition) {
actual_text = "[";
actual_text.append(condition);
actual_text.append("] ");
}
}
actual_text.append(option_def.usage_text);
// Will it all fit on one line?
if (static_cast<uint32_t>(actual_text.length() + strm.GetIndentLevel()) <
output_max_columns) {
// Output it as a single line.
strm.Indent(actual_text.c_str());
strm.EOL();
} else {
// We need to break it up into multiple lines.
int text_width = output_max_columns - strm.GetIndentLevel() - 1;
int start = 0;
int end = start;
int final_end = actual_text.length();
int sub_len;
while (end < final_end) {
// Don't start the 'text' on a space, since we're already outputting the
// indentation.
while ((start < final_end) && (actual_text[start] == ' '))
start++;
end = start + text_width;
if (end > final_end)
end = final_end;
else {
// If we're not at the end of the text, make sure we break the line on
// white space.
while (end > start && actual_text[end] != ' ' &&
actual_text[end] != '\t' && actual_text[end] != '\n')
end--;
}
sub_len = end - start;
if (start != 0)
strm.EOL();
strm.Indent();
assert(start < final_end);
assert(start + sub_len <= final_end);
strm.Write(actual_text.c_str() + start, sub_len);
start = end + 1;
}
strm.EOL();
}
}
示例3: strlen
void
Options::OutputFormattedUsageText
(
Stream &strm,
const char *text,
uint32_t output_max_columns
)
{
int len = strlen (text);
// Will it all fit on one line?
if (static_cast<uint32_t>(len + strm.GetIndentLevel()) < output_max_columns)
{
// Output it as a single line.
strm.Indent (text);
strm.EOL();
}
else
{
// We need to break it up into multiple lines.
int text_width = output_max_columns - strm.GetIndentLevel() - 1;
int start = 0;
int end = start;
int final_end = strlen (text);
int sub_len;
while (end < final_end)
{
// Don't start the 'text' on a space, since we're already outputting the indentation.
while ((start < final_end) && (text[start] == ' '))
start++;
end = start + text_width;
if (end > final_end)
end = final_end;
else
{
// If we're not at the end of the text, make sure we break the line on white space.
while (end > start
&& text[end] != ' ' && text[end] != '\t' && text[end] != '\n')
end--;
}
sub_len = end - start;
if (start != 0)
strm.EOL();
strm.Indent();
assert (start < final_end);
assert (start + sub_len <= final_end);
strm.Write(text + start, sub_len);
start = end + 1;
}
strm.EOL();
}
}
示例4: DumpRegister
bool DumpRegister(const ExecutionContext &exe_ctx, Stream &strm,
RegisterContext *reg_ctx, const RegisterInfo *reg_info) {
if (reg_info) {
RegisterValue reg_value;
if (reg_ctx->ReadRegister(reg_info, reg_value)) {
strm.Indent();
bool prefix_with_altname = (bool)m_command_options.alternate_name;
bool prefix_with_name = !prefix_with_altname;
reg_value.Dump(&strm, reg_info, prefix_with_name, prefix_with_altname,
m_format_options.GetFormat(), 8);
if ((reg_info->encoding == eEncodingUint) ||
(reg_info->encoding == eEncodingSint)) {
Process *process = exe_ctx.GetProcessPtr();
if (process && reg_info->byte_size == process->GetAddressByteSize()) {
addr_t reg_addr = reg_value.GetAsUInt64(LLDB_INVALID_ADDRESS);
if (reg_addr != LLDB_INVALID_ADDRESS) {
Address so_reg_addr;
if (exe_ctx.GetTargetRef()
.GetSectionLoadList()
.ResolveLoadAddress(reg_addr, so_reg_addr)) {
strm.PutCString(" ");
so_reg_addr.Dump(&strm, exe_ctx.GetBestExecutionContextScope(),
Address::DumpStyleResolvedDescription);
}
}
}
}
strm.EOL();
return true;
}
}
return false;
}
示例5: ConvertTypeMaskToType
void
OptionValueDictionary::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
{
const Type dict_type = ConvertTypeMaskToType (m_type_mask);
if (dump_mask & eDumpOptionType)
{
if (m_type_mask != eTypeInvalid)
strm.Printf ("(%s of %ss)", GetTypeAsCString(), GetBuiltinTypeAsCString(dict_type));
else
strm.Printf ("(%s)", GetTypeAsCString());
}
if (dump_mask & eDumpOptionValue)
{
if (dump_mask & eDumpOptionType)
strm.PutCString (" =");
collection::iterator pos, end = m_values.end();
strm.IndentMore();
for (pos = m_values.begin(); pos != end; ++pos)
{
OptionValue *option_value = pos->second.get();
strm.EOL();
strm.Indent(pos->first.GetCString());
const uint32_t extra_dump_options = m_raw_value_dump ? eDumpOptionRaw : 0;
switch (dict_type)
{
default:
case eTypeArray:
case eTypeDictionary:
case eTypeProperties:
case eTypeFileSpecList:
case eTypePathMap:
strm.PutChar (' ');
option_value->DumpValue(exe_ctx, strm, dump_mask | extra_dump_options);
break;
case eTypeBoolean:
case eTypeChar:
case eTypeEnum:
case eTypeFileSpec:
case eTypeFormat:
case eTypeSInt64:
case eTypeString:
case eTypeUInt64:
case eTypeUUID:
// No need to show the type for dictionaries of simple items
strm.PutCString("=");
option_value->DumpValue(exe_ctx, strm, (dump_mask & (~eDumpOptionType)) | extra_dump_options);
break;
}
}
strm.IndentLess();
}
}
示例6:
void
StructuredData::Dictionary::Dump (Stream &s) const
{
bool first = true;
s << "{\n";
s.IndentMore();
for (const auto &pair : m_dict)
{
if (first)
first = false;
else
s << ",\n";
s.Indent();
s << "\"" << pair.first.AsCString() << "\" : ";
pair.second->Dump(s);
}
s.IndentLess();
s.EOL();
s.Indent();
s << "}";
}
示例7: ConvertTypeMaskToType
void
OptionValueArray::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
{
const Type array_element_type = ConvertTypeMaskToType (m_type_mask);
if (dump_mask & eDumpOptionType)
{
if ((GetType() == eTypeArray) && (m_type_mask != eTypeInvalid))
strm.Printf ("(%s of %ss)", GetTypeAsCString(), GetBuiltinTypeAsCString(array_element_type));
else
strm.Printf ("(%s)", GetTypeAsCString());
}
if (dump_mask & eDumpOptionValue)
{
if (dump_mask & eDumpOptionType)
strm.Printf (" =%s", (m_values.size() > 0) ? "\n" : "");
strm.IndentMore();
const uint32_t size = m_values.size();
for (uint32_t i = 0; i<size; ++i)
{
strm.Indent();
strm.Printf("[%u]: ", i);
const uint32_t extra_dump_options = m_raw_value_dump ? eDumpOptionRaw : 0;
switch (array_element_type)
{
default:
case eTypeArray:
case eTypeDictionary:
case eTypeProperties:
case eTypeFileSpecList:
case eTypePathMap:
m_values[i]->DumpValue(exe_ctx, strm, dump_mask | extra_dump_options);
break;
case eTypeBoolean:
case eTypeChar:
case eTypeEnum:
case eTypeFileSpec:
case eTypeFormat:
case eTypeSInt64:
case eTypeString:
case eTypeUInt64:
case eTypeUUID:
// No need to show the type for dictionaries of simple items
m_values[i]->DumpValue(exe_ctx, strm, (dump_mask & (~eDumpOptionType)) | extra_dump_options);
break;
}
if (i < (size - 1))
strm.EOL();
}
strm.IndentLess();
}
}
示例8: exe_ctx
size_t
Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source)
{
ExecutionContext exe_ctx (shared_from_this());
Target *target = exe_ctx.GetTargetPtr();
Process *process = exe_ctx.GetProcessPtr();
size_t num_frames_shown = 0;
strm.Indent();
bool is_selected = false;
if (process)
{
if (process->GetThreadList().GetSelectedThread().get() == this)
is_selected = true;
}
strm.Printf("%c ", is_selected ? '*' : ' ');
if (target && target->GetDebugger().GetUseExternalEditor())
{
StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
if (frame_sp)
{
SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry));
if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file)
{
Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
}
}
}
DumpUsingSettingsFormat (strm, start_frame);
if (num_frames > 0)
{
strm.IndentMore();
const bool show_frame_info = true;
strm.IndentMore ();
num_frames_shown = GetStackFrameList ()->GetStatus (strm,
start_frame,
num_frames,
show_frame_info,
num_frames_with_source);
strm.IndentLess();
strm.IndentLess();
}
return num_frames_shown;
}
示例9: DumpValue
void OptionValueFileSpecList::DumpValue(const ExecutionContext *exe_ctx,
Stream &strm, uint32_t dump_mask) {
if (dump_mask & eDumpOptionType)
strm.Printf("(%s)", GetTypeAsCString());
if (dump_mask & eDumpOptionValue) {
if (dump_mask & eDumpOptionType)
strm.Printf(" =%s", m_current_value.GetSize() > 0 ? "\n" : "");
strm.IndentMore();
const uint32_t size = m_current_value.GetSize();
for (uint32_t i = 0; i < size; ++i) {
strm.Indent();
strm.Printf("[%u]: ", i);
m_current_value.GetFileSpecAtIndex(i).Dump(&strm);
}
strm.IndentLess();
}
}
示例10: if
void
DWARFDebugRanges::Dump(Stream &s, const DataExtractor& debug_ranges_data, uint32_t* offset_ptr, dw_addr_t cu_base_addr)
{
uint32_t addr_size = s.GetAddressByteSize();
bool verbose = s.GetVerbose();
dw_addr_t base_addr = cu_base_addr;
while (debug_ranges_data.ValidOffsetForDataOfSize(*offset_ptr, 2 * addr_size))
{
dw_addr_t begin = debug_ranges_data.GetMaxU64(offset_ptr, addr_size);
dw_addr_t end = debug_ranges_data.GetMaxU64(offset_ptr, addr_size);
// Extend 4 byte addresses that consits of 32 bits of 1's to be 64 bits
// of ones
if (begin == 0xFFFFFFFFull && addr_size == 4)
begin = DW_INVALID_ADDRESS;
s.Indent();
if (verbose)
{
s.AddressRange(begin, end, sizeof (dw_addr_t), " offsets = ");
}
if (begin == 0 && end == 0)
{
s.PutCString(" End");
break;
}
else if (begin == DW_INVALID_ADDRESS)
{
// A base address selection entry
base_addr = end;
s.Address(base_addr, sizeof (dw_addr_t), " Base address = ");
}
else
{
// Convert from offset to an address
dw_addr_t begin_addr = begin + base_addr;
dw_addr_t end_addr = end + base_addr;
s.AddressRange(begin_addr, end_addr, sizeof (dw_addr_t), verbose ? " ==> addrs = " : NULL);
}
}
}
示例11: locker
void
CommandHistory::Dump (Stream& stream,
size_t start_idx,
size_t stop_idx) const
{
Mutex::Locker locker(m_mutex);
stop_idx = std::min(stop_idx, m_history.size() - 1);
for (size_t counter = start_idx;
counter <= stop_idx;
counter++)
{
const std::string hist_item = m_history[counter];
if (!hist_item.empty())
{
stream.Indent();
stream.Printf("%4" PRIu64 ": %s\n", (uint64_t)counter, hist_item.c_str());
}
}
}
示例12: DumpRegisterSet
bool
DumpRegisterSet (const ExecutionContext &exe_ctx,
Stream &strm,
RegisterContext *reg_ctx,
size_t set_idx,
bool primitive_only=false)
{
uint32_t unavailable_count = 0;
uint32_t available_count = 0;
if (!reg_ctx)
return false; // thread has no registers (i.e. core files are corrupt, incomplete crash logs...)
const RegisterSet * const reg_set = reg_ctx->GetRegisterSet(set_idx);
if (reg_set)
{
strm.Printf ("%s:\n", reg_set->name);
strm.IndentMore ();
const size_t num_registers = reg_set->num_registers;
for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx)
{
const uint32_t reg = reg_set->registers[reg_idx];
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg);
// Skip the dumping of derived register if primitive_only is true.
if (primitive_only && reg_info && reg_info->value_regs)
continue;
if (DumpRegister (exe_ctx, strm, reg_ctx, reg_info))
++available_count;
else
++unavailable_count;
}
strm.IndentLess ();
if (unavailable_count)
{
strm.Indent ();
strm.Printf("%u registers were unavailable.\n", unavailable_count);
}
strm.EOL();
}
return available_count > 0;
}
示例13: GenerateOptionUsage
void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd,
uint32_t screen_width) {
const bool only_print_args = cmd->IsDashDashCommand();
auto opt_defs = GetDefinitions();
const uint32_t save_indent_level = strm.GetIndentLevel();
llvm::StringRef name;
StreamString arguments_str;
if (cmd) {
name = cmd->GetCommandName();
cmd->GetFormattedCommandArguments(arguments_str);
} else
name = "";
strm.PutCString("\nCommand Options Usage:\n");
strm.IndentMore(2);
// First, show each usage level set of options, e.g. <cmd>
// [options-for-level-0]
// <cmd>
// [options-for-level-1]
// etc.
const uint32_t num_options = NumCommandOptions();
if (num_options == 0)
return;
uint32_t num_option_sets = GetRequiredOptions().size();
uint32_t i;
if (!only_print_args) {
for (uint32_t opt_set = 0; opt_set < num_option_sets; ++opt_set) {
uint32_t opt_set_mask;
opt_set_mask = 1 << opt_set;
if (opt_set > 0)
strm.Printf("\n");
strm.Indent(name);
// Different option sets may require different args.
StreamString args_str;
if (cmd)
cmd->GetFormattedCommandArguments(args_str, opt_set_mask);
// First go through and print all options that take no arguments as
// a single string. If a command has "-a" "-b" and "-c", this will show
// up as [-abc]
std::set<int> options;
std::set<int>::const_iterator options_pos, options_end;
for (auto &def : opt_defs) {
if (def.usage_mask & opt_set_mask && isprint8(def.short_option)) {
// Add current option to the end of out_stream.
if (def.required && def.option_has_arg == OptionParser::eNoArgument) {
options.insert(def.short_option);
}
}
}
if (options.empty() == false) {
// We have some required options with no arguments
strm.PutCString(" -");
for (i = 0; i < 2; ++i)
for (options_pos = options.begin(), options_end = options.end();
options_pos != options_end; ++options_pos) {
if (i == 0 && ::islower(*options_pos))
continue;
if (i == 1 && ::isupper(*options_pos))
continue;
strm << (char)*options_pos;
}
}
options.clear();
for (auto &def : opt_defs) {
if (def.usage_mask & opt_set_mask && isprint8(def.short_option)) {
// Add current option to the end of out_stream.
if (def.required == false &&
def.option_has_arg == OptionParser::eNoArgument) {
options.insert(def.short_option);
}
}
}
if (options.empty() == false) {
// We have some required options with no arguments
strm.PutCString(" [-");
for (i = 0; i < 2; ++i)
for (options_pos = options.begin(), options_end = options.end();
options_pos != options_end; ++options_pos) {
if (i == 0 && ::islower(*options_pos))
continue;
if (i == 1 && ::isupper(*options_pos))
continue;
//.........这里部分代码省略.........
示例14: range
bool
Disassembler::Disassemble
(
Debugger &debugger,
const ArchSpec &arch,
const ExecutionContext &exe_ctx,
const AddressRange &disasm_range,
uint32_t num_mixed_context_lines,
bool show_bytes,
Stream &strm
)
{
if (disasm_range.GetByteSize())
{
Disassembler *disassembler = Disassembler::FindPlugin(arch);
if (disassembler)
{
AddressRange range(disasm_range);
Process *process = exe_ctx.process;
// If we weren't passed in a section offset address range,
// try and resolve it to something
if (range.GetBaseAddress().IsSectionOffset() == false)
{
if (process && process->IsAlive())
{
process->ResolveLoadAddress (range.GetBaseAddress().GetOffset(), range.GetBaseAddress());
}
else if (exe_ctx.target)
{
exe_ctx.target->GetImages().ResolveFileAddress (range.GetBaseAddress().GetOffset(), range.GetBaseAddress());
}
}
DataExtractor data;
size_t bytes_disassembled = disassembler->ParseInstructions (&exe_ctx, range, data);
if (bytes_disassembled == 0)
{
return false;
}
else
{
// We got some things disassembled...
size_t num_instructions = disassembler->GetInstructionList().GetSize();
uint32_t offset = 0;
SymbolContext sc;
SymbolContext prev_sc;
AddressRange sc_range;
if (num_mixed_context_lines)
strm.IndentMore ();
Address addr(range.GetBaseAddress());
// We extract the section to make sure we don't transition out
// of the current section when disassembling
const Section *addr_section = addr.GetSection();
Module *range_module = range.GetBaseAddress().GetModule();
for (size_t i=0; i<num_instructions; ++i)
{
Disassembler::Instruction *inst = disassembler->GetInstructionList().GetInstructionAtIndex (i);
if (inst)
{
addr_t file_addr = addr.GetFileAddress();
if (addr_section == NULL || addr_section->ContainsFileAddress (file_addr) == false)
{
if (range_module)
range_module->ResolveFileAddress (file_addr, addr);
else if (exe_ctx.target)
exe_ctx.target->GetImages().ResolveFileAddress (file_addr, addr);
addr_section = addr.GetSection();
}
prev_sc = sc;
if (addr_section)
{
Module *module = addr_section->GetModule();
uint32_t resolved_mask = module->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc);
if (resolved_mask)
{
if (prev_sc.function != sc.function || prev_sc.symbol != sc.symbol)
{
if (prev_sc.function || prev_sc.symbol)
strm.EOL();
strm << sc.module_sp->GetFileSpec().GetFilename();
if (sc.function)
strm << '`' << sc.function->GetMangled().GetName();
else if (sc.symbol)
strm << '`' << sc.symbol->GetMangled().GetName();
strm << ":\n";
}
//.........这里部分代码省略.........
示例15: GetStateVariable
void
CommandInterpreter::OutputFormattedHelpText (Stream &strm,
const char *word_text,
const char *separator,
const char *help_text,
uint32_t max_word_len)
{
StateVariable *var = GetStateVariable ("term-width");
int max_columns = var->GetIntValue();
// Sanity check max_columns, to cope with emacs shell mode with TERM=dumb
// (0 rows; 0 columns;).
if (max_columns <= 0) max_columns = 80;
int indent_size = max_word_len + strlen (separator) + 2;
strm.IndentMore (indent_size);
int len = indent_size + strlen (help_text) + 1;
char *text = (char *) malloc (len);
sprintf (text, "%-*s %s %s", max_word_len, word_text, separator, help_text);
if (text[len - 1] == '\n')
text[--len] = '\0';
if (len < max_columns)
{
// Output it as a single line.
strm.Printf ("%s", text);
}
else
{
// We need to break it up into multiple lines.
bool first_line = true;
int text_width;
int start = 0;
int end = start;
int final_end = strlen (text);
int sub_len;
while (end < final_end)
{
if (first_line)
text_width = max_columns - 1;
else
text_width = max_columns - indent_size - 1;
// Don't start the 'text' on a space, since we're already outputting the indentation.
if (!first_line)
{
while ((start < final_end) && (text[start] == ' '))
start++;
}
end = start + text_width;
if (end > final_end)
end = final_end;
else
{
// If we're not at the end of the text, make sure we break the line on white space.
while (end > start
&& text[end] != ' ' && text[end] != '\t' && text[end] != '\n')
end--;
}
sub_len = end - start;
if (start != 0)
strm.EOL();
if (!first_line)
strm.Indent();
else
first_line = false;
assert (start <= final_end);
assert (start + sub_len <= final_end);
if (sub_len > 0)
strm.Write (text + start, sub_len);
start = end + 1;
}
}
strm.EOL();
strm.IndentLess(indent_size);
free (text);
}