Index: lemon/lgf_writer.h
===================================================================
--- lemon/lgf_writer.h	(revision 148)
+++ lemon/lgf_writer.h	(revision 156)
@@ -205,4 +205,5 @@
 
     bool requireEscape(const std::string& str) {
+      if (str.empty() || str[0] == '@') return true;
       std::istringstream is(str);
       char c;
@@ -232,5 +233,48 @@
   }
   
-  /// \e
+  /// \ingroup lemon_io
+  ///  
+  /// \brief LGF writer for directed graphs
+  ///
+  /// This utility writes an \ref lgf-format "LGF" file.
+  ///
+  /// The writing method does a batch processing. The user creates a
+  /// writer object, then various writing rules can be added to the
+  /// 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.
+  ///
+  ///\code
+  ///     DigraphWriter<Digraph>(std::cout, digraph).
+  ///       nodeMap("coordinates", coord_map).
+  ///       nodeMap("size", size).
+  ///       nodeMap("title", title).
+  ///       arcMap("capacity", cap_map).
+  ///       node("source", src).
+  ///       node("target", trg).
+  ///       attribute("caption", caption).
+  ///       run();
+  ///\endcode
+  ///
+  ///
+  /// By default, the writer does not write additional captions to the
+  /// sections, but they can be give as an optional parameter of
+  /// the \c nodes(), \c arcs() or \c
+  /// 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.
   template <typename _Digraph>
   class DigraphWriter {
@@ -274,19 +318,32 @@
   public:
 
-    /// \e
+    /// \brief Constructor
+    ///
+    /// Construct a directed graph writer, which writes to the given
+    /// output stream.
     DigraphWriter(std::ostream& is, Digraph& digraph) 
       : _os(&is), local_os(false), _digraph(digraph),
 	_skip_nodes(false), _skip_arcs(false) {}
 
-    /// \e
+    /// \brief Constructor
+    ///
+    /// Construct a directed graph writer, which writes to the given
+    /// output file.
     DigraphWriter(const std::string& fn, Digraph& digraph) 
       : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
 	_skip_nodes(false), _skip_arcs(false) {}
 
-    /// \e
+    /// \brief Constructor
+    ///
+    /// Construct a directed graph writer, which writes to the given
+    /// output file.
     DigraphWriter(const char* fn, Digraph& digraph) 
       : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
 	_skip_nodes(false), _skip_arcs(false) {}
 
+    /// \brief Copy constructor
+    ///
+    /// The copy constructor transfers all data from the other writer,
+    /// therefore the copied writer will not be usable more. 
     DigraphWriter(DigraphWriter& other) 
       : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
@@ -308,5 +365,5 @@
     }
 
-    /// \e
+    /// \brief Destructor
     ~DigraphWriter() {
       for (typename NodeMaps::iterator it = _node_maps.begin(); 
@@ -336,5 +393,10 @@
   public:
 
-    /// \e
+    /// \name Writing rules
+    /// @{
+    
+    /// \brief Node map reading rule
+    ///
+    /// Add a node map reading rule to the writer.
     template <typename Map>
     DigraphWriter& nodeMap(const std::string& caption, const Map& map) {
@@ -346,5 +408,8 @@
     }
 
-    /// \e
+    /// \brief Node map writing rule
+    ///
+    /// Add a node map writing rule with specialized converter to the
+    /// writer.
     template <typename Map, typename Converter>
     DigraphWriter& nodeMap(const std::string& caption, const Map& map, 
@@ -357,5 +422,7 @@
     }
 
-    /// \e
+    /// \brief Arc map writing rule
+    ///
+    /// Add an arc map writing rule to the writer.
     template <typename Map>
     DigraphWriter& arcMap(const std::string& caption, const Map& map) {
@@ -367,5 +434,8 @@
     }
 
-    /// \e
+    /// \brief Arc map writing rule
+    ///
+    /// Add an arc map writing rule with specialized converter to the
+    /// writer.
     template <typename Map, typename Converter>
     DigraphWriter& arcMap(const std::string& caption, const Map& map, 
@@ -378,5 +448,7 @@
     }
 
-    /// \e
+    /// \brief Attribute writing rule
+    ///
+    /// Add an attribute writing rule to the writer.
     template <typename Value>
     DigraphWriter& attribute(const std::string& caption, const Value& value) {
@@ -387,5 +459,8 @@
     }
 
-    /// \e
+    /// \brief Attribute writing rule
+    ///
+    /// Add an attribute writing rule with specialized converter to the
+    /// writer.
     template <typename Value, typename Converter>
     DigraphWriter& attribute(const std::string& caption, const Value& value, 
@@ -397,5 +472,7 @@
     }
 
-    /// \e
+    /// \brief Node writing rule
+    ///
+    /// Add a node writing rule to the writer.
     DigraphWriter& node(const std::string& caption, const Node& node) {
       typedef _writer_bits::MapLookUpConverter<Node> Converter;
@@ -407,5 +484,7 @@
     }
 
-    /// \e
+    /// \brief Arc writing rule
+    ///
+    /// Add an arc writing rule to writer.
     DigraphWriter& arc(const std::string& caption, const Arc& arc) {
       typedef _writer_bits::MapLookUpConverter<Arc> Converter;
@@ -417,5 +496,10 @@
     }
 
-    /// \e
+    /// \name Select section by name
+    /// @{
+
+    /// \brief Set \c \@nodes section to be read
+    ///
+    /// Set \c \@nodes section to be read
     DigraphWriter& nodes(const std::string& caption) {
       _nodes_caption = caption;
@@ -423,5 +507,7 @@
     }
 
-    /// \e
+    /// \brief Set \c \@arcs section to be read
+    ///
+    /// Set \c \@arcs section to be read
     DigraphWriter& arcs(const std::string& caption) {
       _arcs_caption = caption;
@@ -429,5 +515,7 @@
     }
 
-    /// \e
+    /// \brief Set \c \@attributes section to be read
+    ///
+    /// Set \c \@attributes section to be read
     DigraphWriter& attributes(const std::string& caption) {
       _attributes_caption = caption;
@@ -435,4 +523,10 @@
     }
 
+    /// \name Skipping section
+    /// @{
+
+    /// \brief Skip writing the node set
+    ///
+    /// The \c \@nodes section will be not written to the stream.
     DigraphWriter& skipNodes() {
       LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member");
@@ -440,8 +534,13 @@
     }
 
+    /// \brief Skip writing arc set
+    ///
+    /// The \c \@arcs section will be not written to the stream.
     DigraphWriter& skipArcs() {
       LEMON_ASSERT(!_skip_arcs, "Multiple usage of skipArcs() member");
       return *this;
     }
+
+    /// @}
 
   private:
@@ -459,5 +558,5 @@
       *_os << "@nodes";
       if (!_nodes_caption.empty()) {
-	*_os << ' ' << _nodes_caption;
+	_writer_bits::writeToken(*_os << ' ', _nodes_caption);
       }
       *_os << std::endl;
@@ -468,5 +567,5 @@
       for (typename NodeMaps::iterator it = _node_maps.begin();
 	   it != _node_maps.end(); ++it) {
-	*_os << it->first << '\t';
+	_writer_bits::writeToken(*_os, it->first) << '\t';
       }
       *_os << std::endl;
@@ -519,5 +618,5 @@
       *_os << "@arcs";
       if (!_arcs_caption.empty()) {
-	*_os << ' ' << _arcs_caption;
+	_writer_bits::writeToken(*_os << ' ', _arcs_caption);
       }
       *_os << std::endl;
@@ -529,5 +628,5 @@
       for (typename ArcMaps::iterator it = _arc_maps.begin();
 	   it != _arc_maps.end(); ++it) {
-	*_os << it->first << '\t';
+	_writer_bits::writeToken(*_os, it->first) << '\t';
       }
       *_os << std::endl;
@@ -578,10 +677,10 @@
       *_os << "@attributes";
       if (!_attributes_caption.empty()) {
-	*_os << ' ' << _attributes_caption;
+	_writer_bits::writeToken(*_os << ' ', _attributes_caption);
       }
       *_os << std::endl;
       for (typename Attributes::iterator it = _attributes.begin();
 	   it != _attributes.end(); ++it) {
-	*_os << it->first << ' ';
+	_writer_bits::writeToken(*_os, it->first) << ' ';
 	_writer_bits::writeToken(*_os, it->second->get());
 	*_os << std::endl;
@@ -591,5 +690,10 @@
   public:
     
-    /// \e
+    /// \name Execution of the writer    
+    /// @{
+
+    /// \brief Start the batch processing
+    ///
+    /// This function starts the batch processing
     void run() {
       if (!_skip_nodes) {
@@ -602,10 +706,15 @@
     }
 
-    /// \e
-    std::ostream& stream() {
+    /// \brief Gives back the stream of the writer
+    ///
+    /// Gives back the stream of the writer
+    std::ostream& ostream() {
       return *_os;
     }
+
+    /// @}
   };
 
+  /// \relates DigraphWriter
   template <typename Digraph>
   DigraphWriter<Digraph> digraphWriter(std::istream& is, Digraph& digraph) {
@@ -613,4 +722,5 @@
   }
 
+  /// \relates DigraphWriter
   template <typename Digraph>
   DigraphWriter<Digraph> digraphWriter(const std::string& fn, 
@@ -619,4 +729,5 @@
   }
 
+  /// \relates DigraphWriter
   template <typename Digraph>
   DigraphWriter<Digraph> digraphWriter(const char* fn, Digraph& digraph) {
