From f49e4bb75978a3c784b576041b7cf548b2ca5bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Thu, 29 Nov 2012 19:43:08 +0100 Subject: [PATCH] Header::print() now takes the output stream as parameter --- dic/compdicmain.cpp | 2 +- dic/header.cpp | 36 ++++++++++++++++++------------------ dic/header.h | 2 +- dic/listdicmain.cpp | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/dic/compdicmain.cpp b/dic/compdicmain.cpp index f54eb6f..702eb3c 100644 --- a/dic/compdicmain.cpp +++ b/dic/compdicmain.cpp @@ -251,7 +251,7 @@ int main(int argc, char* argv[]) builder.generateDawg(inFileName, outFileName, dicName); // Print the header - header.print(); + header.print(cout); cout << fmt(_(" Load time: %1% s")) % builder.getLoadTime() << endl; cout << fmt(_(" Compression time: %1% s")) % builder.getBuildTime() << endl; diff --git a/dic/header.cpp b/dic/header.cpp index 96d0f1a..eed0d89 100644 --- a/dic/header.cpp +++ b/dic/header.cpp @@ -21,7 +21,7 @@ #include "config.h" #include // for strcpy -#include // for snprintf +#include // for sprintf #include #include #include @@ -649,30 +649,30 @@ wstring Header::writeDisplayAndInput() const } -void Header::print() const +void Header::print(ostream &out) const { #define fmt(x) boost::format(x) - cout << fmt(_("Dictionary name: %1%")) % lfw(m_dicName) << endl; + out << fmt(_("Dictionary name: %1%")) % lfw(m_dicName) << endl; char buf[150]; strftime(buf, sizeof(buf), "%c", gmtime(&m_compressDate)); - cout << fmt(_("Compressed on: %1%")) % buf << endl; - cout << fmt(_("Compressed using a binary compiled by: %1%")) % lfw(m_userHost) << endl; - cout << fmt(_("Dictionary type: %1%")) % (m_type == kDAWG ? "DAWG" : "GADDAG") << endl; - cout << fmt(_("Letters: %1%")) % lfw(m_letters) << endl; - cout << fmt(_("Number of letters: %1%")) % m_letters.size() << endl; - cout << fmt(_("Number of words: %1%")) % m_nbWords << endl; + out << fmt(_("Compressed on: %1%")) % buf << endl; + out << fmt(_("Compressed using a binary compiled by: %1%")) % lfw(m_userHost) << endl; + out << fmt(_("Dictionary type: %1%")) % (m_type == kDAWG ? "DAWG" : "GADDAG") << endl; + out << fmt(_("Letters: %1%")) % lfw(m_letters) << endl; + out << fmt(_("Number of letters: %1%")) % m_letters.size() << endl; + out << fmt(_("Number of words: %1%")) % m_nbWords << endl; long unsigned int size = sizeof(Dict_header_old) + sizeof(Dict_header_ext) + sizeof(Dict_header_ext_2); - cout << fmt(_("Header size: %1% bytes")) % size << endl; - cout << fmt(_("Root: %1% (edge)")) % m_root << endl; - cout << fmt(_("Nodes: %1% used + %2% saved")) % m_nodesUsed % m_nodesSaved << endl; - cout << fmt(_("Edges: %1% used + %2% saved")) % m_edgesUsed % m_edgesSaved << endl; + out << fmt(_("Header size: %1% bytes")) % size << endl; + out << fmt(_("Root: %1% (edge)")) % m_root << endl; + out << fmt(_("Nodes: %1% used + %2% saved")) % m_nodesUsed % m_nodesSaved << endl; + out << fmt(_("Edges: %1% used + %2% saved")) % m_edgesUsed % m_edgesSaved << endl; #undef fmt - cout << "====================================================================" << endl; - cout << format("%1% | %2% | %3% | %4% | %5% | %6% | %7%") + out << "====================================================================" << endl; + out << format("%1% | %2% | %3% | %4% | %5% | %6% | %7%") % _("Letter") % _("Points") % _("Frequency") % _("Vowel") % _("Consonant") % _("Display") % _("Alt. input") << endl; - cout << "-------+--------+-----------+-------+-----------+-------+------" << endl; + out << "-------+--------+-----------+-------+-----------+-------+------" << endl; #define sz(x) strlen(_(x)) for (unsigned int i = 0; i < m_letters.size(); ++i) { @@ -704,9 +704,9 @@ void Header::print() const { fmter % string(sz("Display"), ' ') % string(sz("Alt. input"), ' '); } - cout << fmter.str() << endl; + out << fmter.str() << endl; } #undef sz - cout << "====================================================================" << endl; + out << "====================================================================" << endl; } diff --git a/dic/header.h b/dic/header.h index 1d5bd61..3208b23 100644 --- a/dic/header.h +++ b/dic/header.h @@ -153,7 +153,7 @@ public: /** * Print a readable summary of the header on standard output */ - void print() const; + void print(ostream &out) const; /** * Write the header to a file, using the latest format diff --git a/dic/listdicmain.cpp b/dic/listdicmain.cpp index 3ee8a54..031f602 100644 --- a/dic/listdicmain.cpp +++ b/dic/listdicmain.cpp @@ -54,7 +54,7 @@ using namespace std; static void printHeader(const Dictionary &iDic) { - iDic.getHeader().print(); + iDic.getHeader().print(cout); }