00001
00002
00003 #include "Analyze.h"
00004
00005 #include <iomanip>
00006 using namespace std;
00007
00008 bool Analyze::s_showperc = false;
00009
00010
00011
00012 Analyze::Analyze(const Tuple& t, const string& itemname, const string& name)
00013 : m_count(0),m_tupleItem(t.tupleItem(itemname)), m_name(name), m_seen(0) {}
00014
00015 Analyze::Analyze(const TupleItem& item, const string& name)
00016 : m_count(0), m_tupleItem(&item), m_name(name), m_seen(0) {}
00017
00018 void Analyze::report(ostream& out)
00019 {
00020 out << endl << make_label(name());
00021 out << setw(6) << count();
00022 if (showperc()) {
00023 float cnt = static_cast<float>(count()), sen = static_cast<float>(seen());
00024 out << " | " << setprecision(3) << ((sen == 0.) ? 0. : 100.*cnt/sen) << '%';
00025 }
00026 }
00027
00028 string Analyze::make_label(const string& in)
00029 {
00030 const unsigned col = 24;
00031 string namestr(in);
00032 if (namestr.length() < col) namestr.insert(namestr.begin(),col - namestr.length(),' ');
00033 namestr += " : ";
00034 return namestr ;
00035 }
00036
00037 void Analyze::separator(ostream& out, char s)
00038 {
00039 out << "\n" << string(55, s );
00040 }
00041
00042 void Analyze::set_tuple_item(const Tuple& t, std::string item_name)
00043 {
00044 m_tupleItem = t.tupleItem(item_name);
00045 }