lemon/lgf_writer.h
changeset 163 c82fd9568d75
parent 156 e561aa7675de
child 165 b4c336c27a03
equal deleted inserted replaced
4:512d95c69100 5:3f179fd8d2bc
   193       case '\v':
   193       case '\v':
   194 	os << "\\v";
   194 	os << "\\v";
   195 	return;
   195 	return;
   196       default:
   196       default:
   197 	if (c < 0x20) {
   197 	if (c < 0x20) {
       
   198 	  std::ios::fmtflags flags = os.flags();
   198 	  os << '\\' << std::oct << static_cast<int>(c);
   199 	  os << '\\' << std::oct << static_cast<int>(c);
       
   200 	  os.flags(flags);
   199 	} else {
   201 	} else {
   200 	  os << c;
   202 	  os << c;
   201 	}
   203 	}
   202 	return;
   204 	return;
   203       }     
   205       }     
   241   /// The writing method does a batch processing. The user creates a
   243   /// The writing method does a batch processing. The user creates a
   242   /// writer object, then various writing rules can be added to the
   244   /// writer object, then various writing rules can be added to the
   243   /// writer, and eventually the writing is executed with the \c run()
   245   /// writer, and eventually the writing is executed with the \c run()
   244   /// member function. A map writing rule can be added to the writer
   246   /// member function. A map writing rule can be added to the writer
   245   /// with the \c nodeMap() or \c arcMap() members. An optional
   247   /// with the \c nodeMap() or \c arcMap() members. An optional
   246   /// converter parameter can also be added as a standard functor converting from
   248   /// converter parameter can also be added as a standard functor
   247   /// the value type of the map to std::string. If it is set, it will
   249   /// converting from the value type of the map to std::string. If it
   248   /// determine how the map's value type is written to the output
   250   /// is set, it will determine how the map's value type is written to
   249   /// stream. If the functor is not set, then a default conversion
   251   /// the output stream. If the functor is not set, then a default
   250   /// will be used. The \c attribute(), \c node() and \c arc() functions
   252   /// conversion will be used. The \c attribute(), \c node() and \c
   251   /// are used to add attribute writing rules.
   253   /// arc() functions are used to add attribute writing rules.
   252   ///
   254   ///
   253   ///\code
   255   ///\code
   254   ///     DigraphWriter<Digraph>(std::cout, digraph).
   256   ///     DigraphWriter<Digraph>(std::cout, digraph).
   255   ///       nodeMap("coordinates", coord_map).
   257   ///       nodeMap("coordinates", coord_map).
   256   ///       nodeMap("size", size).
   258   ///       nodeMap("size", size).
   267   /// sections, but they can be give as an optional parameter of
   269   /// sections, but they can be give as an optional parameter of
   268   /// the \c nodes(), \c arcs() or \c
   270   /// the \c nodes(), \c arcs() or \c
   269   /// attributes() functions.
   271   /// attributes() functions.
   270   ///
   272   ///
   271   /// The \c skipNodes() and \c skipArcs() functions forbid the
   273   /// The \c skipNodes() and \c skipArcs() functions forbid the
   272   /// writing of the sections. If two arc sections should be written to the
   274   /// writing of the sections. If two arc sections should be written
   273   /// output, it can be done in two passes, the first pass writes the
   275   /// to the output, it can be done in two passes, the first pass
   274   /// node section and the first arc section, then the second pass
   276   /// writes the node section and the first arc section, then the
   275   /// skips the node section and writes just the arc section to the
   277   /// second pass skips the node section and writes just the arc
   276   /// stream. The output stream can be retrieved with the \c ostream()
   278   /// section to the stream. The output stream can be retrieved with
   277   /// function, hence the second pass can append its output to the output of the
   279   /// the \c ostream() function, hence the second pass can append its
   278   /// first pass.
   280   /// output to the output of the first pass.
   279   template <typename _Digraph>
   281   template <typename _Digraph>
   280   class DigraphWriter {
   282   class DigraphWriter {
   281   public:
   283   public:
   282 
   284 
   283     typedef _Digraph Digraph;
   285     typedef _Digraph Digraph;
   347     /// therefore the copied writer will not be usable more. 
   349     /// therefore the copied writer will not be usable more. 
   348     DigraphWriter(DigraphWriter& other) 
   350     DigraphWriter(DigraphWriter& other) 
   349       : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
   351       : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
   350 	_skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
   352 	_skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
   351 
   353 
   352       other.is = 0;
   354       other._os = 0;
   353       other.local_os = false;
   355       other.local_os = false;
   354 
   356 
   355       _node_index.swap(other._node_index);
   357       _node_index.swap(other._node_index);
   356       _arc_index.swap(other._arc_index);
   358       _arc_index.swap(other._arc_index);
   357 
   359 
   715     /// @}
   717     /// @}
   716   };
   718   };
   717 
   719 
   718   /// \relates DigraphWriter
   720   /// \relates DigraphWriter
   719   template <typename Digraph>
   721   template <typename Digraph>
   720   DigraphWriter<Digraph> digraphWriter(std::istream& is, Digraph& digraph) {
   722   DigraphWriter<Digraph> digraphWriter(std::ostream& os, Digraph& digraph) {
   721     return DigraphWriter<Digraph>(is, digraph);
   723     DigraphWriter<Digraph> tmp(os, digraph);
       
   724     return tmp;
   722   }
   725   }
   723 
   726 
   724   /// \relates DigraphWriter
   727   /// \relates DigraphWriter
   725   template <typename Digraph>
   728   template <typename Digraph>
   726   DigraphWriter<Digraph> digraphWriter(const std::string& fn, 
   729   DigraphWriter<Digraph> digraphWriter(const std::string& fn, 
   727 				       Digraph& digraph) {
   730 				       Digraph& digraph) {
   728     return DigraphWriter<Digraph>(fn, digraph);
   731     DigraphWriter<Digraph> tmp(fn, digraph);
       
   732     return tmp;
   729   }
   733   }
   730 
   734 
   731   /// \relates DigraphWriter
   735   /// \relates DigraphWriter
   732   template <typename Digraph>
   736   template <typename Digraph>
   733   DigraphWriter<Digraph> digraphWriter(const char* fn, Digraph& digraph) {
   737   DigraphWriter<Digraph> digraphWriter(const char* fn, Digraph& digraph) {
   734     return DigraphWriter<Digraph>(fn, digraph);
   738     DigraphWriter<Digraph> tmp(fn, digraph);
       
   739     return tmp;
   735   }
   740   }
   736 }
   741 }
   737 
   742 
   738 #endif
   743 #endif