backward-cpp icon indicating copy to clipboard operation
backward-cpp copied to clipboard

Abstract stream support in printer classes

Open becrux opened this issue 7 years ago • 4 comments

This patch allows to create new printers based on custom streams.

becrux avatar Apr 27 '18 11:04 becrux

This is still a WIP, probably some code is redundant.

The change was originated by my need to use QTextStream class, in order to write the stacktrace in a QFile.

This should also start an implementation for the issue #26 .

becrux avatar Apr 27 '18 11:04 becrux

Why not keeping the printer API, but changing its backend to pick the right printer under the hood?

Printer printer;
printer.print(st, stdout); // uses legacy FILE backend
printer.print(st, std::cout); //Uses new std::ostream compatible backend

Manu343726 avatar Apr 29 '18 16:04 Manu343726

Also, I don't see any benefit of adding a printer singleton.

Manu343726 avatar Apr 29 '18 16:04 Manu343726

I need to use with Qt QTextStream, in order to dump a stacktrace in a QFile, I cannot use console. Anyway, I assume that hardcoding a stream technology, no matter what is, does not allow this library to be adapter to any other non-STL or non-STDIO context.

Regarding QTextStream, you cannot use STL I/O manipulators, and it does not fit as it is, that's why I tried to create an interface layer, without changing too much (well, I tried).

I was able to perform it with templates, but that required a singleton in my implementation to make everything fit each other. Virtual interfaces could be another approach, but it would have requested more changes IMHO.

becrux avatar Apr 29 '18 17:04 becrux