forked from h2gglobe/h2gglobe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HtmlHelper.h
235 lines (181 loc) · 4.44 KB
/
HtmlHelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#ifndef HtmlHelper_h
#define HtmlHelper_h
#include <string>
#include <sstream>
#include <list>
#include <map>
#include "TCanvas.h"
/**
*
*
*/
class HtmlObject
{
public:
HtmlObject();
virtual ~HtmlObject();
virtual void render(std::ostream &) = 0;
HtmlObject & set(const std::string&, const std::string&);
template<class T> T & add(T * obj) {
objects_.push_back((HtmlObject*)obj);
return *obj;
}
HtmlObject & addobj(HtmlObject * obj) {
objects_.push_back((HtmlObject*)obj);
return *obj;
}
template<class T> HtmlObject & operator << (const T & t) {
text_ << t;
return *this;
}
HtmlObject & txt(const std::string & st) {
*this << st;
return *this;
}
void own(bool x) { own_ = x; }
bool own() { return own_; }
HtmlObject & firstChild() { return objects_.empty() ? *this : *(*objects_.begin()); }
protected:
std::string indent();
std::string unindent();
static int indent_;
bool own_;
std::stringstream text_;
std::list<HtmlObject *> objects_;
std::list<std::pair<std::string,std::string> > attributes_;
};
std::ostream & operator << ( std::ostream &, HtmlObject & );
std::ostream & operator << ( std::ostream &, HtmlObject * );
std::ostream & operator << ( std::ostream &, const std::list<HtmlObject *> & );
/**
*
*
*/
class HtmlHeader : public HtmlObject
{
public:
HtmlHeader(const std::string & title="", const std::string & author="");
virtual ~HtmlHeader();
void render(std::ostream &);
private:
std::string title_;
std::string author_;
};
/**
*
*
*/
class HtmlBody : public HtmlObject
{
public:
HtmlBody();
virtual ~HtmlBody();
void render(std::ostream &);
};
/**
*
*
*/
class HtmlTag : public HtmlObject
{
public:
HtmlTag(const std::string& tag);
virtual ~HtmlTag();
void render(std::ostream &);
private:
std::string tag_;
};
/**
*
*
*/
class HtmlPlot : public HtmlObject {
public:
HtmlPlot(TCanvas *, bool remove=false, const std::string& name = "", bool pdf=true, bool macro=false, bool root=false);
virtual ~HtmlPlot();
void caption(const std::string &);
void render(std::ostream &);
private:
TCanvas * canvas_;
bool remove_;
std::string name_;
std::string caption_;
bool pdf_, macro_, root_;
};
/**
*
*
*/
class HtmlTable : public HtmlObject
{
public:
HtmlTable();
virtual ~HtmlTable();
void render(std::ostream &);
class Cell : public HtmlObject {
public:
Cell(HtmlObject * obj);
virtual ~Cell();
void render(std::ostream &);
};
class Row : public HtmlObject {
public:
Row();
virtual ~Row();
Cell & cell(HtmlObject * obj=0);
void render(std::ostream &);
};
Row & row();
HtmlTag & tbody() { return * tbody_; }
private:
HtmlTag * tbody_;
};
/**
*
*
*/
class HtmlHelper : public HtmlObject
{
public:
HtmlHelper(const std::string& dirname, const std::string& fname="index.html");
virtual ~HtmlHelper();
void dump(bool mkdir=true);
HtmlHeader & header() { return header_; }
HtmlBody & body() { return body_ ; }
HtmlTable::Row & navbar() { return *navbar_; }
HtmlHelper & addPage(const std::string& name);
HtmlPlot * makePlot(TCanvas *c, bool remove=false, const std::string& name = "", bool pdf=true, bool macro=false, bool root=false);
void render(std::ostream &);
private:
std::string dirname_;
std::string filename_;
HtmlHeader header_;
HtmlBody body_;
HtmlTable::Row * navbar_;
std::list<HtmlHelper*> subpages_;
};
template HtmlHeader & HtmlObject::add<HtmlHeader >(HtmlHeader*);
template HtmlBody & HtmlObject::add<HtmlBody >(HtmlBody *);
template HtmlPlot & HtmlObject::add<HtmlPlot >(HtmlPlot *);
template HtmlTable & HtmlObject::add<HtmlTable >(HtmlTable *);
template HtmlTable::Row & HtmlObject::add<HtmlTable::Row >(HtmlTable::Row *);
template HtmlTable::Cell& HtmlObject::add<HtmlTable::Cell>(HtmlTable::Cell *);
template HtmlHelper & HtmlObject::add<HtmlHelper >(HtmlHelper*);
template HtmlObject & HtmlObject::operator<< (const std::string & );
#ifdef __CINT__
#pragma link C++ class HtmlObject;
#pragma link C++ class HtmlHeader;
#pragma link C++ class HtmlTag ;
#pragma link C++ class HtmlBody ;
#pragma link C++ class HtmlPlot ;
#pragma link C++ class HtmlTable ;
#pragma link C++ class HtmlTable::Row ;
#pragma link C++ class HtmlTable::Cell;
#pragma link C++ class HtmlHelper;
#endif
#endif
// Local Variables:
// mode: c++
// mode: sensitive
// c-basic-offset: 8
// End: