InputFile Class Reference

List of all members.


Detailed Description

class InputFile handles input file I/O

Public Member Functions

 InputFile (G4String filename, G4int _maxline=1024)
 ~InputFile ()
const char * filename ()
bool good ()
int linenumber ()
char * getline ()
void setMaxline (int _maxline)
void close ()
void repeatLine ()

Private Attributes

std::ifstream in
G4String name
char * line
int maxline
int lineno
bool repeatline

Constructor & Destructor Documentation

InputFile::InputFile ( G4String  filename,
G4int  _maxline = 1024 
) [inline]

References BLAssert, in, line, lineno, maxline, name, and repeatline.

00041                                                           : in(), name() {
00042                 name = filename;
00043                 in.open(name.c_str());
00044                 maxline = _maxline;
00045                 line = new char[maxline];
00046                 BLAssert(line != 0);
00047                 lineno = 0;
00048                 repeatline = false;
00049         }

InputFile::~InputFile (  )  [inline]

References close().

00050 { close(); }


Member Function Documentation

const char* InputFile::filename (  )  [inline]

References name.

Referenced by BLFieldMap::readFile().

00051 { return name.c_str(); }

bool InputFile::good (  )  [inline]

References in.

Referenced by BLFieldMap::readFile().

00052 { return in.good(); }

int InputFile::linenumber (  )  [inline]

char* InputFile::getline (  )  [inline]

References in, line, lineno, maxline, and repeatline.

Referenced by CylinderImpl::handleCommand(), GridImpl::handleCommand(), FieldMapImpl::readBlock(), BLFieldMap::readFile(), and TimeImpl::readTime().

00054                         {               // skips blank lines and comments
00055                 if(repeatline) {
00056                         repeatline = false;
00057                         return line;
00058                 }
00059                 while(in.good()) {
00060                         line[0] = '\0';
00061                         in.getline(line,maxline);
00062                         ++lineno;
00063                         if(line[0] == '*')
00064                                 printf("%s\n",line);
00065                         if(line[0] == '\0' || line[0] == '#' || line[0] == '*')
00066                                 continue;
00067                         return line;
00068                 }
00069                 return 0;
00070         }

void InputFile::setMaxline ( int  _maxline  )  [inline]

References BLAssert, line, and maxline.

Referenced by BLFieldMap::readFile().

00071                                       {
00072                 maxline = _maxline;
00073                 BLAssert(maxline >= 80);
00074                 if(line) delete line;
00075                 line = new char[maxline];
00076                 BLAssert(line != 0);
00077         }

void InputFile::close (  )  [inline]

References in, and line.

Referenced by BLFieldMap::readFile(), and ~InputFile().

00078 { if(line) { in.close(); delete line; line = 0; } }

void InputFile::repeatLine (  )  [inline]


Member Data Documentation

std::ifstream InputFile::in [private]

Referenced by close(), getline(), good(), and InputFile().

G4String InputFile::name [private]

Referenced by filename(), and InputFile().

char* InputFile::line [private]

Referenced by close(), getline(), InputFile(), and setMaxline().

int InputFile::maxline [private]

Referenced by getline(), InputFile(), and setMaxline().

int InputFile::lineno [private]

Referenced by getline(), InputFile(), and linenumber().

bool InputFile::repeatline [private]

Referenced by getline(), InputFile(), and repeatLine().


The documentation for this class was generated from the following file:
g4beamline