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 in, line, lineno, maxline, name, and repeatline.

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

InputFile::~InputFile (  )  [inline]

References close().

00049 { close(); }


Member Function Documentation

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

References name.

Referenced by BLFieldMap::readFile().

00050 { return name.c_str(); }

bool InputFile::good (  )  [inline]

References in.

Referenced by BLFieldMap::readFile().

00051 { 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().

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

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

References line, and maxline.

Referenced by BLFieldMap::readFile().

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

void InputFile::close (  )  [inline]

References in, and line.

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

00077 { 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