KSquare Utilities
HTMLReport.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <fcntl.h>
6 
7 #include <string>
8 #include <iomanip>
9 #include <fstream>
10 #include <iostream>
11 #include <fstream>
12 #include <vector>
13 
14 #include "MemoryDebug.h"
15 #include "KKBaseTypes.h"
16 
17 
18 #include <sys/types.h>
19 #ifdef WIN32
20 #include <io.h>
21 #include <windows.h>
22 #else
23 //#include <sys/loadavg.h>
24 #include <unistd.h>
25 #endif
26 
27 
28 using namespace std;
29 using namespace KKB;
30 
31 #include "HTMLReport.h"
32 
33 
34 
36  KKStr _title,
37  AlignmentType _alignment
38  ):
39  curAlignment (_alignment),
40  fileName (_fileName),
41  opened (false),
42  r (),
43  title (_title)
44 {
45  r.open (fileName.Str (), std::ios_base::out);
46  opened = true;
47 
48  r << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" << std::endl
49  << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << std::endl
50  << "<head>" << std::endl
51  << "<title>" << title << "</title>" << std::endl
52  << "</head>" << std::endl
53  << "<body " << CurStyleStr () << ">" << std::endl;
54 }
55 
56 
57 
58 
59 KKStr HTMLReport::CurStyleStr ()
60 {
61  KKStr styleStr = "stype=\"";
62 
63  styleStr << "text-align:";
64 
65  switch (curAlignment)
66  {
67  case AlignmentType::Left: styleStr << "left"; break;
68  case AlignmentType::Center: styleStr << "center"; break;
69  case AlignmentType::Right: styleStr << "right"; break;
70  }
71 
72  styleStr << "\"";
73 
74  return styleStr;
75 } /* CurStyleStr */
76 
77 
78 
79 
81 {
82  if (opened)
83  Close ();
84 }
85 
86 
87 
88 void HTMLReport::Append (const char* str)
89 {
90  r << str;
91 }
92 
93 
94 
95 void HTMLReport::Close ()
96 {
97  if (opened)
98  {
99  r.close ();
100  opened = false;
101  }
102 }
103 
104 
105 
106 HTMLReport& KKB::operator<< (HTMLReport& htmlReport,
107  kkint32 right
108  )
109 {
110  KKStr s (30);
111  s = StrFormatInt (right, "0");
112  htmlReport.Append (s.Str ());
113  return htmlReport;
114 }
115 
116 
117 
118 HTMLReport& KKB::operator<< (HTMLReport& htmlReport,
119  kkuint32 right
120  )
121 {
122  KKStr s (30);
123  s = StrFormatInt (right, "0");
124  htmlReport.Append (s.Str ());
125  return htmlReport;
126 }
127 
128 
129 
130 HTMLReport& KKB::operator<< (HTMLReport& htmlReport,
131  kkint64 right
132  )
133 {
134  KKStr s (30);
135  s = StrFormatInt64 (right, "0");
136  htmlReport.Append (s.Str ());
137  return htmlReport;
138 }
139 
140 
141 
142 HTMLReport& KKB::operator<< (HTMLReport& htmlReport,
143  kkuint64 right
144  )
145 {
146  KKStr s (30);
147  s = StrFormatInt64 (right, "0");
148  htmlReport.Append (s.Str ());
149  return htmlReport;
150 }
151 
152 
153 
154 HTMLReport& KKB::operator<< (HTMLReport& htmlReport,
155  double right
156  )
157 {
158  char buff[50];
159 
160 # ifdef USE_SECURE_FUNCS
161  sprintf_s (buff, sizeof (buff), "%f", right);
162 # else
163  sprintf (buff, "%f", right);
164 # endif
165 
166  htmlReport.Append (buff);
167  return htmlReport;
168 }
169 
170 
171 
172 HTMLReport& KKB::operator<< (HTMLReport& htmlReport,
173  char right
174  )
175 {
176  char buff[20];
177  buff[0] = right;
178  buff[1] = 0;
179  htmlReport.Append (buff);
180  return htmlReport;
181 }
182 
183 
184 
185 HTMLReport& KKB::operator<< (HTMLReport& htmlReport,
186  const char* right
187  )
188 {
189  htmlReport.Append (right);
190  return htmlReport;
191 }
192 
193 
194 
195 
196 HTMLReport& KKB::operator<< (HTMLReport& htmlReport,
197  const KKStr& right
198  )
199 {
200  htmlReport.Append (right.Str ());
201  return htmlReport;
202 }
203 
204 
205 
206 
207 HTMLReport& KKB::operator<< (HTMLReport& htmlReport,
208  KKStrConstPtr right
209  )
210 {
211  if (right)
212  htmlReport.Append (right->Str ());
213  return htmlReport;
214 }
215 
216 
217 
218 HTMLReport& KKB::operator<< (HTMLReport& htmlReport,
219  const DateTime& right
220  )
221 {
222  KKStr s = right.Date ().YYYY_MM_DD () + "-" + right.Time ().HH_MM_SS ();
223  htmlReport.Append (s.Str ());
224  return htmlReport;
225 }
226 
227 
228 
229 
230 HTMLReport& __cdecl KKB::operator<< (KKB::HTMLReport& htmlReport,
231  KKB::HTMLReport& (__cdecl* mf)(KKB::HTMLReport &)
232  )
233 {
234  mf (htmlReport);
235  return htmlReport;
236 }
237 
238 
239 
240 HTMLReport& __cdecl KKB::endl (HTMLReport & htmlReport)
241 {
242  htmlReport.Append ("\n");
243  return htmlReport;
244 }
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for &#39;size&#39; characters.
Definition: KKStr.cpp:655
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
KKStr StrFormatInt64(kkint64 val, const char *mask)
Definition: KKStr.cpp:5013
__int32 kkint32
Definition: KKBaseTypes.h:88
KKStr HH_MM_SS() const
Definition: DateTime.cpp:841
HTMLReport(KKStr _fileName, KKStr _title, AlignmentType _alignment)
Definition: HTMLReport.cpp:35
KKStr YYYY_MM_DD() const
Convert into displayable string; ex: 20011/05/17.
Definition: DateTime.cpp:701
KKStr operator+(const char *right) const
Definition: KKStr.cpp:3986
void Append(const char *str)
Definition: HTMLReport.cpp:88
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
__int64 kkint64
Definition: KKBaseTypes.h:90
KKStr & operator=(KKStr &&src)
Definition: KKStr.cpp:1369
const KKB::DateType & Date() const
Definition: DateTime.h:230
KKTHread * KKTHreadPtr
KKStr(const KKStr &str)
Copy Constructor.
Definition: KKStr.cpp:561
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
unsigned __int64 kkuint64
Definition: KKBaseTypes.h:91
KKStr StrFormatInt(kkint32 val, const char *mask)
Definition: KKStr.cpp:5004
KKStr operator+(const KKStr &right) const
Definition: KKStr.cpp:3998
const char * Str() const
Returns a pointer to a ascii string.
Definition: KKStr.h:422
HTMLReport &__cdecl operator<<(HTMLReport &htmlReport, HTMLReport &(__cdecl *mf)(HTMLReport &))
Definition: HTMLReport.cpp:230
const TimeType & Time() const
Definition: DateTime.h:232