StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbXmlWriter.cc
1 /***************************************************************************
2  *
3  * $Id: StDbXmlWriter.cc,v 1.10 2016/05/27 16:26:23 dmitry Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: implement typeAcceptor for WRITING XML files of DB-tables
9  *
10  ***************************************************************************
11  *
12  * $Log: StDbXmlWriter.cc,v $
13  * Revision 1.10 2016/05/27 16:26:23 dmitry
14  * more coverity
15  *
16  * Revision 1.9 2016/05/26 15:15:30 dmitry
17  * unused variable in unused code - commented out
18  *
19  * Revision 1.8 2015/05/15 19:37:11 dmitry
20  * fixed type issue, as signed int was assumed
21  *
22  * Revision 1.7 2001/10/24 04:05:20 porter
23  * added long long type to I/O and got rid of obsolete dataIndex table
24  *
25  * Revision 1.6 2000/01/10 20:37:55 porter
26  * expanded functionality based on planned additions or feedback from Online work.
27  * update includes:
28  * 1. basis for real transaction model with roll-back
29  * 2. limited SQL access via the manager for run-log & tagDb
30  * 3. balance obtained between enumerated & string access to databases
31  * 4. 3-levels of diagnostic output: Quiet, Normal, Verbose
32  * 5. restructured Node model for better XML support
33  *
34  * Revision 1.5 1999/12/03 17:03:24 porter
35  * added multi-row support for the Xml reader & writer
36  *
37  * Revision 1.4 1999/09/30 02:06:12 porter
38  * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor)
39  * allow multiple rows (StDbTable), & Added the comment sections at top of
40  * each header and src file
41  *
42  **************************************************************************/
43 
44 #include "StDbXmlWriter.h"
45 #include "StDbTable.h"
46 
47 //----------------------------------------------------
48 
49 void
50 StDbXmlWriter::streamHeader(const char* name){
51  *os << "<StDbName>"<<name<< endl;
52 }
53 
54 //----------------------------------------------------
55 
56 void
57 StDbXmlWriter::streamAccessor(){
58  *os << "<StDbAccessor>" << endl;
59 }
60 
61 //----------------------------------------------------
62 
63 void
64 StDbXmlWriter::endAccessor(){
65  *os << "</StDbAccessor>" << endl;
66 }
67 
68 //----------------------------------------------------
69 
70 void
71 StDbXmlWriter::streamTail(){
72  *os << "</StDbName>" << endl;
73 }
74 
75 //----------------------------------------------------
76 
77 void
78 StDbXmlWriter::streamRow(int row){
79  *os << "<TabRow>" << row << endl;
80 }
81 
82 //----------------------------------------------------
83 
84 void
85 StDbXmlWriter::streamEndRow(){
86  *os << "</TabRow>" << endl;
87 }
88 //----------------------------------------------------
89 
90 void
91 StDbXmlWriter::streamTableName(const char* name){
92  *os << "<StDbTable>"<<name << endl;
93 }
94 //----------------------------------------------------
95 
96 void
97 StDbXmlWriter::streamEndTableName(){
98  *os << "</StDbTable>"<< endl;
99 }
100 
101 //----------------------------------------------------
102 
103 void
104 StDbXmlWriter::ioTable(StDbTable* table){
105 
106  char * name = table->getName();
107  streamTableName(name); delete [] name;
108  streamAccessor();
109  table->StreamAccessor((typeAcceptor*)this, false);
110  endAccessor();
111 
112  int k;
113  int nrows = 1;
114 // int* elements = table->getElementID(nrows);
115 
116 // if(!elements){
117 // elements = new int[nrows];
118 // for(k=0;k<nrows;k++)elements[k]=k;
119 // }
120 
121  table->setRowNumber(); // set to 0
122 
123  for(k=0;k<nrows;k++){
124  streamRow(k);
125  table->dbStreamer((typeAcceptor*)this, false);
126  streamEndRow();
127  }
128  streamEndTableName();
129 }
130 
131 //----------------------------------------------------
132 
133 void
134 StDbXmlWriter::pass(char* name, char*& i, int& len){
135 *os << "<dbString> "<<name<<" <value> "<< i <<" </value> </dbString>" << endl;
136 }
137 
138 //----------------------------------------------------
139 
140 void
141 StDbXmlWriter::pass(char* name, unsigned char& i, int& len){
142 *os << "<dbUChar> "<<name<<" <value> "<< (int)i <<" </value> </dbUChar>" << endl;
143 }
144 
145 //----------------------------------------------------
146 
147 void
148 StDbXmlWriter::pass(char* name, unsigned char*& i, int& len){
149  *os << "<dbUCharArray> " << name << " <length> ";
150  *os << len << " </length>" << endl;
151  *os << "<value>" << endl;
152 
153  int icount = 0;
154  for(int j=0; j<len-1;j++){
155  *os << (int)i[j] << ", ";
156  icount++;
157  if(icount==8){
158  *os << endl;
159  icount = 0;
160  }
161  }
162 
163  *os << (int)i[len-1] << endl;
164  *os << "</value> </dbUCharArray> " << endl;
165 }
166 
167 
168 //----------------------------------------------------
169 
170 void
171 StDbXmlWriter::pass(char* name, short& i, int& len){
172 *os << "<dbShort> "<<name<<" <value> "<< i <<" </value> </dbShort>" << endl;
173 }
174 
175 //----------------------------------------------------
176 
177 void
178 StDbXmlWriter::pass(char* name, short*& i, int& len){
179 
180  *os << "<dbShortArray> " << name << " <length> ";
181  *os << len << " </length>" << endl;
182  *os << "<value>" << endl;
183 
184  int icount = 0;
185  for(int j=0; j<len-1;j++){
186  *os << i[j] << ", ";
187  icount++;
188  if(icount==8){
189  *os << endl;
190  icount = 0;
191  }
192  }
193 
194  *os << i[len-1] << endl;
195  *os << "</value> </dbShortArray> " << endl;
196 }
197 
198 //----------------------------------------------------
199 
200 void
201 StDbXmlWriter::pass(char* name, unsigned short& i, int& len){
202 *os << "<dbUShort> "<<name<<" <value> "<< i <<" </value> </dbUShort>" << endl;
203 }
204 
205 //----------------------------------------------------
206 
207 void
208 StDbXmlWriter::pass(char* name, unsigned short*& i, int& len){
209 
210  *os << "<dbUShortArray> " << name << " <length> ";
211  *os << len << " </length>" << endl;
212  *os << "<value>" << endl;
213 
214  int icount = 0;
215  for(int j=0; j<len-1;j++){
216  *os << i[j] << ", ";
217  icount++;
218  if(icount==8){
219  *os << endl;
220  icount = 0;
221  }
222  }
223 
224  *os << i[len-1] << endl;
225  *os << "</value> </dbUShortArray> " << endl;
226 }
227 
228 //----------------------------------------------------
229 
230 void
231 StDbXmlWriter::pass(char* name, int& i, int& len){
232 *os << "<dbInt> "<<name<<" <value> "<< i <<" </value> </dbInt>" << endl;
233 }
234 
235 //----------------------------------------------------
236 
237 void
238 StDbXmlWriter::pass(char* name, int*& i, int& len){
239 
240  *os << "<dbIntArray> " << name << " <length> ";
241  *os << len << " </length>" << endl;
242  *os << "<value>" << endl;
243 
244  int icount = 0;
245  for(int j=0; j<len-1;j++){
246  *os << i[j] << ", ";
247  icount++;
248  if(icount==8){
249  *os << endl;
250  icount = 0;
251  }
252  }
253 
254  *os << i[len-1] << endl;
255  *os << "</value> </dbIntArray> " << endl;
256 }
257 
258 //----------------------------------------------------
259 
260 void
261 StDbXmlWriter::pass(char* name, unsigned int& i, int& len){
262 *os << "<dbUInt> "<<name<<" <value> "<< i <<" </value> </dbUInt>" << endl;
263 }
264 
265 //----------------------------------------------------
266 
267 void
268 StDbXmlWriter::pass(char* name, unsigned int*& i, int& len){
269 
270  *os << "<dbUIntArray> " << name << " <length> ";
271  *os << len << " </length>" << endl;
272  *os << "<value>" << endl;
273 
274  int icount = 0;
275  for(int j=0; j<len-1;j++){
276  *os << i[j] << ", ";
277  icount++;
278  if(icount==8){
279  *os << endl;
280  icount = 0;
281  }
282  }
283 
284  *os << i[len-1] << endl;
285  *os << "</value> </dbUIntArray> " << endl;
286 }
287 
288 //----------------------------------------------------
289 
290 void
291 StDbXmlWriter::pass(char* name, float& i, int& len){
292 *os << "<dbFloat> "<<name<<" <value> "<< i <<" </value> </dbFloat>" << endl;
293 }
294 
295 //----------------------------------------------------
296 
297 void
298 StDbXmlWriter::pass(char* name, float*& i, int& len){
299 
300  *os << "<dbFloatArray> " << name << " <length> ";
301  *os << len << " </length>" << endl;
302  *os << "<value>" << endl;
303 
304  int icount = 0;
305  for(int j=0; j<len-1;j++){
306  *os << i[j] << ", ";
307  icount++;
308  if(icount==8){
309  *os << endl;
310  icount = 0;
311  }
312  }
313 
314  *os << i[len-1] << endl;
315  *os << "</value> </dbFloatArray> " << endl;
316 }
317 
318 //----------------------------------------------------
319 
320 void
321 StDbXmlWriter::pass(char* name, double& i, int& len){
322 *os << "<dbDouble> "<<name<<" <value> "<< i <<" </value> </dbDouble>" << endl;
323 }
324 
325 //----------------------------------------------------
326 
327 void
328 StDbXmlWriter::pass(char* name, double*& i, int& len){
329 
330  *os << "<dbDoubleArray> " << name << " <length> ";
331  *os << len << " </length>" << endl;
332  *os << "<value>" << endl;
333 
334  int icount = 0;
335  for(int j=0; j<len-1;j++){
336  *os << i[j] << ", ";
337  icount++;
338  if(icount==8){
339  *os << endl;
340  icount = 0;
341  }
342  }
343 
344  *os << i[len-1] << endl;
345  *os << "</value> </dbDoubleArray> " << endl;
346 }
347 
348 //----------------------------------------------------
349 void
350 StDbXmlWriter::pass(char* name, long& i, int& len){
351 *os << "<dbLong> "<<name<<" <value> "<< i <<" </value> </dbLong>" << endl;
352 }
353 
354 //----------------------------------------------------
355 
356 void
357 StDbXmlWriter::pass(char* name, long*& i, int& len){
358 
359  *os << "<dbLongArray> " << name << " <length> ";
360  *os << len << " </length>" << endl;
361  *os << "<value>" << endl;
362 
363  int icount = 0;
364  for(int j=0; j<len-1;j++){
365  *os << i[j] << ", ";
366  icount++;
367  if(icount==8){
368  *os << endl;
369  icount = 0;
370  }
371  }
372 
373  *os << i[len-1] << endl;
374  *os << "</value> </dbLongArray> " << endl;
375 }
376 
377 //----------------------------------------------------
378 
379 void
380 StDbXmlWriter::pass(char* name, unsigned long& i, int& len){
381 *os << "<dbULong> "<<name<<" <value> "<< i <<" </value> </dbULong>" << endl;
382 }
383 void
384 StDbXmlWriter::pass(char* name, long long& i, int& len){
385 *os << "<dbLongLong> "<<name<<" <value> "<< i <<" </value> </dbLongLong>" << endl;
386 }
387 
388 //----------------------------------------------------
389 
390 void
391 StDbXmlWriter::pass(char* name, unsigned long*& i, int& len){
392 
393  *os << "<dbULongArray> " << name << " <length> ";
394  *os << len << " </length>" << endl;
395  *os << "<value>" << endl;
396 
397  int icount = 0;
398  for(int j=0; j<len-1;j++){
399  *os << i[j] << ", ";
400  icount++;
401  if(icount==8){
402  *os << endl;
403  icount = 0;
404  }
405  }
406 
407  *os << i[len-1] << endl;
408  *os << "</value> </dbULongArray> " << endl;
409 }
410 //----------------------------------------------------
411 
412 void
413 StDbXmlWriter::pass(char* name, long long*& i, int& len){
414 
415  *os << "<dbLongLongArray> " << name << " <length> ";
416  *os << len << " </length>" << endl;
417  *os << "<value>" << endl;
418 
419  int icount = 0;
420  for(int j=0; j<len-1;j++){
421  *os << i[j] << ", ";
422  icount++;
423  if(icount==8){
424  *os << endl;
425  icount = 0;
426  }
427  }
428 
429  *os << i[len-1] << endl;
430  *os << "</value> </dbLongLongArray> " << endl;
431 }
432 //----------------------------------------------------
433 
434 
435 
436 
437 
438 
439 
440 
441 
442 
443 
444 
445