lemon/lemon_writer.h
changeset 1492 0d58f0301923
parent 1476 182da222fceb
child 1494 ae55ba000ebb
equal deleted inserted replaced
1:9afd8c9d6b90 2:bbef6de884c5
    53       void writeId(std::ostream&, const Item&) {}
    53       void writeId(std::ostream&, const Item&) {}
    54       
    54       
    55       template <class _ItemIdWriter>
    55       template <class _ItemIdWriter>
    56       struct Constraints {
    56       struct Constraints {
    57 	void constraints() {
    57 	void constraints() {
    58 	  const Item item;
       
    59 	  bool b = writer.isIdWriter();
    58 	  bool b = writer.isIdWriter();
    60 	  ignore_unused_variable_warning(b);
    59 	  ignore_unused_variable_warning(b);
    61 	  writer.writeId(os, item);
    60 	  writer.writeId(os, item);
    62 	}
    61 	}
    63 	_ItemIdWriter& writer;
    62 	_ItemIdWriter& writer;
    64 	std::ostream& os;
    63 	std::ostream& os;
       
    64 	const Item& item;
       
    65       };
       
    66 
       
    67     };
       
    68 
       
    69     template <typename Item>
       
    70     class ItemWriter {
       
    71     public:
       
    72 
       
    73       void write(std::ostream&, const Item&) {}
       
    74       
       
    75       template <class _ItemWriter>
       
    76       struct Constraints {
       
    77 	void constraints() {
       
    78 	  writer.write(os, item);
       
    79 	}
       
    80 	_ItemWriter& writer;
       
    81 	std::ostream& os;
       
    82 	const Item& item;
    65       };
    83       };
    66 
    84 
    67     };
    85     };
    68 
    86 
    69   }
    87   }
   350     ///
   368     ///
   351     /// Add a new node map writer command for the writer.
   369     /// Add a new node map writer command for the writer.
   352     template <typename Writer, typename Map>
   370     template <typename Writer, typename Map>
   353     NodeSetWriter& writeNodeMap(std::string name, const Map& map, 
   371     NodeSetWriter& writeNodeMap(std::string name, const Map& map, 
   354 			    const Writer& writer = Writer()) {
   372 			    const Writer& writer = Writer()) {
   355       checkConcept<concept::WriteMap<Node, typename Map::Value>, Map>();
   373       checkConcept<concept::ReadMap<Node, typename Map::Value>, Map>();
       
   374       checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
   356       writers.push_back(
   375       writers.push_back(
   357 	make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
   376 	make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
   358       return *this;
   377       return *this;
   359     }
   378     }
   360 
   379 
   515     ///
   534     ///
   516     /// Add a new edge map writer command for the writer.
   535     /// Add a new edge map writer command for the writer.
   517     template <typename Writer, typename Map>
   536     template <typename Writer, typename Map>
   518     EdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 
   537     EdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 
   519 			    const Writer& writer = Writer()) {
   538 			    const Writer& writer = Writer()) {
   520       checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
   539       checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>();
       
   540       checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
   521       writers.push_back(
   541       writers.push_back(
   522 	make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
   542 	make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
   523       return *this;
   543       return *this;
   524     }
   544     }
   525 
   545 
   696     ///
   716     ///
   697     /// Add a new undirected map writer command for the writer.
   717     /// Add a new undirected map writer command for the writer.
   698     template <typename Writer, typename Map>
   718     template <typename Writer, typename Map>
   699     UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map, 
   719     UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map, 
   700 					  const Writer& writer = Writer()) {
   720 					  const Writer& writer = Writer()) {
   701       checkConcept<concept::WriteMap<UndirEdge, typename Map::Value>, Map>();
   721       checkConcept<concept::ReadMap<UndirEdge, typename Map::Value>, Map>();
       
   722       checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
   702       writers.push_back(
   723       writers.push_back(
   703 	make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer)));
   724 	make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer)));
   704       return *this;
   725       return *this;
   705     }
   726     }
   706 
   727 
   707     /// \brief Add a new directed edge map writer command for the writer.
   728     /// \brief Add a new directed edge map writer command for the writer.
   708     ///
   729     ///
   709     /// Add a new directed map writer command for the writer.
   730     /// Add a new directed map writer command for the writer.
   710     template <typename Map>
   731     template <typename Map>
   711     UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map) {
   732     UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map) {
   712       checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
   733       return writeEdgeMap<typename Traits::
   713       writeUndirEdgeMap("+" + name, composeMap(forwardMap(graph), map));
   734 	template Writer<typename Map::Value>, Map>(name, map);
   714       writeUndirEdgeMap("-" + name, composeMap(backwardMap(graph), map));
       
   715       return *this;
       
   716     }
   735     }
   717 
   736 
   718     /// \brief Add a new directed map writer command for the writer.
   737     /// \brief Add a new directed map writer command for the writer.
   719     ///
   738     ///
   720     /// Add a new directed map writer command for the writer.
   739     /// Add a new directed map writer command for the writer.
   721     template <typename Writer, typename Map>
   740     template <typename Writer, typename Map>
   722     UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 
   741     UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 
   723 				     const Writer& writer = Writer()) {
   742 				     const Writer& writer = Writer()) {
   724       checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
   743       checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>();
       
   744       checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
   725       writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer);
   745       writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer);
   726       writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer);
   746       writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer);
   727       return *this;
   747       return *this;
   728     }
   748     }
   729 
   749 
  1158     /// Add an attribute writer command for the writer.
  1178     /// Add an attribute writer command for the writer.
  1159     template <typename Writer, typename Value>
  1179     template <typename Writer, typename Value>
  1160     AttributeWriter& writeAttribute(const std::string& name, 
  1180     AttributeWriter& writeAttribute(const std::string& name, 
  1161 				    const Value& value,
  1181 				    const Value& value,
  1162 				    const Writer& writer = Writer()) {
  1182 				    const Writer& writer = Writer()) {
       
  1183       checkConcept<_writer_bits::ItemWriter<Value>, Writer>();
  1163       writers.push_back(make_pair(name, new ValueWriter<Value, Writer>
  1184       writers.push_back(make_pair(name, new ValueWriter<Value, Writer>
  1164       			       (value, writer)));
  1185       			       (value, writer)));
  1165       return *this;
  1186       return *this;
  1166     }
  1187     }
  1167 
  1188