src/lemon/lemon_reader.h
changeset 1427 14c75970840e
parent 1424 c3d754f5e631
child 1429 4283998fb2be
equal deleted inserted replaced
4:694c1c8c8ddd 5:5809fb77b2b3
    97   /// In the Lemon Format each section starts with a line contains a \c \@
    97   /// In the Lemon Format each section starts with a line contains a \c \@
    98   /// character on the first not white space position. This line is the
    98   /// character on the first not white space position. This line is the
    99   /// header line of the section. Each next lines belong to this section
    99   /// header line of the section. Each next lines belong to this section
   100   /// while it does not starts with \c \@ character. This line can start a 
   100   /// while it does not starts with \c \@ character. This line can start a 
   101   /// new section or if it can close the file with the \c \@end line.
   101   /// new section or if it can close the file with the \c \@end line.
   102   /// The file format ignore the empty lines and it may contain comments
   102   /// The file format ignore the empty and comment lines. The line is
   103   /// started with a \c # character to the end of the line. 
   103   /// comment line if it starts with a \c # character. 
   104   ///
   104   ///
   105   /// The framework provides an abstract LemonReader::SectionReader class
   105   /// The framework provides an abstract LemonReader::SectionReader class
   106   /// what defines the interface of a SectionReader. The SectionReader
   106   /// what defines the interface of a SectionReader. The SectionReader
   107   /// has the \c header() member function what get a header line string and
   107   /// has the \c header() member function what get a header line string and
   108   /// decides if it want to process the next section. Several SectionReaders
   108   /// decides if it want to process the next section. Several SectionReaders
   109   /// can be attached to an LemonReader and the first attached what can
   109   /// can be attached to an LemonReader and the first attached what can
   110   /// process the section will be used. Its \c read() member will called
   110   /// process the section will be used. Its \c read() member will called
   111   /// with a stream contains the section. From this stream the empty lines
   111   /// with a stream contains the section. From this stream the empty and
   112   /// and comments are filtered out.
   112   /// comment lines are filtered out.
   113   ///
   113   ///
   114   /// \relates GraphReader
   114   /// \relates GraphReader
   115   /// \relates NodeSetReader
   115   /// \relates NodeSetReader
   116   /// \relates EdgeSetReader
   116   /// \relates EdgeSetReader
   117   /// \relates NodesReader
   117   /// \relates NodesReader
   131 
   131 
   132     protected:
   132     protected:
   133 
   133 
   134       enum skip_state_type {
   134       enum skip_state_type {
   135 	no_skip,
   135 	no_skip,
   136 	after_comment,
       
   137 	after_endl,
   136 	after_endl,
   138 	empty_line
   137 	comment_line
   139       };
   138       };
   140 
   139 
   141       char_type small_buf[1];
   140       char_type small_buf[1];
   142 
   141 
   143 
   142 
   178 	case no_skip:
   177 	case no_skip:
   179 	  switch (c) {
   178 	  switch (c) {
   180 	  case '\n': 
   179 	  case '\n': 
   181 	    skip_state = after_endl;
   180 	    skip_state = after_endl;
   182 	    return true;
   181 	    return true;
   183 	  case '#':
       
   184 	    skip_state = after_comment;
       
   185 	    return false;
       
   186 	  default:
   182 	  default:
   187 	    return true;
   183 	    return true;
   188 	  }
   184 	  }
   189 	case after_comment:
       
   190 	  switch (c) {
       
   191 	  case '\n': 
       
   192 	    skip_state = after_endl;
       
   193 	    return true;
       
   194 	  default:
       
   195 	    return false;
       
   196 	  }        
       
   197 	case after_endl:
   185 	case after_endl:
   198 	  switch (c) {
   186 	  switch (c) {
   199 	  case '@':
   187 	  case '@':
   200 	    return false;
   188 	    return false;
   201 	  case '\n': 
   189 	  case '\n': 
   202 	    return false;
   190 	    return false;
   203 	  case '#':
   191 	  case '#':
   204 	    skip_state = empty_line;
   192 	    skip_state = comment_line;
   205 	    return false;
   193 	    return false;
   206 	  default:
   194 	  default:
   207 	    if (!isspace(c)) {
   195 	    if (!isspace(c)) {
   208 	      skip_state = no_skip;
   196 	      skip_state = no_skip;
   209 	      return true;
   197 	      return true;
   210 	    } else {
   198 	    } else {
   211 	      return false;
   199 	      return false;
   212 	    }
   200 	    }
   213 	  }
   201 	  }
   214 	  break;
   202 	  break;
   215 	case empty_line:
   203 	case comment_line:
   216 	  switch (c) {
   204 	  switch (c) {
   217 	  case '\n': 
   205 	  case '\n': 
   218 	    skip_state = after_endl;
   206 	    skip_state = after_endl;
   219 	    return false;
   207 	    return false;
   220 	  default:
   208 	  default: