bool
config_file_iterator::Impl::get_next_line( cstring& line )
{
    bool broken_line = false;

    line.clear();

    while( !m_curr_level->m_stream.eof() || !!m_curr_level->m_parent.get() ) {
        // 10. Switch to upper include level if current one is finished
        // 20.  Read/append next file line
        // 30.  Increment line number
        // 40.  Remove comments
        // 50.  Remove trailing and leading spaces
        // 60.  Skip empty string
        // 70.  Concatenate broken lines if needed. Put the result into line
        // 80.  If line is not completed, try to finish it by reading the next line
        // 90.  Process command line
        // 100. Substitute macros references with their definitions
        // 110. Next line found.

        if( m_curr_level->m_stream.eof() ) {                                                // 10 //
            m_curr_level = m_curr_level->m_parent;
            continue;
        }

        std::ifstream&  input   = m_curr_level->m_stream;
        char_type* buffer_insert_pos = broken_line ? m_buffer.get() + line.size() : m_buffer.get();

        input.getline( buffer_insert_pos, (std::streamsize)(m_buffer_size - line.size()),   // 20 //
                       m_line_delimeter );

        cstring next_line( buffer_insert_pos,
                           input.gcount() > 0
                           ? buffer_insert_pos + (input.eof() ? input.gcount() : (input.gcount()-1))
                           : buffer_insert_pos );


        m_curr_level->m_curr_location.second++;                                             // 30 //

        cstring::size_type comment_pos = next_line.find( m_sl_comment_delimeter );
        if( comment_pos != cstring::npos )
            next_line.trim_right( next_line.begin()+comment_pos );                          // 40 //

        if( m_trim_trailing_spaces )                                                        // 50 //
            next_line.trim_right();
        if( m_trim_leading_spaces && !broken_line )
            next_line.trim_left();

        if( next_line.is_empty() ) {                                                        // 60 //
            if( m_skip_empty_lines )
                continue;
            else
                next_line.assign( buffer_insert_pos, buffer_insert_pos );
        }

        line = broken_line ? cstring( line.begin(), next_line.end() ) : next_line;          // 70 //

        broken_line = match_back( line, m_line_beak );
        if( broken_line ) {                                                                 // 80 //
            line.trim_right( 1 );
            continue;
        }

        if( match_front( line, m_command_delimeter ) ) {                                    // 90 //
            process_command_line( line );
            continue;
        }

        if( !is_active_line() )
            continue;

        substitute_macros( line );                                                          // 100 //

        return true;                                                                        // 110 //
    }

    BOOST_RT_PARAM_VALIDATE_LOGIC( !broken_line, BOOST_RT_PARAM_LITERAL( "broken line is not completed" ) );
    BOOST_RT_PARAM_VALIDATE_LOGIC( m_conditional_states.size() == 0,
                                   BOOST_RT_PARAM_LITERAL( "matching endif command is missing" ) );

    return false;
}