11#include " ConsoleExporter.h"
2+ #include " FileExporter.h"
23
34#include < iostream>
4- #include < sstream>
55
6- ConsoleExporter::ConsoleExporter (const Options& options) {
7- std::streambuf* buf;
8- std::streambuf* logbuf;
9- if (options.GetOutputFilename () == " -" ) {
10- buf = std::cout.rdbuf ();
11- if (options.GetOutputXml () || options.GetOutputJSON ()) {
12- logbuf = 0 ;
13- } else {
14- logbuf = std::cout.rdbuf ();
15- }
16- } else {
17- m_of.open (options.GetOutputFilename ().c_str (), std::ios::out | std::ios::binary);
18- buf = m_of.rdbuf ();
19- logbuf = std::cout.rdbuf ();
20- }
21-
22- m_out = std::make_shared<std::ostream>(buf);
23- m_log = std::make_shared<std::ostream>(logbuf);
24- std::ostream out (buf);
25- std::ostream log (logbuf);
26- if (!out) {
27- std::ostringstream stream;
28- stream
29- << " Error: Can't open file: "
30- << options.GetOutputFilename ()
31- << std::endl;
32- throw std::runtime_error (stream.str ().c_str ());
33- }
6+ ConsoleExporter::ConsoleExporter (const Options& options)
7+ : FileExporter(options, true ) {
348}
359
3610void ConsoleExporter::LogMessage (const std::string& message) {
37- (*m_log ) << message << std::flush;
11+ Log ( ) << message << std::flush;
3812}
3913
4014void ConsoleExporter::WriteHeader () {}
@@ -43,7 +17,7 @@ void ConsoleExporter::WriteFooter(
4317 int files,
4418 long locsTotal,
4519 const ProcessResult& processResult) {
46- (*m_out )
20+ Out ( )
4721 << " Configuration:"
4822 << std::endl
4923 << " Number of files: "
@@ -83,17 +57,17 @@ void ConsoleExporter::ReportSeq(
8357 int count,
8458 const SourceFile& source1,
8559 const SourceFile& source2) {
86- (*m_out )
60+ Out ( )
8761 << source1.GetFilename ()
8862 << " (" << source1.GetLine (line1).GetLineNumber () << " )"
8963 << std::endl;
90- (*m_out )
64+ Out ( )
9165 << source2.GetFilename ()
9266 << " (" << source2.GetLine (line2).GetLineNumber () << " )"
9367 << std::endl;
9468 for (int j = 0 ; j < count; j++) {
95- (*m_out ) << source1.GetLine (j + line1).GetLine () << std::endl;
69+ Out ( ) << source1.GetLine (j + line1).GetLine () << std::endl;
9670 }
9771
98- (*m_out ) << std::endl;
72+ Out ( ) << std::endl;
9973}
0 commit comments