cgma
InputDeck::LineExtractor Class Reference

List of all members.

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

Detailed Description

Definition at line 988 of file MCNPInput.cpp.


Constructor & Destructor Documentation

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();
  }

Member Function Documentation

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.

  }
Returns:
the file line number of the next line (as will be returned by either peekLine or takeLine)

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.

                                    {
    if( has_next ) return next_line;
    else throw std::runtime_error("LineExtractor out of lines, cannot peekLine().");
  }
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.

                       { 
    if( has_next ){
      std::string ret = next_line;
      get_next();
      return ret;
    }
    else throw std::runtime_error("LineExtractor out of lines, cannot takeLine().");
  }
std::string InputDeck::LineExtractor::takeLine ( int &  lineno) [inline]

Definition at line 1073 of file MCNPInput.cpp.

                                   {
    lineno = next_line_idx;
    return takeLine();
  }

Member Data Documentation

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.

Definition at line 994 of file MCNPInput.cpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines