47std::vector<G4tgrFileIn*> G4tgrFileIn::theInstances;
52 : theCurrentFile(-1), theName(
"")
73 std::vector<G4tgrFileIn*>::const_iterator vfcite;
74 for( vfcite = theInstances.begin(); vfcite != theInstances.end(); vfcite++)
76 if( (*vfcite)->GetName() == filename)
83 if( vfcite == theInstances.end() )
87 instance->theCurrentFile = -1;
90 theInstances.push_back( instance );
101 std::ifstream* fin =
new std::ifstream(filename);
102 theFiles.push_back(fin);
104 theLineNo.push_back( 0 );
106 theNames.push_back( filename );
109 if( !fin->is_open() )
124 if (filein.
GetName() != filename )
126 G4String ErrMessage =
"File not opened yet: " + filename;
147 G4int wsiz = wordlist.size();
149 for (ii = 0; ii < wsiz; ii++)
155 const G4int NMAXLIN = 1000;
159 (theLineNo[theCurrentFile])++;
160 for ( ii = 0; ii < NMAXLIN; ii++) { ltemp[ii] =
' '; }
161 theFiles[theCurrentFile]->getline( ltemp, NMAXLIN );
164 for ( ii=0; ii < NMAXLIN; ii++)
166 if ( ltemp[ii] ==
'\0' ) {
break; }
168 if ( ii == NMAXLIN-1 )
171 G4String ErrMessage =
"Too long line. Please split it "
172 +
G4String(
"putting a '\\' at the end!");
173 G4Exception(
"G4tgrFileIn::GetWordsInLine()",
"InvalidInput",
184 std::istringstream istr_line(ltemp);
194 if( *tt !=
' ' && *(tt) !=
'\0' )
202 G4cout <<
"G4tgrFileIn::GetWordsInLine() - NoWords"
203 << NoWords << ltemp <<
G4endl;
207 else if( *(tt-1) ==
' ' || *(tt-1) ==
'\015' || *(tt-1) ==
'\t')
213 G4cout <<
"G4tgrFileIn::GetWordsInLine() - NoWords"
214 << NoWords << ltemp <<
G4endl;
220 }
while((*tt !=
'\0') && (stemp.length()!=0));
222 if(stemp.length() == 0) { NoWords = 0; }
225 for( ii=0; ii < NoWords; ii++)
229 if ( stemp.length() == 0 ) {
break; }
234 G4cout <<
"!!!COMMENT" << comment << stemp.c_str() <<
G4endl;
241 else if ( comment > 0 )
243 stemp = stemp.substr( 0, comment );
244 wordlist.push_back(stemp);
247 wordlist.push_back(stemp);
259 if ( wordlist.size() != 0 )
261 if( (*(wordlist.end()-1)).compare(
"\\") == 0 )
274 std::vector<G4String> wordlist2;
276 unsigned int imerge = 0;
277 for(
size_t jj = 0; jj < wordlist.size(); jj++)
279 if( wordlist[jj].substr(0,1) ==
"\"" )
283 if( wordlist[jj][ wordlist[jj].size()-1 ] ==
'\"' )
287 G4String err1 =
" word with trailing '\"' while there is no";
288 G4String err2 =
" previous word with leading '\"' in line ";
296 wordlist2.push_back( wordlist[jj] );
298 else if( imerge == 1 )
302 wordq.
append( wordlist[jj].substr(1,wordlist[jj].size()) );
306 wordq.
append( wordlist[jj].substr(0,wordlist[jj].size()) );
310 else if( imerge == 2 )
314 wordq.
append( wordlist[jj].substr(1,wordlist[jj].size()-2));
318 wordq.
append( wordlist[jj].substr(0,wordlist[jj].size()-1) );
320 wordlist2.push_back( wordq );
327 G4String err1 =
" word with leading '\"' in line while there is no";
328 G4String err2 =
" later word with trailing '\"' in line ";
333 wordlist = wordlist2;
340 if( wordlist[0] ==
"#include" )
342 if( wordlist.size() != 2 )
346 =
"'#include' should have as second argument, the filename !";
347 G4Exception(
"G4tgrFileIn::GetWordsInLine()",
"InvalidInput",
354 G4cout <<
" G4tgrFileIn::GetWordsInLine() - Include found !" <<
G4endl;
368 G4cerr <<
"!! EXITING: ERROR IN LINE No "
369 << theLineNo[theCurrentFile] <<
" file: "
370 << theNames[theCurrentFile] <<
" : ";
377 G4bool isok = theFiles[theCurrentFile]->eof();
383 G4cout <<
" G4tgrFileIn::EndOfFile() - EOF: "
384 << theCurrentFile <<
G4endl;
388 if( theCurrentFile != -1 )
398 G4cout <<
" G4tgrFileIn::EndOfFile() - EOF: "
399 << isok <<
" " << theCurrentFile <<
G4endl;
402 if( theCurrentFile != -1 )
419 G4cout <<
"G4tgrFileIn::Close() - "
420 << theCurrentFile <<
", size " << theFiles.size() <<
G4endl;
424 theFiles[theCurrentFile+1]->close();
432 G4String Err1 = sent +
" in file " + theName;
436 G4Exception(
"G4tgrFileIn::DumpException()",
"FileError",
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4String & append(const G4String &)
static G4String ConvertToString(G4bool boolVal)
void OpenNewFile(const char *filename)
const G4String & GetName()
G4int GetWordsInLine(std::vector< G4String > &wl)
static G4tgrFileIn & GetInstanceOpened(const G4String &name)
static G4tgrFileIn & GetInstance(const G4String &name)
void DumpException(const G4String &sent)
static G4int GetVerboseLevel()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)