ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/sandbox/nice_chart.C
Revision: 1.1
Committed: Wed Jun 22 11:07:16 2011 UTC (13 years, 10 months ago) by buchmann
Content type: text/plain
Branch: MAIN
CVS Tags: cbaf_4_98ifb_paper, beforeFR20120418, cbaf_4p7ifb, Honeypot, cbaf_2p1ifb, HEAD
Error occurred while calculating annotation data.
Log Message:
Initial commit of Plotting tools

File Contents

# Content
1 #include <iostream>
2 #include <vector>
3 #include <sstream>
4
5 using namespace std;
6
7 int write_first_line(vector<vector<string> > &entries) {
8 if(entries.size()>0) {
9 vector<string> firstline = entries[0];
10 int ncolumns=firstline.size();
11 int ndividers=ncolumns+1;
12 int cellwidth=(int)(((float)(60-ndividers))/(ncolumns));
13 cout << " |";
14 for(int idiv=0;idiv<ncolumns;idiv++) {
15 for(int isig=0;isig<cellwidth;isig++) cout << "-";
16 cout << "|";
17 }
18 cout << endl;
19 return ncolumns;
20 } else {
21 return 0;
22 }
23 }
24
25 void write_entry(string entry,int width) {
26 int currwidth=entry.size();
27 while(currwidth<width) {
28 entry=" "+entry;
29 if(entry.size()<width) entry=entry+" ";
30 currwidth=entry.size();
31 }
32 cout << entry << "|";
33 }
34
35 void make_nice_table(vector<vector <string> > &entries) {
36 int ncolumns=write_first_line(entries);
37 int cellwidth=(int)(((float)(60-(ncolumns+1)))/(ncolumns));
38 for(int iline=0;iline<entries.size();iline++) {
39 vector<string> currline = entries[iline];
40 cout << " |";
41 for(int ientry=0;ientry<currline.size();ientry++) {
42 write_entry(currline[ientry],cellwidth);
43 }
44 cout << endl;
45 if(iline==0) write_first_line(entries);
46 }
47 write_first_line(entries);
48 }
49
50 int main() {
51 cout << "ok let's have a go at this" << endl;
52 vector<vector<string> > entries;
53 vector<string> hello;
54 hello.push_back("abc");
55 hello.push_back("b");
56 hello.push_back("cef");
57 entries.push_back(hello);
58 hello.clear();
59 hello.push_back("d");
60 hello.push_back("egh");
61 hello.push_back("f");
62 entries.push_back(hello);
63 hello.clear();
64 hello.push_back("d");
65 hello.push_back("");
66 hello.push_back("f");
67 entries.push_back(hello);
68 make_nice_table(entries);
69 return 0;
70 }
71
72