Bug fixes and improvements in LGF IO
authorBalazs Dezso <deba@inf.elte.hu>
Sat, 31 May 2008 12:31:21 +0200
changeset 163c82fd9568d75
parent 162 33247f6fff16
child 164 00d297da491e
Bug fixes and improvements in LGF IO
lemon/lgf_reader.h
lemon/lgf_writer.h
     1.1 --- a/lemon/lgf_reader.h	Tue May 27 16:01:20 2008 +0200
     1.2 +++ b/lemon/lgf_reader.h	Sat May 31 12:31:21 2008 +0200
     1.3 @@ -467,7 +467,7 @@
     1.4        : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
     1.5  	_use_nodes(other._use_nodes), _use_arcs(other._use_arcs) {
     1.6  
     1.7 -      other.is = 0;
     1.8 +      other._is = 0;
     1.9        other.local_is = false;
    1.10        
    1.11        _node_index.swap(other._node_index);
    1.12 @@ -1078,8 +1078,10 @@
    1.13      ///
    1.14      /// This function starts the batch processing
    1.15      void run() {
    1.16 -      
    1.17        LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
    1.18 +      if (!*_is) {
    1.19 +	throw DataFormatError("Cannot find file");
    1.20 +      }
    1.21        
    1.22        bool nodes_done = false;
    1.23        bool arcs_done = false;
    1.24 @@ -1160,20 +1162,23 @@
    1.25    /// \relates DigraphReader
    1.26    template <typename Digraph>
    1.27    DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph) {
    1.28 -    return DigraphReader<Digraph>(is, digraph);
    1.29 +    DigraphReader<Digraph> tmp(is, digraph);
    1.30 +    return tmp;
    1.31    }
    1.32  
    1.33    /// \relates DigraphReader
    1.34    template <typename Digraph>
    1.35    DigraphReader<Digraph> digraphReader(const std::string& fn, 
    1.36  				       Digraph& digraph) {
    1.37 -    return DigraphReader<Digraph>(fn, digraph);
    1.38 +    DigraphReader<Digraph> tmp(fn, digraph);
    1.39 +    return tmp;
    1.40    }
    1.41  
    1.42    /// \relates DigraphReader
    1.43    template <typename Digraph>
    1.44    DigraphReader<Digraph> digraphReader(const char* fn, Digraph& digraph) {
    1.45 -    return DigraphReader<Digraph>(fn, digraph);
    1.46 +    DigraphReader<Digraph> tmp(fn, digraph);
    1.47 +    return tmp;
    1.48    }
    1.49  }
    1.50  
     2.1 --- a/lemon/lgf_writer.h	Tue May 27 16:01:20 2008 +0200
     2.2 +++ b/lemon/lgf_writer.h	Sat May 31 12:31:21 2008 +0200
     2.3 @@ -195,7 +195,9 @@
     2.4  	return;
     2.5        default:
     2.6  	if (c < 0x20) {
     2.7 +	  std::ios::fmtflags flags = os.flags();
     2.8  	  os << '\\' << std::oct << static_cast<int>(c);
     2.9 +	  os.flags(flags);
    2.10  	} else {
    2.11  	  os << c;
    2.12  	}
    2.13 @@ -243,12 +245,12 @@
    2.14    /// writer, and eventually the writing is executed with the \c run()
    2.15    /// member function. A map writing rule can be added to the writer
    2.16    /// with the \c nodeMap() or \c arcMap() members. An optional
    2.17 -  /// converter parameter can also be added as a standard functor converting from
    2.18 -  /// the value type of the map to std::string. If it is set, it will
    2.19 -  /// determine how the map's value type is written to the output
    2.20 -  /// stream. If the functor is not set, then a default conversion
    2.21 -  /// will be used. The \c attribute(), \c node() and \c arc() functions
    2.22 -  /// are used to add attribute writing rules.
    2.23 +  /// converter parameter can also be added as a standard functor
    2.24 +  /// converting from the value type of the map to std::string. If it
    2.25 +  /// is set, it will determine how the map's value type is written to
    2.26 +  /// the output stream. If the functor is not set, then a default
    2.27 +  /// conversion will be used. The \c attribute(), \c node() and \c
    2.28 +  /// arc() functions are used to add attribute writing rules.
    2.29    ///
    2.30    ///\code
    2.31    ///     DigraphWriter<Digraph>(std::cout, digraph).
    2.32 @@ -269,13 +271,13 @@
    2.33    /// attributes() functions.
    2.34    ///
    2.35    /// The \c skipNodes() and \c skipArcs() functions forbid the
    2.36 -  /// writing of the sections. If two arc sections should be written to the
    2.37 -  /// output, it can be done in two passes, the first pass writes the
    2.38 -  /// node section and the first arc section, then the second pass
    2.39 -  /// skips the node section and writes just the arc section to the
    2.40 -  /// stream. The output stream can be retrieved with the \c ostream()
    2.41 -  /// function, hence the second pass can append its output to the output of the
    2.42 -  /// first pass.
    2.43 +  /// writing of the sections. If two arc sections should be written
    2.44 +  /// to the output, it can be done in two passes, the first pass
    2.45 +  /// writes the node section and the first arc section, then the
    2.46 +  /// second pass skips the node section and writes just the arc
    2.47 +  /// section to the stream. The output stream can be retrieved with
    2.48 +  /// the \c ostream() function, hence the second pass can append its
    2.49 +  /// output to the output of the first pass.
    2.50    template <typename _Digraph>
    2.51    class DigraphWriter {
    2.52    public:
    2.53 @@ -349,7 +351,7 @@
    2.54        : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
    2.55  	_skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
    2.56  
    2.57 -      other.is = 0;
    2.58 +      other._os = 0;
    2.59        other.local_os = false;
    2.60  
    2.61        _node_index.swap(other._node_index);
    2.62 @@ -717,21 +719,24 @@
    2.63  
    2.64    /// \relates DigraphWriter
    2.65    template <typename Digraph>
    2.66 -  DigraphWriter<Digraph> digraphWriter(std::istream& is, Digraph& digraph) {
    2.67 -    return DigraphWriter<Digraph>(is, digraph);
    2.68 +  DigraphWriter<Digraph> digraphWriter(std::ostream& os, Digraph& digraph) {
    2.69 +    DigraphWriter<Digraph> tmp(os, digraph);
    2.70 +    return tmp;
    2.71    }
    2.72  
    2.73    /// \relates DigraphWriter
    2.74    template <typename Digraph>
    2.75    DigraphWriter<Digraph> digraphWriter(const std::string& fn, 
    2.76  				       Digraph& digraph) {
    2.77 -    return DigraphWriter<Digraph>(fn, digraph);
    2.78 +    DigraphWriter<Digraph> tmp(fn, digraph);
    2.79 +    return tmp;
    2.80    }
    2.81  
    2.82    /// \relates DigraphWriter
    2.83    template <typename Digraph>
    2.84    DigraphWriter<Digraph> digraphWriter(const char* fn, Digraph& digraph) {
    2.85 -    return DigraphWriter<Digraph>(fn, digraph);
    2.86 +    DigraphWriter<Digraph> tmp(fn, digraph);
    2.87 +    return tmp;
    2.88    }
    2.89  }
    2.90