#include <EvtParser.hh>
Public Member Functions | |
EvtParser () | |
int | getLineofToken (int i) |
int | getNToken () |
const std::string & | getToken (int i) |
int | Read (const std::string filename) |
~EvtParser () | |
Private Member Functions | |
void | addToken (int line, const std::string &string) |
Private Attributes | |
int | _lengthoftokenlist |
int * | _linelist |
int | _ntoken |
std::string * | _tokenlist |
|
00036 { 00037 _ntoken=0; 00038 _lengthoftokenlist=0; 00039 _tokenlist=0; 00040 _linelist=0; 00041 }
|
|
00043 { 00044 00045 delete [] _tokenlist; 00046 delete [] _linelist; 00047 00048 }
|
|
00134 { 00135 00136 //report(INFO,"EvtGen") <<_ntoken<<" "<<line<<" "<<string<<endl; 00137 00138 if (_ntoken==_lengthoftokenlist) { 00139 00140 int new_length=1000+4*_lengthoftokenlist; 00141 00142 00143 00144 int* newlinelist= new int[new_length]; 00145 std::string* newtokenlist= new std::string[new_length]; 00146 00147 int i; 00148 00149 for(i=0;i<_ntoken;i++){ 00150 newlinelist[i]=_linelist[i]; 00151 newtokenlist[i]=_tokenlist[i]; 00152 } 00153 00154 delete [] _tokenlist; 00155 delete [] _linelist; 00156 00157 _tokenlist=newtokenlist; 00158 _linelist=newlinelist; 00159 00160 _lengthoftokenlist=new_length; 00161 00162 } 00163 00164 00165 _tokenlist[_ntoken]=string; 00166 00167 _linelist[_ntoken]=line; 00168 00169 _ntoken++; 00170 00171 //report(INFO,"EvtGen") << "First:"<<_tokenlist[0]<<" last:"<<_tokenlist[_ntoken-1]<<endl; 00172 00173 }
|
|
00063 { 00064 00065 return _linelist[i]; 00066 00067 }
|
|
00051 {
00052
00053 return _ntoken;
00054
00055 }
|
|
00057 { 00058 00059 return _tokenlist[i]; 00060 00061 }
|
|
00069 { 00070 ifstream fin; 00071 00072 fin.open(filename.c_str()); 00073 if (!fin) { 00074 report(ERROR,"EvtGen") << "Could not open file '"<<filename.c_str()<<"'"<<endl; 00075 return -1; 00076 } 00077 00078 char buf[MAXBUF]; 00079 char buf2[MAXBUF]; 00080 char c; 00081 00082 int line=0; 00083 int i; 00084 00085 while(fin.peek() != EOF){ 00086 line++; 00087 00088 i=0; 00089 while((c=fin.get()) != '\n' && i<MAXBUF) { 00090 buf[i]=c; 00091 i++; 00092 } 00093 if(i==MAXBUF) { 00094 report(ERROR,"EvtGen") << "Error in EvtParser: line:" 00095 <<line<<" to long"<<endl; 00096 } 00097 else { 00098 buf[i] = '\0'; 00099 } 00100 00101 //search for '#' which indicates comment for rest of line! 00102 i=0; 00103 do{ 00104 if (buf[i]=='#') buf[i]=0; 00105 i++; 00106 }while(buf[i-1]!=0); 00107 00108 //read each token 00109 istrstream ist(buf,strlen(buf)); 00110 while(ist>>buf2){ 00111 i=0; 00112 int semicolon=0; 00113 do{ 00114 if (buf2[i]==';') { 00115 buf2[i]=0; 00116 semicolon=1; 00117 } 00118 }while(buf2[i++]!=0); 00119 if (buf2[0]!=0){ 00120 addToken(line,buf2); 00121 } 00122 if (semicolon) addToken(line,";"); 00123 } 00124 } 00125 00126 fin.close(); 00127 00128 return 0; 00129 00130 }
|
|
|
|
|
|
|
|
|