84 #include "StDbXmlReader.h"
85 #include "stdb_streams.h"
88 #include "dbStruct.hh"
90 #ifndef __STDB_STANDALONE__
91 #include "StMessMgr.h"
93 #define LOG_DEBUG cout
96 #define LOG_ERROR cerr
97 #define LOG_FATAL cerr
103 static void passAux(
elem* e, T*& i,
int& len)
107 memset(i,0,
sizeof(T)*len);
108 const char* p1 = e->val.data;
112 if (p2[0] && p2[0]!=
',')
continue;
113 i[iloop++] = (T)atof(p1);
115 if (iloop==len || p2[0]==0)
break;
120 StDbXmlReader::StDbXmlReader(){ tab =
new dbTable(); }
124 StDbXmlReader::~StDbXmlReader() {
delete tab; }
128 StDbXmlReader::findElement(
char* name){
137 for(k=0;k<tab->a.nelems;k++){
139 if(strcmp(name,e->name)==0){
147 if(tab->curRow==-1)tab->curRow=0;
148 if(tab->curRow==tab->numRows)
return retVal;
149 for(k=0;k<tab->row[tab->curRow]->nelems;k++){
151 e=tab->row[tab->curRow]->e[k];
152 if(strcmp(name,e->name)==0){
157 if(k==tab->row[tab->curRow]->nelems-1)tab->curRow++;
168 StDbXmlReader::readTable(ifstream &is){
182 is.getline(line,255);
187 for(icount=0;icount<k;icount++){
188 if(!(line[icount]==
' ')){
198 loca[i] =
new char[strlen(line2)+1];
199 strcpy(loca[i],line2);
215 StDbXmlReader::buildDbTable(){
222 if(strstr(loca[j],tab->startKey)){
234 if(strstr(loca[j],(tab->a).startKey)){
251 if(strstr(loca[j],e->startKey)){
254 (tab->a).e.push_back(e0);
256 if(strstr(loca[j],e->endKey))e0->iend = j;
257 }
else if(strstr(loca[j],e->endKey)){
259 }
else if(strstr(loca[j],(tab->a).endKey)){
260 if(strstr(loca[j],e->endKey))e0->iend = j;
262 (tab->a).nelems = nelems;
278 if(strstr(loca[j],row.startKey)){
281 if(strstr(loca[j],row.endKey))row0->iend = j;
282 tab->row.push_back(row0);
283 row0->rowNumber = numRows;
285 }
else if(strstr(loca[j],tab->endKey)){
287 tab->numRows = numRows;
299 for(
int nrows=0; nrows<tab->numRows; nrows++){
302 j=tab->row[nrows]->istart;
305 if(strstr(loca[j],e->startKey)){
308 tab->row[nrows]->e.push_back(e0);
310 if(strstr(loca[j],e->endKey))e0->iend = j;
312 }
else if(strstr(loca[j],e->endKey)){
315 }
else if(strstr(loca[j],row.endKey)){
316 tab->row[nrows]->nelems = nelems;
331 StDbXmlReader::buildStruct(){
333 char * p1 = strstr(loca[tab->istart],tab->startKey);
334 int len = strlen(tab->startKey);
336 for(k=0;k<len+1;k++)p1++;
338 char* tmpName =
new char[strlen(p1)+1];
342 if((
id=strstr(tmpName,
"<")))*
id=
'\0';
343 tab->name=
new char[strlen(tmpName)+1];
344 strcpy(tab->name,tmpName);
351 len = strlen(tab->row[0]->startKey);
353 for(
int n=0; n<tab->numRows;n++){
356 p1 = strstr(loca[tab->row[n]->istart],tab->row[n]->startKey);
357 for(k=0;k<len+1;k++)p1++;
358 tmpName =
new char[strlen(p1)+1];
360 if((
id=strstr(tmpName,
"<")))*
id=
'\0';
361 tab->row[n]->rowID = atoi(tmpName);
376 StDbXmlReader::fillElements(
accessor* a){
380 char *p1 = 0, *p2 = 0, *hlen = 0;
384 for(
int k=0;k<a->nelems;k++){
390 p1=strstr(loca[e->istart],e->startKey) + strlen(e->startKey);
392 p2=strstr(loca[e->istart],
">");
393 len = strlen(p1) - strlen(p2);
394 e->type =
new char[len+1];
395 memcpy(e->type,p1,len);
400 while(p2[0]==
' ')p2++;
402 len = strlen(p2) - strlen(p1);
403 e->name =
new char[len+1];
404 memcpy(e->name,p2,len);
409 p1=strstr(loca[e->istart],e->size.startKey);
412 p1+=strlen(e->size.startKey);
413 p2=strstr(loca[e->istart],e->size.endKey);
414 len = strlen(p1) - strlen(p2)+1;
415 hlen =
new char[len+1];
418 e->size.isize = atoi(hlen);
421 if(e->size.isize==0)e->size.isize=1;
426 p1=strstr(loca[e->istart],(e->val).startKey);
430 p1+=strlen((e->val).startKey);
431 while(p1[0]==
' ')p1++;
432 p2=strstr(loca[e->istart],(e->val).endKey);
433 len = strlen(p1) - strlen(p2);
434 (e->val).
data =
new char[len];
435 memcpy((e->val).data,p1,len);
436 (e->val).
data[len]=
'\0';
443 ilist =e->iend - e->istart;
445 for(j=2;j<ilist;j++)iline += strlen(loca[e->istart+j]);
447 for(j=2;j<ilist;j++) fs<<loca[e->istart+j];
449 e->val.data =
new char[fs2.length()+1];
451 strcpy(e->val.data,fs2.c_str());
465 StDbXmlReader::pass(
char* name,
char*& i,
int& len){
466 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
467 if(strcmp(e->type,
"String")==0){
468 i=
new char[strlen((e->val).data)+1];
469 strcpy(i,(e->val).data);
476 StDbXmlReader::pass(
char* name,
unsigned char& i,
int& len){
477 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
478 if(strcmp(e->type,
"Char")==0)i=atoi((e->val).data);
484 StDbXmlReader::pass(
char* name,
unsigned char*& i,
int& len)
486 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
487 if(!strstr(e->type,
"UChar"))
return;
498 StDbXmlReader::pass(
char* name,
short& i,
int& len){
499 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
500 if(strcmp(e->type,
"Short")==0)i=atoi((e->val).data);
507 StDbXmlReader::pass(
char* name,
short*& i,
int& len){
509 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
510 if(!strstr(e->type,
"Short"))
return;
518 StDbXmlReader::pass(
char* name,
unsigned short& i,
int& len){
519 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
520 if(strcmp(e->type,
"UShort")==0)i=atoi((e->val).data);
527 StDbXmlReader::pass(
char* name,
unsigned short*& i,
int& len){
529 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
530 if(!strstr(e->type,
"UShort"))
return;
535 StDbXmlReader::pass(
char* name,
int& i,
int& len){
538 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
539 if(strcmp(e->type,
"Int")==0)i=atoi((e->val).data);
545 StDbXmlReader::pass(
char* name,
int*& i,
int& len){
548 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
549 if(!strstr(e->type,
"Int"))
return;
553 StDbXmlReader::pass(
char* name,
unsigned int& i,
int& len){
554 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
555 if(strcmp(e->type,
"UInt")==0)i=atoi((e->val).data);
561 StDbXmlReader::pass(
char* name,
unsigned int*& i,
int& len){
563 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
564 if(!strstr(e->type,
"UInt"))
return;
571 StDbXmlReader::pass(
char* name,
long& i,
int& len){
572 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
573 if(strcmp(e->type,
"Long")==0)i=atol((e->val).data);
580 StDbXmlReader::pass(
char* name,
long*& i,
int& len){
582 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
583 if(!strstr(e->type,
"Long"))
return;
590 StDbXmlReader::pass(
char* name,
unsigned long& i,
int& len){
591 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
592 if(strcmp(e->type,
"ULong")==0)i=atol((e->val).data);
598 StDbXmlReader::pass(
char* name,
long long& i,
int& len){
599 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
601 if(strcmp(e->type,
"LongLong")==0)i=atoll((e->val).data);
603 if(strcmp(e->type,
"LongLong")==0)i=atol((e->val).data);
607 StDbXmlReader::pass(
char* name,
long long*& i,
int& len){
609 cout<<
"Not Yet Implemented"<<endl;
616 StDbXmlReader::pass(
char* name,
unsigned long*& i,
int& len){
618 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
619 if(!strstr(e->type,
"ULong"))
return;
627 StDbXmlReader::pass(
char* name,
float*& i,
int& len){
629 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
630 if(!strstr(e->type,
"Float"))
return;
636 StDbXmlReader::pass(
char* name,
double*& i,
int& len){
638 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
639 if(!strstr(e->type,
"Double"))
return;
645 StDbXmlReader::pass(
char* name,
float& i,
int& len){
646 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
647 if(strcmp(e->type,
"Float")==0)i=(float)atof((e->val).data);
653 StDbXmlReader::pass(
char* name,
double& i,
int& len){
654 elem* e = findElement(name);
if(!e){ LOG_ERROR<<name<<
" not found"<<endm;
return;}
655 if(strcmp(e->type,
"Double")==0)i=atof((e->val).data);