Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make print_**() methods' ostream argument templated #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions backward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4051,8 +4051,8 @@ class Printer {
TraceResolver _resolver;
SnippetFactory _snippets;

template <typename ST>
void print_stacktrace(ST &st, std::ostream &os, Colorize &colorize) {
template <typename ST, typename Ostream = std::ostream>
void print_stacktrace(ST &st, Ostream &os, Colorize &colorize) {
print_header(os, st.thread_id());
_resolver.load_stacktrace(st);
if ( reverse ) {
Expand All @@ -4066,24 +4066,26 @@ class Printer {
}
}

template <typename IT>
void print_stacktrace(IT begin, IT end, std::ostream &os, size_t thread_id,
template <typename IT, typename Ostream = std::ostream>
void print_stacktrace(IT begin, IT end, Ostream &os, size_t thread_id,
Colorize &colorize) {
print_header(os, thread_id);
for (; begin != end; ++begin) {
print_trace(os, *begin, colorize);
}
}

void print_header(std::ostream &os, size_t thread_id) {
template <typename Ostream = std::ostream>
void print_header(Ostream &os, size_t thread_id) {
os << "Stack trace (most recent call last)";
if (thread_id) {
os << " in thread " << thread_id;
}
os << ":\n";
}

void print_trace(std::ostream &os, const ResolvedTrace &trace,
template <typename Ostream = std::ostream>
void print_trace(Ostream &os, const ResolvedTrace &trace,
Colorize &colorize) {
os << "#" << std::left << std::setw(2) << trace.idx << std::right;
bool already_indented = true;
Expand Down Expand Up @@ -4121,7 +4123,8 @@ class Printer {
}
}

void print_snippet(std::ostream &os, const char *indent,
template <typename Ostream = std::ostream>
void print_snippet(Ostream &os, const char *indent,
const ResolvedTrace::SourceLoc &source_loc,
Colorize &colorize, Color::type color_code,
int context_size) {
Expand All @@ -4145,7 +4148,8 @@ class Printer {
}
}

void print_source_loc(std::ostream &os, const char *indent,
template <typename Ostream = std::ostream>
void print_source_loc(Ostream &os, const char *indent,
const ResolvedTrace::SourceLoc &source_loc,
void *addr = nullptr) {
os << indent << "Source \"" << source_loc.filename << "\", line "
Expand Down