lemon/lemon_writer.h
changeset 1845 f8bbfed86036
parent 1705 3f63d9db307b
child 1852 ffa7c6e96330
equal deleted inserted replaced
5:808c7adc60aa 6:bd5b02f9e3b1
   162     template <typename Map>
   162     template <typename Map>
   163     struct Ref<ConstYMap<Map> > { 
   163     struct Ref<ConstYMap<Map> > { 
   164       typedef ConstYMap<Map> Type;
   164       typedef ConstYMap<Map> Type;
   165     };
   165     };
   166 
   166 
       
   167 
       
   168     template <typename _Item>    
       
   169     class MapWriterBase {
       
   170     public:
       
   171       typedef _Item Item;
       
   172 
       
   173       virtual ~MapWriterBase() {}
       
   174 
       
   175       virtual void write(std::ostream& os, const Item& item) = 0;
       
   176     };
       
   177 
       
   178 
       
   179     template <typename _Item, typename _Map, typename _Writer>
       
   180     class MapWriter : public MapWriterBase<_Item> {
       
   181     public:
       
   182       typedef _Map Map;
       
   183       typedef _Writer Writer;
       
   184       typedef typename Writer::Value Value;
       
   185       typedef _Item Item;
       
   186       
       
   187       typename _writer_bits::Ref<Map>::Type map;
       
   188       Writer writer;
       
   189 
       
   190       MapWriter(const Map& _map, const Writer& _writer) 
       
   191 	: map(_map), writer(_writer) {}
       
   192 
       
   193       virtual ~MapWriter() {}
       
   194 
       
   195       virtual void write(std::ostream& os, const Item& item) {
       
   196 	Value value = map[item];
       
   197 	writer.write(os, value);
       
   198       }
       
   199 
       
   200     };
       
   201 
       
   202 
       
   203     class ValueWriterBase {
       
   204     public:
       
   205       virtual ~ValueWriterBase() {}
       
   206       virtual void write(std::ostream&) = 0;
       
   207     };
       
   208 
       
   209     template <typename _Value, typename _Writer>
       
   210     class ValueWriter : public ValueWriterBase {
       
   211     public:
       
   212       typedef _Value Value;
       
   213       typedef _Writer Writer;
       
   214 
       
   215       ValueWriter(const Value& _value, const Writer& _writer)
       
   216  	: value(_value), writer(_writer) {}
       
   217 
       
   218       virtual void write(std::ostream& os) {
       
   219 	writer.write(os, value);
       
   220       }
       
   221     private:
       
   222       const Value& value;
       
   223       Writer writer;
       
   224     };
       
   225     
       
   226 
       
   227     template <typename _Item>
       
   228     class IdWriterBase {
       
   229     public:
       
   230       typedef _Item Item;
       
   231       virtual ~IdWriterBase() {}
       
   232       virtual void write(std::ostream&, const Item&) const = 0;
       
   233       virtual bool isIdWriter() const = 0;
       
   234     };
       
   235 
       
   236     template <typename _Item, typename _BoxedIdWriter>
       
   237     class IdWriter : public IdWriterBase<_Item> {
       
   238     public:
       
   239       typedef _Item Item;
       
   240       typedef _BoxedIdWriter BoxedIdWriter;
       
   241 
       
   242       const BoxedIdWriter& idWriter;
       
   243 
       
   244       IdWriter(const BoxedIdWriter& _idWriter) 
       
   245 	: idWriter(_idWriter) {}
       
   246 
       
   247       virtual void write(std::ostream& os, const Item& item) const {
       
   248 	idWriter.writeId(os, item);
       
   249       }
       
   250 
       
   251       virtual bool isIdWriter() const {
       
   252 	return idWriter.isIdWriter();
       
   253       }
       
   254     };
       
   255 
   167   }
   256   }
   168 
   257 
   169   /// \ingroup io_group
   258   /// \ingroup io_group
   170   /// \brief Lemon Format writer class.
   259   /// \brief Lemon Format writer class.
   171   /// 
   260   /// 
   279     typedef std::vector<SectionWriter*> SectionWriters;
   368     typedef std::vector<SectionWriter*> SectionWriters;
   280     SectionWriters writers;
   369     SectionWriters writers;
   281 
   370 
   282   };
   371   };
   283 
   372 
   284   /// \brief Helper class for implementing the common SectionWriters.
       
   285   ///
       
   286   /// Helper class for implementing the common SectionWriters.
       
   287   class CommonSectionWriterBase : public LemonWriter::SectionWriter {
       
   288     typedef LemonWriter::SectionWriter Parent;
       
   289   protected:
       
   290     
       
   291     /// \brief Constructor for CommonSectionWriterBase.
       
   292     ///
       
   293     /// Constructor for CommonSectionWriterBase. It attach this writer to
       
   294     /// the given LemonWriter.
       
   295     CommonSectionWriterBase(LemonWriter& _writer) 
       
   296       : Parent(_writer) {}
       
   297 
       
   298     template <typename _Item>    
       
   299     class WriterBase {
       
   300     public:
       
   301       typedef _Item Item;
       
   302 
       
   303       virtual ~WriterBase() {}
       
   304 
       
   305       virtual void write(std::ostream& os, const Item& item) = 0;
       
   306     };
       
   307 
       
   308 
       
   309     template <typename _Item, typename _Map, typename _Writer>
       
   310     class MapWriter : public WriterBase<_Item> {
       
   311     public:
       
   312       typedef _Map Map;
       
   313       typedef _Writer Writer;
       
   314       typedef typename Writer::Value Value;
       
   315       typedef _Item Item;
       
   316       
       
   317       typename _writer_bits::Ref<Map>::Type map;
       
   318       Writer writer;
       
   319 
       
   320       MapWriter(const Map& _map, const Writer& _writer) 
       
   321 	: map(_map), writer(_writer) {}
       
   322 
       
   323       virtual ~MapWriter() {}
       
   324 
       
   325       virtual void write(std::ostream& os, const Item& item) {
       
   326 	Value value = map[item];
       
   327 	writer.write(os, value);
       
   328       }
       
   329 
       
   330     };
       
   331 
       
   332 
       
   333     class ValueWriterBase {
       
   334     public:
       
   335       virtual ~ValueWriterBase() {}
       
   336       virtual void write(std::ostream&) = 0;
       
   337     };
       
   338 
       
   339     template <typename _Value, typename _Writer>
       
   340     class ValueWriter : public ValueWriterBase {
       
   341     public:
       
   342       typedef _Value Value;
       
   343       typedef _Writer Writer;
       
   344 
       
   345       ValueWriter(const Value& _value, const Writer& _writer)
       
   346  	: value(_value), writer(_writer) {}
       
   347 
       
   348       virtual void write(std::ostream& os) {
       
   349 	writer.write(os, value);
       
   350       }
       
   351     private:
       
   352       const Value& value;
       
   353       Writer writer;
       
   354     };
       
   355     
       
   356 
       
   357     template <typename _Item>
       
   358     class IdWriterBase {
       
   359     public:
       
   360       typedef _Item Item;
       
   361       virtual ~IdWriterBase() {}
       
   362       virtual void write(std::ostream&, const Item&) const = 0;
       
   363       virtual bool isIdWriter() const = 0;
       
   364     };
       
   365 
       
   366     template <typename _Item, typename _BoxedIdWriter>
       
   367     class IdWriter : public IdWriterBase<_Item> {
       
   368     public:
       
   369       typedef _Item Item;
       
   370       typedef _BoxedIdWriter BoxedIdWriter;
       
   371 
       
   372       const BoxedIdWriter& idWriter;
       
   373 
       
   374       IdWriter(const BoxedIdWriter& _idWriter) 
       
   375 	: idWriter(_idWriter) {}
       
   376 
       
   377       virtual void write(std::ostream& os, const Item& item) const {
       
   378 	idWriter.writeId(os, item);
       
   379       }
       
   380 
       
   381       virtual bool isIdWriter() const {
       
   382 	return idWriter.isIdWriter();
       
   383       }
       
   384     };
       
   385   };
       
   386 
       
   387   /// \ingroup io_group
   373   /// \ingroup io_group
   388   /// \brief SectionWriter for writing a graph's nodeset.
   374   /// \brief SectionWriter for writing a graph's nodeset.
   389   ///
   375   ///
   390   /// The lemon format can store multiple graph nodesets with several maps.
   376   /// The lemon format can store multiple graph nodesets with several maps.
   391   /// The nodeset section's header line is \c \@nodeset \c nodeset_id, but the
   377   /// The nodeset section's header line is \c \@nodeset \c nodeset_id, but the
   401   /// Otherwise if the \c _forceIdMap constructor parameter is true then
   387   /// Otherwise if the \c _forceIdMap constructor parameter is true then
   402   /// the id map will be the id in the graph.
   388   /// the id map will be the id in the graph.
   403   ///
   389   ///
   404   /// \relates LemonWriter
   390   /// \relates LemonWriter
   405   template <typename _Graph, typename _Traits = DefaultWriterTraits>
   391   template <typename _Graph, typename _Traits = DefaultWriterTraits>
   406   class NodeSetWriter : public CommonSectionWriterBase {
   392   class NodeSetWriter : public LemonWriter::SectionWriter {
   407     typedef CommonSectionWriterBase Parent;
   393     typedef LemonWriter::SectionWriter Parent;
   408   public:
   394   public:
   409 
   395 
   410     typedef _Graph Graph;
   396     typedef _Graph Graph;
   411     typedef _Traits Traits;
   397     typedef _Traits Traits;
   412     typedef typename Graph::Node Node;
   398     typedef typename Graph::Node Node;
   455     NodeSetWriter& writeNodeMap(std::string name, const Map& map, 
   441     NodeSetWriter& writeNodeMap(std::string name, const Map& map, 
   456 			    const Writer& writer = Writer()) {
   442 			    const Writer& writer = Writer()) {
   457       checkConcept<concept::ReadMap<Node, typename Map::Value>, Map>();
   443       checkConcept<concept::ReadMap<Node, typename Map::Value>, Map>();
   458       checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
   444       checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
   459       writers.push_back(
   445       writers.push_back(
   460 	make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
   446 	make_pair(name, new _writer_bits::
       
   447 		  MapWriter<Node, Map, Writer>(map, writer)));
   461       return *this;
   448       return *this;
   462     }
   449     }
   463 
   450 
   464   protected:
   451   protected:
   465 
   452 
   525       }
   512       }
   526     }
   513     }
   527 
   514 
   528   private:
   515   private:
   529 
   516 
   530     typedef std::vector<std::pair<std::string, WriterBase<Node>*> > MapWriters;
   517     typedef std::vector<std::pair<std::string, _writer_bits::
       
   518 				  MapWriterBase<Node>*> > MapWriters;
   531     MapWriters writers;
   519     MapWriters writers;
   532 
   520 
   533     WriterBase<Node>* idMap;
   521     _writer_bits::MapWriterBase<Node>* idMap;
   534     bool forceIdMap;
   522     bool forceIdMap;
   535    
   523    
   536     const Graph& graph;   
   524     const Graph& graph;   
   537     std::string id;
   525     std::string id;
   538 
   526 
   560   /// have to be connected. If a NodeSetWriter can write the nodes' id,
   548   /// have to be connected. If a NodeSetWriter can write the nodes' id,
   561   /// it will be able to use with this class.
   549   /// it will be able to use with this class.
   562   ///
   550   ///
   563   /// \relates LemonWriter
   551   /// \relates LemonWriter
   564   template <typename _Graph, typename _Traits = DefaultWriterTraits>
   552   template <typename _Graph, typename _Traits = DefaultWriterTraits>
   565   class EdgeSetWriter : public CommonSectionWriterBase {
   553   class EdgeSetWriter : public LemonWriter::SectionWriter {
   566     typedef CommonSectionWriterBase Parent;
   554     typedef LemonWriter::SectionWriter Parent;
   567   public:
   555   public:
   568 
   556 
   569     typedef _Graph Graph;
   557     typedef _Graph Graph;
   570     typedef _Traits Traits;
   558     typedef _Traits Traits;
   571     typedef typename Graph::Node Node;
   559     typedef typename Graph::Node Node;
   584 		  const std::string& _id = std::string(),
   572 		  const std::string& _id = std::string(),
   585 		  bool _forceIdMap = true)
   573 		  bool _forceIdMap = true)
   586       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
   574       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
   587 	graph(_graph), id(_id) {
   575 	graph(_graph), id(_id) {
   588       checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>();
   576       checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>();
   589       nodeIdWriter.reset(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter));
   577       nodeIdWriter.reset(new _writer_bits::
       
   578 			 IdWriter<Node, NodeIdWriter>(_nodeIdWriter));
   590     } 
   579     } 
   591 
   580 
   592     /// \brief Destructor.
   581     /// \brief Destructor.
   593     ///
   582     ///
   594     /// Destructor for EdgeSetWriter.
   583     /// Destructor for EdgeSetWriter.
   621     EdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 
   610     EdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 
   622 			    const Writer& writer = Writer()) {
   611 			    const Writer& writer = Writer()) {
   623       checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>();
   612       checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>();
   624       checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
   613       checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
   625       writers.push_back(
   614       writers.push_back(
   626 	make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
   615 	make_pair(name, new _writer_bits::
       
   616 		  MapWriter<Edge, Map, Writer>(map, writer)));
   627       return *this;
   617       return *this;
   628     }
   618     }
   629 
   619 
   630   protected:
   620   protected:
   631 
   621 
   699       }
   689       }
   700     } 
   690     } 
   701 
   691 
   702   private:
   692   private:
   703 
   693 
   704     typedef std::vector<std::pair<std::string, WriterBase<Edge>*> > MapWriters;
   694     typedef std::vector<std::pair<std::string, _writer_bits::
       
   695 				  MapWriterBase<Edge>*> > MapWriters;
   705     MapWriters writers;
   696     MapWriters writers;
   706 
   697 
   707     WriterBase<Edge>* idMap;
   698     _writer_bits::MapWriterBase<Edge>* idMap;
   708     bool forceIdMap;
   699     bool forceIdMap;
   709    
   700    
   710     const Graph& graph;   
   701     const Graph& graph;   
   711     std::string id;
   702     std::string id;
   712 
   703 
   713     std::auto_ptr<IdWriterBase<Node> > nodeIdWriter;
   704     std::auto_ptr<_writer_bits::IdWriterBase<Node> > nodeIdWriter;
   714   };
   705   };
   715 
   706 
   716   /// \ingroup io_group
   707   /// \ingroup io_group
   717   /// \brief SectionWriter for writing a undirected edgeset.
   708   /// \brief SectionWriter for writing a undirected edgeset.
   718   ///
   709   ///
   741   /// which nodes have to be connected. If a NodeSetWriter can write the 
   732   /// which nodes have to be connected. If a NodeSetWriter can write the 
   742   /// nodes' id, it will be able to use with this class.
   733   /// nodes' id, it will be able to use with this class.
   743   ///
   734   ///
   744   /// \relates LemonWriter
   735   /// \relates LemonWriter
   745   template <typename _Graph, typename _Traits = DefaultWriterTraits>
   736   template <typename _Graph, typename _Traits = DefaultWriterTraits>
   746   class UndirEdgeSetWriter : public CommonSectionWriterBase {
   737   class UndirEdgeSetWriter : public LemonWriter::SectionWriter {
   747     typedef CommonSectionWriterBase Parent;
   738     typedef LemonWriter::SectionWriter Parent;
   748   public:
   739   public:
   749 
   740 
   750     typedef _Graph Graph;
   741     typedef _Graph Graph;
   751     typedef _Traits Traits;
   742     typedef _Traits Traits;
   752     typedef typename Graph::Node Node;
   743     typedef typename Graph::Node Node;
   766 		       const std::string& _id = std::string(),
   757 		       const std::string& _id = std::string(),
   767 		       bool _forceIdMap = true)
   758 		       bool _forceIdMap = true)
   768       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
   759       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
   769 	graph(_graph), id(_id) {
   760 	graph(_graph), id(_id) {
   770       checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>();
   761       checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>();
   771       nodeIdWriter.reset(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter));
   762       nodeIdWriter.reset(new _writer_bits::
       
   763 			 IdWriter<Node, NodeIdWriter>(_nodeIdWriter));
   772     } 
   764     } 
   773 
   765 
   774     /// \brief Destructor.
   766     /// \brief Destructor.
   775     ///
   767     ///
   776     /// Destructor for UndirEdgeSetWriter.
   768     /// Destructor for UndirEdgeSetWriter.
   803     UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map, 
   795     UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map, 
   804 					  const Writer& writer = Writer()) {
   796 					  const Writer& writer = Writer()) {
   805       checkConcept<concept::ReadMap<UndirEdge, typename Map::Value>, Map>();
   797       checkConcept<concept::ReadMap<UndirEdge, typename Map::Value>, Map>();
   806       checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
   798       checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
   807       writers.push_back(
   799       writers.push_back(
   808 	make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer)));
   800 	make_pair(name, new _writer_bits::
       
   801 		  MapWriter<UndirEdge, Map, Writer>(map, writer)));
   809       return *this;
   802       return *this;
   810     }
   803     }
   811 
   804 
   812     /// \brief Add a new directed edge map writer command for the writer.
   805     /// \brief Add a new directed edge map writer command for the writer.
   813     ///
   806     ///
   926       }
   919       }
   927     } 
   920     } 
   928 
   921 
   929   private:
   922   private:
   930 
   923 
   931     typedef std::vector<std::pair<std::string, 
   924     typedef std::vector<std::pair<std::string, _writer_bits::
   932 				  WriterBase<UndirEdge>*> > MapWriters;
   925 				  MapWriterBase<UndirEdge>*> > MapWriters;
   933     MapWriters writers;
   926     MapWriters writers;
   934 
   927 
   935     WriterBase<UndirEdge>* idMap;
   928     _writer_bits::MapWriterBase<UndirEdge>* idMap;
   936     bool forceIdMap;
   929     bool forceIdMap;
   937    
   930    
   938     const Graph& graph;   
   931     const Graph& graph;   
   939     std::string id;
   932     std::string id;
   940 
   933 
   941     std::auto_ptr<IdWriterBase<Node> > nodeIdWriter;
   934     std::auto_ptr<_writer_bits::IdWriterBase<Node> > nodeIdWriter;
   942   };
   935   };
   943 
   936 
   944   /// \ingroup io_group
   937   /// \ingroup io_group
   945   /// \brief SectionWriter for writing labeled nodes.
   938   /// \brief SectionWriter for writing labeled nodes.
   946   ///
   939   ///
   950   /// Each line in the section contains the label of the node and 
   943   /// Each line in the section contains the label of the node and 
   951   /// then the node id. 
   944   /// then the node id. 
   952   ///
   945   ///
   953   /// \relates LemonWriter
   946   /// \relates LemonWriter
   954   template <typename _Graph>
   947   template <typename _Graph>
   955   class NodeWriter : public CommonSectionWriterBase {
   948   class NodeWriter : public LemonWriter::SectionWriter {
   956     typedef CommonSectionWriterBase Parent;
   949     typedef LemonWriter::SectionWriter Parent;
   957     typedef _Graph Graph;
   950     typedef _Graph Graph;
   958     typedef typename Graph::Node Node;
   951     typedef typename Graph::Node Node;
   959   public:
   952   public:
   960     
   953     
   961     /// \brief Constructor.
   954     /// \brief Constructor.
   966     template <typename _IdWriter>
   959     template <typename _IdWriter>
   967     NodeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 
   960     NodeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 
   968 	       const std::string& _id = std::string()) 
   961 	       const std::string& _id = std::string()) 
   969       : Parent(_writer), id(_id) {
   962       : Parent(_writer), id(_id) {
   970       checkConcept<_writer_bits::ItemIdWriter<Node>, _IdWriter>();
   963       checkConcept<_writer_bits::ItemIdWriter<Node>, _IdWriter>();
   971       idWriter.reset(new IdWriter<Node, _IdWriter>(_idWriter));
   964       idWriter.reset(new _writer_bits::IdWriter<Node, _IdWriter>(_idWriter));
   972     }
   965     }
   973 
   966 
   974 
   967 
   975     /// \brief Destructor.
   968     /// \brief Destructor.
   976     ///
   969     ///
  1018 
  1011 
  1019     std::string id;
  1012     std::string id;
  1020 
  1013 
  1021     typedef std::vector<std::pair<std::string, const Node*> > NodeWriters;
  1014     typedef std::vector<std::pair<std::string, const Node*> > NodeWriters;
  1022     NodeWriters writers;
  1015     NodeWriters writers;
  1023     std::auto_ptr<IdWriterBase<Node> > idWriter;
  1016     std::auto_ptr<_writer_bits::IdWriterBase<Node> > idWriter;
  1024   };
  1017   };
  1025 
  1018 
  1026   /// \ingroup io_group
  1019   /// \ingroup io_group
  1027   /// \brief SectionWriter for writing labeled edges.
  1020   /// \brief SectionWriter for writing labeled edges.
  1028   ///
  1021   ///
  1032   /// Each line in the section contains the label of the edge and 
  1025   /// Each line in the section contains the label of the edge and 
  1033   /// then the edge id. 
  1026   /// then the edge id. 
  1034   ///
  1027   ///
  1035   /// \relates LemonWriter
  1028   /// \relates LemonWriter
  1036   template <typename _Graph>
  1029   template <typename _Graph>
  1037   class EdgeWriter : public CommonSectionWriterBase {
  1030   class EdgeWriter : public LemonWriter::SectionWriter {
  1038     typedef CommonSectionWriterBase Parent;
  1031     typedef LemonWriter::SectionWriter Parent;
  1039     typedef _Graph Graph;
  1032     typedef _Graph Graph;
  1040     typedef typename Graph::Edge Edge;
  1033     typedef typename Graph::Edge Edge;
  1041   public:
  1034   public:
  1042     
  1035     
  1043     /// \brief Constructor.
  1036     /// \brief Constructor.
  1048     template <typename _IdWriter>
  1041     template <typename _IdWriter>
  1049     EdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 
  1042     EdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 
  1050 	       const std::string& _id = std::string()) 
  1043 	       const std::string& _id = std::string()) 
  1051       : Parent(_writer), id(_id) {
  1044       : Parent(_writer), id(_id) {
  1052       checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>();
  1045       checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>();
  1053       idWriter.reset(new IdWriter<Edge, _IdWriter>(_idWriter));
  1046       idWriter.reset(new _writer_bits::IdWriter<Edge, _IdWriter>(_idWriter));
  1054     }
  1047     }
  1055 
  1048 
  1056     /// \brief Destructor.
  1049     /// \brief Destructor.
  1057     ///
  1050     ///
  1058     /// Destructor for EdgeWriter.
  1051     /// Destructor for EdgeWriter.
  1099     std::string id;
  1092     std::string id;
  1100 
  1093 
  1101     typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
  1094     typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
  1102     EdgeWriters writers;
  1095     EdgeWriters writers;
  1103 
  1096 
  1104     std::auto_ptr<IdWriterBase<Edge> > idWriter;
  1097     std::auto_ptr<_writer_bits::IdWriterBase<Edge> > idWriter;
  1105   };
  1098   };
  1106 
  1099 
  1107   /// \ingroup io_group
  1100   /// \ingroup io_group
  1108   /// \brief SectionWriter for writing labeled undirected edges.
  1101   /// \brief SectionWriter for writing labeled undirected edges.
  1109   ///
  1102   ///
  1113   /// Each line in the section contains the label of the undirected edge and 
  1106   /// Each line in the section contains the label of the undirected edge and 
  1114   /// then the undirected edge id. 
  1107   /// then the undirected edge id. 
  1115   ///
  1108   ///
  1116   /// \relates LemonWriter
  1109   /// \relates LemonWriter
  1117   template <typename _Graph>
  1110   template <typename _Graph>
  1118   class UndirEdgeWriter : public CommonSectionWriterBase {
  1111   class UndirEdgeWriter : public LemonWriter::SectionWriter {
  1119     typedef CommonSectionWriterBase Parent;
  1112     typedef LemonWriter::SectionWriter Parent;
  1120     typedef _Graph Graph;
  1113     typedef _Graph Graph;
  1121     typedef typename Graph::Node Node;
  1114     typedef typename Graph::Node Node;
  1122     typedef typename Graph::Edge Edge;
  1115     typedef typename Graph::Edge Edge;
  1123     typedef typename Graph::UndirEdge UndirEdge;
  1116     typedef typename Graph::UndirEdge UndirEdge;
  1124   public:
  1117   public:
  1133     UndirEdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 
  1126     UndirEdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 
  1134 	       const std::string& _id = std::string()) 
  1127 	       const std::string& _id = std::string()) 
  1135       : Parent(_writer), id(_id) {
  1128       : Parent(_writer), id(_id) {
  1136       checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>();
  1129       checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>();
  1137       checkConcept<_writer_bits::ItemIdWriter<UndirEdge>, _IdWriter>();
  1130       checkConcept<_writer_bits::ItemIdWriter<UndirEdge>, _IdWriter>();
  1138       undirEdgeIdWriter.reset(new IdWriter<UndirEdge, _IdWriter>(_idWriter));
  1131       undirEdgeIdWriter.reset(new _writer_bits::
  1139       edgeIdWriter.reset(new IdWriter<Edge, _IdWriter>(_idWriter));
  1132 			      IdWriter<UndirEdge, _IdWriter>(_idWriter));
       
  1133       edgeIdWriter.reset(new _writer_bits::
       
  1134 			 IdWriter<Edge, _IdWriter>(_idWriter));
  1140     }
  1135     }
  1141 
  1136 
  1142     /// \brief Destructor.
  1137     /// \brief Destructor.
  1143     ///
  1138     ///
  1144     /// Destructor for UndirEdgeWriter.
  1139     /// Destructor for UndirEdgeWriter.
  1200     std::string id;
  1195     std::string id;
  1201 
  1196 
  1202     typedef std::vector<std::pair<std::string, 
  1197     typedef std::vector<std::pair<std::string, 
  1203 				  const UndirEdge*> > UndirEdgeWriters;
  1198 				  const UndirEdge*> > UndirEdgeWriters;
  1204     UndirEdgeWriters undirEdgeWriters;
  1199     UndirEdgeWriters undirEdgeWriters;
  1205     std::auto_ptr<IdWriterBase<UndirEdge> > undirEdgeIdWriter;
  1200     std::auto_ptr<_writer_bits::IdWriterBase<UndirEdge> > undirEdgeIdWriter;
  1206 
  1201 
  1207     typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
  1202     typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
  1208     EdgeWriters edgeWriters;
  1203     EdgeWriters edgeWriters;
  1209     std::auto_ptr<IdWriterBase<Edge> > edgeIdWriter;
  1204     std::auto_ptr<_writer_bits::IdWriterBase<Edge> > edgeIdWriter;
  1210 
  1205 
  1211   };
  1206   };
  1212 
  1207 
  1213   /// \ingroup io_group
  1208   /// \ingroup io_group
  1214   /// \brief SectionWriter for attributes.
  1209   /// \brief SectionWriter for attributes.
  1220   /// The attributeset section contains several lines. Each of them starts
  1215   /// The attributeset section contains several lines. Each of them starts
  1221   /// with the name of attribute and then the value.
  1216   /// with the name of attribute and then the value.
  1222   ///
  1217   ///
  1223   /// \relates LemonWriter
  1218   /// \relates LemonWriter
  1224   template <typename _Traits = DefaultWriterTraits>
  1219   template <typename _Traits = DefaultWriterTraits>
  1225   class AttributeWriter : public CommonSectionWriterBase {
  1220   class AttributeWriter : public LemonWriter::SectionWriter {
  1226     typedef CommonSectionWriterBase Parent;
  1221     typedef LemonWriter::SectionWriter Parent;
  1227     typedef _Traits Traits; 
  1222     typedef _Traits Traits; 
  1228   public:
  1223   public:
  1229     /// \brief Constructor.
  1224     /// \brief Constructor.
  1230     ///
  1225     ///
  1231     /// Constructor for AttributeWriter. It creates the AttributeWriter and
  1226     /// Constructor for AttributeWriter. It creates the AttributeWriter and
  1265     template <typename Writer, typename Value>
  1260     template <typename Writer, typename Value>
  1266     AttributeWriter& writeAttribute(const std::string& name, 
  1261     AttributeWriter& writeAttribute(const std::string& name, 
  1267 				    const Value& value,
  1262 				    const Value& value,
  1268 				    const Writer& writer = Writer()) {
  1263 				    const Writer& writer = Writer()) {
  1269       checkConcept<_writer_bits::ItemWriter<Value>, Writer>();
  1264       checkConcept<_writer_bits::ItemWriter<Value>, Writer>();
  1270       writers.push_back(make_pair(name, new ValueWriter<Value, Writer>
  1265       writers.push_back(make_pair(name, new _writer_bits::
  1271       			       (value, writer)));
  1266 				  ValueWriter<Value, Writer>(value, writer)));
  1272       return *this;
  1267       return *this;
  1273     }
  1268     }
  1274 
  1269 
  1275   protected:
  1270   protected:
  1276 
  1271 
  1294     }    
  1289     }    
  1295 
  1290 
  1296   private:
  1291   private:
  1297     std::string id;
  1292     std::string id;
  1298 
  1293 
  1299     typedef std::vector<std::pair<std::string, ValueWriterBase*> > Writers;
  1294     typedef std::vector<std::pair<std::string, 
       
  1295 				  _writer_bits::ValueWriterBase*> > Writers;
  1300     Writers writers;  
  1296     Writers writers;  
  1301   };
  1297   };
  1302 
  1298 
  1303 
  1299 
  1304 }
  1300 }