1 |
|
2 |
#include "table.h"
|
3 |
|
4 |
std::ostream& operator<<( std::ostream& os, const TTable& tab )
|
5 |
{
|
6 |
if (tab.GetTable()->size()==0) return os;
|
7 |
std::string delimiter = tab.GetDelimiter();
|
8 |
bool tex = (tab.GetStyle()==TTable::TeX);
|
9 |
if (tab.GetHeader()!="") os<<tab.GetHeader()<<std::endl;
|
10 |
if (tex) {
|
11 |
delimiter = " & ";
|
12 |
os << "\\begin{tabular}{";
|
13 |
for (unsigned i=0; i<tab.GetTable()->size(); ++i) os << "c";
|
14 |
os << "}" <<std::endl;
|
15 |
}
|
16 |
|
17 |
std::vector<TColumnBase*>::const_iterator it=tab.GetTable()->begin();
|
18 |
os<<std::setw((*it)->Width())<<(*it)->GetHeader();
|
19 |
++it;
|
20 |
for (;it!=tab.GetTable()->end();++it){
|
21 |
os <<delimiter<<std::setw((*it)->Width())<<(*it)->GetHeader();
|
22 |
}
|
23 |
if (!tex) {
|
24 |
it=tab.GetTable()->begin();
|
25 |
os.fill('-');
|
26 |
os<<std::endl<<std::setw((*it)->Width())<<"";
|
27 |
++it;
|
28 |
for (;it!=tab.GetTable()->end();++it){
|
29 |
os << "+" << std::setw((*it)->Width()) << "";
|
30 |
}
|
31 |
os.fill(' ');
|
32 |
} else
|
33 |
os<<"\\\\ \\hline";
|
34 |
os<<std::endl;
|
35 |
for (unsigned l=0; l<tab.Length(); ++l){
|
36 |
it=tab.GetTable()->begin();
|
37 |
os<<(*it++)->Str(l);
|
38 |
for (;it!=tab.GetTable()->end();++it){
|
39 |
os <<delimiter<<(*it)->Str(l);
|
40 |
}
|
41 |
if (tex) os<<"\\\\";
|
42 |
os<<std::endl;
|
43 |
}
|
44 |
if (!tex && tab.GetCaption()!="")
|
45 |
os<<tab.GetCaption()<<std::endl;
|
46 |
if (tex) {
|
47 |
os<<"\\label{tab:xyz}"<<std::endl;
|
48 |
if (tab.GetCaption()!="") os<<"\\caption{"<<tab.GetCaption()<<"}"<<std::endl;
|
49 |
os<<"\\end{tabular}"<<std::endl;
|
50 |
}
|
51 |
return os;
|
52 |
}
|
53 |
|