Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

StDbXmlReader Class Reference

#include <StDbXmlReader.h>

Inheritance diagram for StDbXmlReader:

typeAcceptor List of all members.

Public Member Functions

 StDbXmlReader ()
virtual ~StDbXmlReader ()
void readTable (ifstream &is)
virtual void pass (char *name, short &i, int &len)
virtual void pass (char *name, int &i, int &len)
virtual void pass (char *name, long &i, int &len)
virtual void pass (char *name, unsigned short &i, int &len)
virtual void pass (char *name, unsigned int &i, int &len)
virtual void pass (char *name, unsigned long &i, int &len)
virtual void pass (char *name, long long &i, int &len)
virtual void pass (char *name, float &i, int &len)
virtual void pass (char *name, double &i, int &len)
virtual void pass (char *name, char *&i, int &len)
virtual void pass (char *name, unsigned char &i, int &len)
virtual void pass (char *name, unsigned char *&i, int &len)
virtual void pass (char *name, short *&i, int &len)
virtual void pass (char *name, int *&i, int &len)
virtual void pass (char *name, long *&i, int &len)
virtual void pass (char *name, unsigned short *&i, int &len)
virtual void pass (char *name, unsigned int *&i, int &len)
virtual void pass (char *name, unsigned long *&i, int &len)
virtual void pass (char *name, long long *&i, int &len)
virtual void pass (char *name, float *&i, int &len)
virtual void pass (char *name, double *&i, int &len)

Protected Member Functions

void buildDbTable ()
void buildStruct ()
void fillElements (accessor *a)
elemfindElement (char *name)

Protected Attributes

char * loca [20024]
dbTabletab
int maxlines

Constructor & Destructor Documentation

StDbXmlReader::StDbXmlReader  ) 
 

Definition at line 87 of file StDbXmlReader.cc.

00087 { tab = new dbTable(); }

StDbXmlReader::~StDbXmlReader  )  [virtual]
 

Definition at line 91 of file StDbXmlReader.cc.

00091 { delete tab; }


Member Function Documentation

void StDbXmlReader::buildDbTable  )  [protected]
 

Definition at line 182 of file StDbXmlReader.cc.

00182 { 00183 00184 int done = 0; 00185 int j=0; 00186 00187 // find table start 00188 while (!done) { 00189 if(strstr(loca[j],tab->startKey)){ 00190 tab->istart = j; 00191 done = 1; 00192 } 00193 j++; 00194 } 00195 00196 // find accessor start 00197 j=tab->istart+1; 00198 done = 0; 00199 while (!done) { 00200 // cout << loca[j] << endl; 00201 if(strstr(loca[j],(tab->a).startKey)){ 00202 (tab->a).istart = j; 00203 done = 1; 00204 } 00205 j++; 00206 } 00207 00208 // if(j>=maxlines)cout << "1 j to big " << j << " max= " << maxlines << endl; 00209 00210 elem* e0; 00211 elem *e = new elem(); // key holder 00212 // (tab->a).e.push_back(e) 00213 done = 0; 00214 int nelems = 0; 00215 j=(tab->a).istart+1; 00216 // if(j>=maxlines)cout << "2 j to big " << j << " max= " << maxlines << endl; 00217 while (!done) { 00218 if(strstr(loca[j],e->startKey)){ 00219 e0 = new elem(); 00220 e0->istart = j; 00221 (tab->a).e.push_back(e0); 00222 nelems++; 00223 if(strstr(loca[j],e->endKey))e0->iend = j; 00224 } else if(strstr(loca[j],e->endKey)){ 00225 e0->iend = j; 00226 } else if(strstr(loca[j],(tab->a).endKey)){ 00227 if(strstr(loca[j],e->endKey))e0->iend = j; 00228 (tab->a).iend = j; 00229 (tab->a).nelems = nelems; 00230 done = 1; 00231 } 00232 j++; 00233 } 00234 00235 // end of accessor 00236 // find all rows 00237 j=(tab->a).iend+1; 00238 // if(j>=maxlines)cout << "3 j to big " << j << " max= " << maxlines << endl; 00239 dbRow row; 00240 dbRow* row0; 00241 00242 done = 0; 00243 int numRows = 0; 00244 while (!done) { 00245 if(strstr(loca[j],row.startKey)){ 00246 row0 = new dbRow(); 00247 row0->istart = j; 00248 if(strstr(loca[j],row.endKey))row0->iend = j; 00249 tab->row.push_back(row0); 00250 row0->rowNumber = numRows; 00251 numRows++; 00252 } else if(strstr(loca[j],tab->endKey)){ 00253 tab->iend = j; 00254 tab->numRows = numRows; 00255 tab->curRow = -1; 00256 done = 1; 00257 } 00258 j++; 00259 } 00260 00261 // cout << "Numrows = " << numRows<< endl; 00262 // cout << "Current Row = " << tab->curRow << endl; 00263 // 00264 // Loop over rows 00265 // 00266 for(int nrows=0; nrows<tab->numRows; nrows++){ 00267 done = 0; 00268 nelems = 0; 00269 j=tab->row[nrows]->istart; 00270 while (!done) { 00271 // cout << loca[j] << endl; 00272 if(strstr(loca[j],e->startKey)){ 00273 e0 = new elem(); 00274 e0->istart = j; 00275 tab->row[nrows]->e.push_back(e0); 00276 nelems++; 00277 if(strstr(loca[j],e->endKey))e0->iend = j; 00278 // cout<<"estart"<< loca[j] <<endl; 00279 } else if(strstr(loca[j],e->endKey)){ 00280 e0->iend = j; 00281 // cout<<"eend"<< loca[j] <<endl; 00282 } else if(strstr(loca[j],row.endKey)){ 00283 tab->row[nrows]->nelems = nelems; 00284 done = 1; 00285 // cout<<"rowend"<< loca[j] <<endl; 00286 } 00287 j++; 00288 } 00289 } 00290 00291 buildStruct(); 00292 00293 }

void StDbXmlReader::buildStruct  )  [protected]
 

Definition at line 298 of file StDbXmlReader.cc.

00298 { 00299 00300 char * p1 = strstr(loca[tab->istart],tab->startKey); 00301 int len = strlen(tab->startKey); 00302 int k; 00303 for(k=0;k<len+1;k++)p1++; 00304 00305 char* tmpName = new char[strlen(p1)+1]; 00306 strcpy(tmpName,p1); 00307 char* id; 00308 00309 if((id=strstr(tmpName,"<")))*id='\0'; 00310 tab->name=new char[strlen(tmpName)+1]; 00311 strcpy(tab->name,tmpName); 00312 delete [] tmpName; 00313 00314 accessor * a = &(tab->a); 00315 fillElements(a); 00316 // a = (accessor*)(tab); 00317 00318 len = strlen(tab->row[0]->startKey); 00319 00320 for(int n=0; n<tab->numRows;n++){ 00321 00322 // 1st get rowID (elementID) of this row 00323 p1 = strstr(loca[tab->row[n]->istart],tab->row[n]->startKey); 00324 for(k=0;k<len+1;k++)p1++; 00325 tmpName = new char[strlen(p1)+1]; 00326 strcpy(tmpName,p1); 00327 if((id=strstr(tmpName,"<")))*id='\0'; 00328 tab->row[n]->rowID = atoi(tmpName); 00329 delete [] tmpName; 00330 00331 // now get row values 00332 00333 a = (accessor*)(tab->row[n]); 00334 fillElements(a); 00335 00336 } 00337 00338 }

void StDbXmlReader::fillElements accessor a  )  [protected]
 

Definition at line 343 of file StDbXmlReader.cc.

00343 { 00344 00345 elem* e; 00346 int len,j; 00347 char *p1,*p2,*hlen; 00348 int ilist; 00349 int iline; 00350 00351 for(int k=0;k<a->nelems;k++){ 00352 00353 e=a->e[k]; 00354 00355 // get Type 00356 00357 p1=strstr(loca[e->istart],e->startKey) + strlen(e->startKey); 00358 00359 p2=strstr(loca[e->istart],">"); 00360 len = strlen(p1) - strlen(p2); 00361 e->type = new char[len]; 00362 memcpy(e->type,p1,len); 00363 e->type[len]='\0'; 00364 00365 // get Name 00366 p2++; 00367 while(p2[0]==' ')p2++; 00368 p1 = strstr(p2,"<"); 00369 len = strlen(p2) - strlen(p1); 00370 e->name = new char[len]; 00371 memcpy(e->name,p2,len); 00372 e->name[len]='\0'; 00373 00374 // get size 00375 00376 p1=strstr(loca[e->istart],e->size.startKey); 00377 00378 if(p1){ 00379 p1+=strlen(e->size.startKey); 00380 p2=strstr(loca[e->istart],e->size.endKey); 00381 len = strlen(p1) - strlen(p2)+1; 00382 hlen = new char[len]; 00383 memcpy(hlen,p1,len); 00384 hlen[len-1]='\0'; 00385 e->size.isize = atoi(hlen); 00386 } 00387 if(e->size.isize==0)e->size.isize=1; // <length> not required for len=1 00388 00389 00390 // get values : if array it is on separate lines 00391 00392 p1=strstr(loca[e->istart],(e->val).startKey); 00393 if(p1){ 00394 // <element Type> ... <value> data </value> 00395 // </element Type> 00396 p1+=strlen((e->val).startKey); 00397 while(p1[0]==' ')p1++; 00398 p2=strstr(loca[e->istart],(e->val).endKey); 00399 len = strlen(p1) - strlen(p2); 00400 (e->val).data = new char[len]; 00401 memcpy((e->val).data,p1,len); 00402 (e->val).data[len]='\0'; 00403 } else { 00404 // <element Type> ... 00405 // <value> 00406 // data 00407 // data 00408 // </value> </element Type> 00409 ilist =e->iend - e->istart; 00410 iline =0; 00411 for(j=2;j<ilist;j++)iline += strlen(loca[e->istart+j]); 00412 StString fs; 00413 for(j=2;j<ilist;j++) fs<<loca[e->istart+j]; //<<endl; 00414 string fs2=fs.str(); 00415 e->val.data = new char[fs2.length()+1]; 00416 //cout << "TEST:: " << fullLine << " len = " << strlen(fullLine) << endl; 00417 strcpy(e->val.data,fs2.c_str()); 00418 00419 } 00420 00421 // cout << "Test:: " << endl; 00422 // cout << e->name << " "<<e->type << " " << e->val.data << endl; 00423 } 00424 00425 }

elem * StDbXmlReader::findElement char *  name  )  [protected]
 

Definition at line 95 of file StDbXmlReader.cc.

00095 { 00096 00097 elem* e = 0; 00098 elem* retVal = 0; 00099 00100 int k; 00101 // check accessor 1st 00102 // here it's a bit scary : if accessor element has same name as data-element 00103 if(tab->curRow==-1){ 00104 for(k=0;k<tab->a.nelems;k++){ 00105 e=tab->a.e[k]; 00106 if(strcmp(name,e->name)==0){ 00107 retVal=e; 00108 break; 00109 } 00110 } 00111 } 00112 00113 if(!retVal){ // now check rows 00114 if(tab->curRow==-1)tab->curRow=0; // init row 00115 if(tab->curRow==tab->numRows)return retVal; 00116 for(k=0;k<tab->row[tab->curRow]->nelems;k++){ 00117 // cout <<k<<" elements = " << tab->nelems << endl; 00118 e=tab->row[tab->curRow]->e[k]; 00119 if(strcmp(name,e->name)==0){ 00120 retVal=e; 00121 break; 00122 } 00123 } 00124 if(k==tab->row[tab->curRow]->nelems-1)tab->curRow++; 00125 } 00126 00127 return retVal; 00128 }

void StDbXmlReader::pass char *  name,
double *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 602 of file StDbXmlReader.cc.

00602 { 00603 00604 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00605 if(!strstr(e->type,"Double"))return; 00606 passAux(e,i,len); 00607 }

void StDbXmlReader::pass char *  name,
float *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 593 of file StDbXmlReader.cc.

00593 { 00594 00595 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00596 if(!strstr(e->type,"Float")) return; 00597 passAux(e,i,len); 00598 }

void StDbXmlReader::pass char *  name,
long long *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 573 of file StDbXmlReader.cc.

00573 { 00574 // 00575 cout<<"Not Yet Implemented"<<endl; 00576 }

void StDbXmlReader::pass char *  name,
unsigned long *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 582 of file StDbXmlReader.cc.

00582 { 00583 00584 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00585 if(!strstr(e->type,"ULong"))return; 00586 passAux(e,i,len); 00587 }

void StDbXmlReader::pass char *  name,
unsigned int *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 527 of file StDbXmlReader.cc.

00527 { 00528 00529 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00530 if(!strstr(e->type,"UInt"))return; 00531 passAux(e,i,len); 00532 }

void StDbXmlReader::pass char *  name,
unsigned short *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 493 of file StDbXmlReader.cc.

00493 { 00494 00495 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00496 if(!strstr(e->type,"UShort"))return; 00497 passAux(e,i,len); 00498 }

void StDbXmlReader::pass char *  name,
long *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 546 of file StDbXmlReader.cc.

00546 { 00547 00548 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00549 if(!strstr(e->type,"Long")) return; 00550 passAux(e,i,len); 00551 }

void StDbXmlReader::pass char *  name,
int *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 511 of file StDbXmlReader.cc.

00511 { 00512 00513 // cout << "In IntArray " << endl; 00514 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00515 if(!strstr(e->type,"Int")) return; 00516 passAux(e,i,len); 00517 }

void StDbXmlReader::pass char *  name,
short *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 473 of file StDbXmlReader.cc.

00473 { 00474 00475 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00476 if(!strstr(e->type,"Short"))return; 00477 passAux(e,i,len); 00478 }

void StDbXmlReader::pass char *  name,
unsigned char *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 450 of file StDbXmlReader.cc.

00451 { 00452 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00453 if(!strstr(e->type,"UChar")) return; 00454 passAux(e,i,len); 00455 }

void StDbXmlReader::pass char *  name,
unsigned char &  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 442 of file StDbXmlReader.cc.

00442 { 00443 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00444 if(strcmp(e->type,"Char")==0)i=atoi((e->val).data); 00445 }

void StDbXmlReader::pass char *  name,
char *&  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 431 of file StDbXmlReader.cc.

00431 { 00432 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00433 if(strcmp(e->type,"String")==0){ 00434 i=new char[strlen((e->val).data)+1]; 00435 strcpy(i,(e->val).data); 00436 } 00437 }

void StDbXmlReader::pass char *  name,
double &  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 619 of file StDbXmlReader.cc.

00619 { 00620 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00621 if(strcmp(e->type,"Double")==0)i=atof((e->val).data); 00622 00623 }

void StDbXmlReader::pass char *  name,
float &  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 611 of file StDbXmlReader.cc.

00611 { 00612 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00613 if(strcmp(e->type,"Float")==0)i=(float)atof((e->val).data); 00614 00615 }

void StDbXmlReader::pass char *  name,
long long &  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 564 of file StDbXmlReader.cc.

00564 { 00565 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00566 #ifndef __osf__ 00567 if(strcmp(e->type,"LongLong")==0)i=atoll((e->val).data); 00568 #else 00569 if(strcmp(e->type,"LongLong")==0)i=atol((e->val).data); 00570 #endif 00571 }

void StDbXmlReader::pass char *  name,
unsigned long &  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 556 of file StDbXmlReader.cc.

00556 { 00557 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00558 if(strcmp(e->type,"ULong")==0)i=atol((e->val).data); 00559 }

void StDbXmlReader::pass char *  name,
unsigned int &  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 519 of file StDbXmlReader.cc.

00519 { 00520 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00521 if(strcmp(e->type,"UInt")==0)i=atoi((e->val).data); 00522 }

void StDbXmlReader::pass char *  name,
unsigned short &  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 484 of file StDbXmlReader.cc.

00484 { 00485 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00486 if(strcmp(e->type,"UShort")==0)i=atoi((e->val).data); 00487 }

void StDbXmlReader::pass char *  name,
long &  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 537 of file StDbXmlReader.cc.

00537 { 00538 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00539 if(strcmp(e->type,"Long")==0)i=atol((e->val).data); 00540 }

void StDbXmlReader::pass char *  name,
int &  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 501 of file StDbXmlReader.cc.

00501 { 00502 // cout << "In Int " << endl; 00503 00504 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00505 if(strcmp(e->type,"Int")==0)i=atoi((e->val).data); 00506 }

void StDbXmlReader::pass char *  name,
short &  i,
int &  len
[virtual]
 

Implements typeAcceptor.

Definition at line 464 of file StDbXmlReader.cc.

00464 { 00465 elem* e = findElement(name); if(!e){ cerr<<name<<" not found"<<endl; return;} 00466 if(strcmp(e->type,"Short")==0)i=atoi((e->val).data); 00467 }

void StDbXmlReader::readTable ifstream &  is  ) 
 

Definition at line 135 of file StDbXmlReader.cc.

00135 { 00136 00137 int done = 0; 00138 int i = 0; 00139 int j,icount,k; 00140 char tmp[2]; 00141 char line[256]; 00142 char line2[256]; 00143 00144 while(!done){ 00145 if(is.eof()){ 00146 done = 1; 00147 } else { 00148 // cout << "line . " << i << endl; 00149 is.getline(line,255); 00150 k = strlen(line); 00151 j = 0; 00152 line2[j]='\0'; 00153 char* ptr=&line2[0]; 00154 for(icount=0;icount<k;icount++){ 00155 if(!(line[icount]==' ')){ 00156 *tmp=line[icount]; 00157 tmp[1]='\0'; 00158 j++; 00159 strncpy(ptr,tmp,1); 00160 ptr++; 00161 } 00162 } 00163 line2[j]='\0'; 00164 // cout << line << endl; 00165 loca[i] = new char[strlen(line2)+1]; 00166 strcpy(loca[i],line2); 00167 // cout << "line i = "<< loca[i] << endl; 00168 i++; 00169 } 00170 } 00171 00172 maxlines = i-1; 00173 00174 buildDbTable(); 00175 00176 }


Member Data Documentation

char* StDbXmlReader::loca[20024] [protected]
 

Definition at line 66 of file StDbXmlReader.h.

int StDbXmlReader::maxlines [protected]
 

Definition at line 68 of file StDbXmlReader.h.

dbTable* StDbXmlReader::tab [protected]
 

Definition at line 67 of file StDbXmlReader.h.


The documentation for this class was generated from the following files:
Generated on Thu Aug 24 14:46:09 2006 for Doxygen by doxygen 1.3.7