cgma
|
Public Member Functions | |
LineExtractor (std::istream &input_p) | |
const std::string & | peekLine () const |
const std::string & | peekLine (int &lineno) const |
std::string | takeLine () |
std::string | takeLine (int &lineno) |
bool | hasLine () const |
int | getLineCount () const |
Protected Member Functions | |
void | get_next () |
Protected Attributes | |
std::istream & | input |
std::string | next_line |
bool | has_next |
int | next_line_idx |
Definition at line 988 of file MCNPInput.cpp.
InputDeck::LineExtractor::LineExtractor | ( | std::istream & | input_p | ) | [inline] |
Definition at line 1048 of file MCNPInput.cpp.
: input(input_p), next_line("*NO INPUT*"), has_next(true), next_line_idx(0) { get_next(); }
void InputDeck::LineExtractor::get_next | ( | ) | [inline, protected] |
Definition at line 1006 of file MCNPInput.cpp.
{ bool comment; do{ if(!std::getline(input, next_line)){ has_next = false; } else{ comment = false; next_line_idx++; // strip trailing carriage return, if any if(next_line.length() > 0 && *(next_line.rbegin()) == '\r') next_line.resize(next_line.size()-1); // convert to lowercase strlower(next_line); // Append a space, to catch blank comment lines (e.g. "c\n") that would otherwise not meet // the MCNP comment card spec ("a C anywhere in columns 1-5 followed by at least one blank.") // I have seen lines like "c\n" or " c\n" as complete comment cards in practice, so MCNP must // accept them. next_line.append(" "); // We want to find "c " within the first five // columns, but not if the c has anything other than a space before it. size_t idx = next_line.find("c "); if( idx < 5 ){ if( idx == 0 || next_line.at(idx-1) == ' '){ comment = true; } } } } while( has_next && comment ); // iterate until next_line is not a comment line. }
int InputDeck::LineExtractor::getLineCount | ( | ) | const [inline] |
Definition at line 1086 of file MCNPInput.cpp.
{ return next_line_idx; }
bool InputDeck::LineExtractor::hasLine | ( | ) | const [inline] |
Definition at line 1078 of file MCNPInput.cpp.
{ return has_next; }
const std::string& InputDeck::LineExtractor::peekLine | ( | ) | const [inline] |
Definition at line 1054 of file MCNPInput.cpp.
const std::string& InputDeck::LineExtractor::peekLine | ( | int & | lineno | ) | const [inline] |
Definition at line 1059 of file MCNPInput.cpp.
{ lineno = next_line_idx; return peekLine(); }
std::string InputDeck::LineExtractor::takeLine | ( | ) | [inline] |
Definition at line 1064 of file MCNPInput.cpp.
std::string InputDeck::LineExtractor::takeLine | ( | int & | lineno | ) | [inline] |
Definition at line 1073 of file MCNPInput.cpp.
{ lineno = next_line_idx; return takeLine(); }
bool InputDeck::LineExtractor::has_next [protected] |
Definition at line 993 of file MCNPInput.cpp.
std::istream& InputDeck::LineExtractor::input [protected] |
Definition at line 991 of file MCNPInput.cpp.
std::string InputDeck::LineExtractor::next_line [protected] |
Definition at line 992 of file MCNPInput.cpp.
int InputDeck::LineExtractor::next_line_idx [protected] |
Definition at line 994 of file MCNPInput.cpp.