[Lemon-commits] Balazs Dezso: Bug fixes and improvements in LGF IO

Lemon HG hg at lemon.cs.elte.hu
Wed Jun 4 12:25:35 CEST 2008


details:   http://lemon.cs.elte.hu/hg/lemon/rev/c82fd9568d75
changeset: 163:c82fd9568d75
user:      Balazs Dezso <deba [at] inf.elte.hu>
date:      Sat May 31 12:31:21 2008 +0200
description:
	Bug fixes and improvements in LGF IO

diffstat:

2 files changed, 33 insertions(+), 23 deletions(-)
lemon/lgf_reader.h |   15 ++++++++++-----
lemon/lgf_writer.h |   41 +++++++++++++++++++++++------------------

diffs (142 lines):

diff -r 33247f6fff16 -r c82fd9568d75 lemon/lgf_reader.h
--- a/lemon/lgf_reader.h	Tue May 27 16:01:20 2008 +0200
+++ b/lemon/lgf_reader.h	Sat May 31 12:31:21 2008 +0200
@@ -467,7 +467,7 @@
       : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
 	_use_nodes(other._use_nodes), _use_arcs(other._use_arcs) {
 
-      other.is = 0;
+      other._is = 0;
       other.local_is = false;
       
       _node_index.swap(other._node_index);
@@ -1078,8 +1078,10 @@
     ///
     /// This function starts the batch processing
     void run() {
-      
       LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
+      if (!*_is) {
+	throw DataFormatError("Cannot find file");
+      }
       
       bool nodes_done = false;
       bool arcs_done = false;
@@ -1160,20 +1162,23 @@
   /// \relates DigraphReader
   template <typename Digraph>
   DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph) {
-    return DigraphReader<Digraph>(is, digraph);
+    DigraphReader<Digraph> tmp(is, digraph);
+    return tmp;
   }
 
   /// \relates DigraphReader
   template <typename Digraph>
   DigraphReader<Digraph> digraphReader(const std::string& fn, 
 				       Digraph& digraph) {
-    return DigraphReader<Digraph>(fn, digraph);
+    DigraphReader<Digraph> tmp(fn, digraph);
+    return tmp;
   }
 
   /// \relates DigraphReader
   template <typename Digraph>
   DigraphReader<Digraph> digraphReader(const char* fn, Digraph& digraph) {
-    return DigraphReader<Digraph>(fn, digraph);
+    DigraphReader<Digraph> tmp(fn, digraph);
+    return tmp;
   }
 }
 
diff -r 33247f6fff16 -r c82fd9568d75 lemon/lgf_writer.h
--- a/lemon/lgf_writer.h	Tue May 27 16:01:20 2008 +0200
+++ b/lemon/lgf_writer.h	Sat May 31 12:31:21 2008 +0200
@@ -195,7 +195,9 @@
 	return;
       default:
 	if (c < 0x20) {
+	  std::ios::fmtflags flags = os.flags();
 	  os << '\\' << std::oct << static_cast<int>(c);
+	  os.flags(flags);
 	} else {
 	  os << c;
 	}
@@ -243,12 +245,12 @@
   /// writer, and eventually the writing is executed with the \c run()
   /// member function. A map writing rule can be added to the writer
   /// with the \c nodeMap() or \c arcMap() members. An optional
-  /// converter parameter can also be added as a standard functor converting from
-  /// the value type of the map to std::string. If it is set, it will
-  /// determine how the map's value type is written to the output
-  /// stream. If the functor is not set, then a default conversion
-  /// will be used. The \c attribute(), \c node() and \c arc() functions
-  /// are used to add attribute writing rules.
+  /// converter parameter can also be added as a standard functor
+  /// converting from the value type of the map to std::string. If it
+  /// is set, it will determine how the map's value type is written to
+  /// the output stream. If the functor is not set, then a default
+  /// conversion will be used. The \c attribute(), \c node() and \c
+  /// arc() functions are used to add attribute writing rules.
   ///
   ///\code
   ///     DigraphWriter<Digraph>(std::cout, digraph).
@@ -269,13 +271,13 @@
   /// attributes() functions.
   ///
   /// The \c skipNodes() and \c skipArcs() functions forbid the
-  /// writing of the sections. If two arc sections should be written to the
-  /// output, it can be done in two passes, the first pass writes the
-  /// node section and the first arc section, then the second pass
-  /// skips the node section and writes just the arc section to the
-  /// stream. The output stream can be retrieved with the \c ostream()
-  /// function, hence the second pass can append its output to the output of the
-  /// first pass.
+  /// writing of the sections. If two arc sections should be written
+  /// to the output, it can be done in two passes, the first pass
+  /// writes the node section and the first arc section, then the
+  /// second pass skips the node section and writes just the arc
+  /// section to the stream. The output stream can be retrieved with
+  /// the \c ostream() function, hence the second pass can append its
+  /// output to the output of the first pass.
   template <typename _Digraph>
   class DigraphWriter {
   public:
@@ -349,7 +351,7 @@
       : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
 	_skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
 
-      other.is = 0;
+      other._os = 0;
       other.local_os = false;
 
       _node_index.swap(other._node_index);
@@ -717,21 +719,24 @@
 
   /// \relates DigraphWriter
   template <typename Digraph>
-  DigraphWriter<Digraph> digraphWriter(std::istream& is, Digraph& digraph) {
-    return DigraphWriter<Digraph>(is, digraph);
+  DigraphWriter<Digraph> digraphWriter(std::ostream& os, Digraph& digraph) {
+    DigraphWriter<Digraph> tmp(os, digraph);
+    return tmp;
   }
 
   /// \relates DigraphWriter
   template <typename Digraph>
   DigraphWriter<Digraph> digraphWriter(const std::string& fn, 
 				       Digraph& digraph) {
-    return DigraphWriter<Digraph>(fn, digraph);
+    DigraphWriter<Digraph> tmp(fn, digraph);
+    return tmp;
   }
 
   /// \relates DigraphWriter
   template <typename Digraph>
   DigraphWriter<Digraph> digraphWriter(const char* fn, Digraph& digraph) {
-    return DigraphWriter<Digraph>(fn, digraph);
+    DigraphWriter<Digraph> tmp(fn, digraph);
+    return tmp;
   }
 }
 



More information about the Lemon-commits mailing list