00001 #include "AtlfastUtils/HeaderPrinter.h"
00002 #include <string>
00003 #include <iostream>
00004 #include <sstream>
00005
00006 namespace Atlfast {
00007 using std::string;
00008 using std::endl;
00009 using std::cout;
00010 using std::ostringstream;
00011
00012 unsigned int HeaderPrinter::width(80);
00013
00014 string HeaderPrinter::m_fullLine(width, '=');
00015 HeaderPrinter::HeaderPrinter(string title, MsgStream& log):
00016 m_title(title), m_log(log){
00017
00018
00019
00020 m_hollowLine+=string(1u,'|');
00021 m_hollowLine+=string(width-2,' ');
00022 m_hollowLine+=string(1u,'|');
00023 int nBlanks =width-m_title.size()-2;
00024 if(nBlanks>0){
00025 unsigned int lBlanks = (nBlanks%2==0)? nBlanks/2:1+nBlanks/2;
00026 unsigned int rBlanks = nBlanks/2;
00027 m_title=
00028 string(1u,'|')
00029 +string(lBlanks,' ')
00030 +m_title
00031 +string(rBlanks,' ')
00032 +string(1u,'|');
00033 }
00034 }
00035
00036 void HeaderPrinter::add(const string& s,
00037 std::vector<int>::const_iterator it,
00038 std::vector<int>::const_iterator en){
00039 ostringstream sout;
00040 sout<<s;
00041 for(; it !=en; ++it) sout << " " << (*it);
00042 m_strings.push_back(sout.str());
00043 }
00044
00045 void HeaderPrinter::add(const string&s , int i){
00046 ostringstream sout;
00047 sout << s << " " << i;
00048 m_strings.push_back(sout.str());
00049 }
00050
00051 void HeaderPrinter::add(const string& s, double d){
00052 ostringstream sout;
00053 sout << s << " " << d;
00054 m_strings.push_back(sout.str());
00055 }
00056
00057 void HeaderPrinter::add(const string& s1, const string& s2){
00058 string temp = s1+" "+s2;
00059 m_strings.push_back(temp);
00060 }
00061
00062 void HeaderPrinter::add(const string& s, bool b){
00063 string temp = s+" ";
00064 temp += b? "true":"false";
00065 m_strings.push_back(temp);
00066 }
00067
00068 void HeaderPrinter::add(const string& s){
00069 m_strings.push_back(s);
00070 }
00071
00072 void HeaderPrinter::print()const{
00073
00074 cout<<m_fullLine<<endl;
00075 cout<<m_hollowLine<<endl;
00076 cout<<m_title<<endl;
00077 cout<<m_hollowLine<<endl;
00078 std::vector<string>::const_iterator it = m_strings.begin();
00079 std::vector<string>::const_iterator en = m_strings.end();
00080
00081 for(;it!=en; ++it){
00082 string temp = *it;
00083 if(temp.size()<width-2){
00084 temp = string(1u,'|')+string(1u,' ')+temp;
00085 }
00086 while(temp.size()<width-1){
00087 temp += string(1u,' ');
00088 }
00089 temp += string(1u,'|');
00090 cout<<temp<<endl;
00091 }
00092 cout<<m_hollowLine<<endl;
00093 cout<<m_fullLine<<endl;
00094 cout<<endl<<endl;
00095 return;
00096 }
00097
00098 }
00099
00100
00101
00102
00103
00104
00105