src/lemon/graph_writer.h
changeset 1191 c988f12c6c0c
parent 1164 80bb73097736
child 1208 f486d30e4e7b
equal deleted inserted replaced
2:bfde3197f7bc 3:a116e83da6d8
    45     template <typename _Value>
    45     template <typename _Value>
    46     struct Writer {
    46     struct Writer {
    47       /// The value type.
    47       /// The value type.
    48       typedef _Value Value;
    48       typedef _Value Value;
    49 
    49 
    50       /// \brief Writes a value from the given stream.
    50       /// \brief Writes a value to the given stream.
    51       ///
    51       ///
    52       /// Writes a value from the given stream.
    52       /// Writes a value to the given stream.
    53       void write(std::ostream& os, const Value& value) {
    53       void write(std::ostream& os, const Value& value) {
    54 	os << value << '\t';
    54 	os << value << '\t';
    55       }
    55       }
    56     };
    56     };
    57 
    57 
    70     ///
    70     ///
    71     /// Constructor for the writer. If the given parameter is true
    71     /// Constructor for the writer. If the given parameter is true
    72     /// the writer creates escape sequences from special characters.
    72     /// the writer creates escape sequences from special characters.
    73     QuotedStringWriter(bool _escaped = true) : escaped(_escaped) {}
    73     QuotedStringWriter(bool _escaped = true) : escaped(_escaped) {}
    74 
    74 
    75     /// \brief Writes a quoted string from the given stream.
    75     /// \brief Writes a quoted string to the given stream.
    76     ///
    76     ///
    77     /// Writes a quoted string from the given stream.
    77     /// Writes a quoted string to the given stream.
    78     void write(std::ostream& os, const std::string& value) {
    78     void write(std::ostream& os, const std::string& value) {
    79       os << "\"";
    79       os << "\"";
    80       if (escaped) {
    80       if (escaped) {
    81 	ostringstream ls;
    81 	ostringstream ls;
    82 	for (int i = 0; i < (int)value.size(); ++i) {
    82 	for (int i = 0; i < (int)value.size(); ++i) {
   272     }
   272     }
   273 
   273 
   274     void writeEdgeSet() {
   274     void writeEdgeSet() {
   275       if (edge_map_writers.size() == 0) return;
   275       if (edge_map_writers.size() == 0) return;
   276       if (node_map_writers.size() == 0) {
   276       if (node_map_writers.size() == 0) {
   277 	throw Exception() << "Missing node id map";
   277 	//	ErrorMessage message;
       
   278 	//	message << "Missing node id map";
       
   279 	//	throw IOLogicError(message);
   278       }
   280       }
   279       os << "@edgeset" << std::endl;
   281       os << "@edgeset" << std::endl;
   280       os << "\t\t";
   282       os << "\t\t";
   281       for (int i = 0; i < (int)edge_map_writers.size(); ++i) {
   283       for (int i = 0; i < (int)edge_map_writers.size(); ++i) {
   282 	os << edge_map_writers[i].first << '\t';
   284 	os << edge_map_writers[i].first << '\t';
   293     }
   295     }
   294 
   296 
   295     void writeNodes() {
   297     void writeNodes() {
   296       if (node_writers.size() == 0) return;
   298       if (node_writers.size() == 0) return;
   297       if (node_map_writers.size() == 0) {
   299       if (node_map_writers.size() == 0) {
   298 	throw Exception() << "Missing node id map";
   300 	//	throw Exception() << "Missing node id map";
   299       }
   301       }
   300       os << "@nodes" << std::endl;
   302       os << "@nodes" << std::endl;
   301       for (int i = 0; i < (int)node_writers.size(); ++i) {
   303       for (int i = 0; i < (int)node_writers.size(); ++i) {
   302 	os << node_writers[i].first << '\t';
   304 	os << node_writers[i].first << '\t';
   303 	node_map_writers[0].second->write(os, node_writers[i].second);
   305 	node_map_writers[0].second->write(os, node_writers[i].second);
   306     }
   308     }
   307 
   309 
   308     void writeEdges() {
   310     void writeEdges() {
   309       if (edge_writers.size() == 0) return;
   311       if (edge_writers.size() == 0) return;
   310       if (edge_map_writers.size() == 0) {
   312       if (edge_map_writers.size() == 0) {
   311 	throw Exception() << "Missing edge id map";
   313 	//	throw Exception() << "Missing edge id map";
   312       }
   314       }
   313       os << "@edges" << std::endl;
   315       os << "@edges" << std::endl;
   314       for (int i = 0; i < (int)edge_writers.size(); ++i) {
   316       for (int i = 0; i < (int)edge_writers.size(); ++i) {
   315 	os << edge_writers[i].first << '\t';
   317 	os << edge_writers[i].first << '\t';
   316 	edge_map_writers[0].second->write(os, edge_writers[i].second);
   318 	edge_map_writers[0].second->write(os, edge_writers[i].second);