[Lemon-commits] [lemon_svn] deba: r1856 - hugo/trunk/src/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:48:14 CET 2006


Author: deba
Date: Thu Apr 28 11:54:38 2005
New Revision: 1856

Modified:
   hugo/trunk/src/lemon/graph_reader.h
   hugo/trunk/src/lemon/graph_writer.h

Log:
GUI section handling.



Modified: hugo/trunk/src/lemon/graph_reader.h
==============================================================================
--- hugo/trunk/src/lemon/graph_reader.h	(original)
+++ hugo/trunk/src/lemon/graph_reader.h	Thu Apr 28 11:54:38 2005
@@ -181,6 +181,11 @@
     bool escaped;
   };
 
+  class GUIReader {
+  public:
+    virtual void read(std::istream& is) = 0;
+  };
+
   /// \brief The graph reader class.
   ///
   ///
@@ -263,7 +268,8 @@
     /// and it use the given reader as the default skipper.
     GraphReader(std::istream& _is, Graph& _graph, 
 		const DefaultReader& _reader = DefaultReader()) 
-      : is(_is), graph(_graph), nodeSkipper(_reader), edgeSkipper(_reader) {}
+      : gui_reader(0), is(_is), graph(_graph), 
+	nodeSkipper(_reader), edgeSkipper(_reader) {}
 
     /// \brief Destruct the graph reader.
     ///
@@ -411,6 +417,9 @@
 	if (line.find("@edges") == 0) {
 	  line = readEdges(line_num, edgeInverter);
 	}
+	if (line.find("@gui") == 0) {
+	  line = readGUI(line_num);
+	}
 	if (line.find("@end") != 0) {
 	  throw DataFormatError("Invalid control sequence error");
 	}
@@ -420,6 +429,11 @@
       }
     }
 
+    GraphReader& readGUI(GUIReader& reader) {
+      gui_reader = &reader;
+      return *this;
+    }
+
   private:
 
     template <typename Item> class InverterBase;
@@ -544,6 +558,18 @@
       return line;    
     }
 
+    std::string readGUI(int& line_num) {
+      std::stringstream section;
+      std::string line;
+      while (line = readNotEmptyLine(is, line_num), line[0] != '@') {
+	section << line << std::endl;
+      }
+      if (gui_reader != 0) {
+	gui_reader->read(section);
+      }
+      return line;
+    }
+
     std::string readNotEmptyLine(std::istream& is, int& line_num) {
       std::string line;
       while (++line_num, getline(is, line)) {	
@@ -732,6 +758,8 @@
     typedef std::map<std::string, Edge*> EdgeReaders;
     EdgeReaders edge_readers;
 
+    GUIReader* gui_reader;
+
     std::istream& is;
     Graph& graph;
 

Modified: hugo/trunk/src/lemon/graph_writer.h
==============================================================================
--- hugo/trunk/src/lemon/graph_writer.h	(original)
+++ hugo/trunk/src/lemon/graph_writer.h	Thu Apr 28 11:54:38 2005
@@ -156,6 +156,11 @@
     bool escaped;
   };
 
+  class GUIWriter {
+  public:
+    virtual void write(std::ostream& os) = 0;
+  };
+
   
   /// \brief The graph writer class.
   ///
@@ -238,7 +243,7 @@
     /// it constructs the given map and it use the given writer as the
     /// default skipper.
     GraphWriter(std::ostream& _os, const Graph& _graph) 
-      : os(_os), graph(_graph) {}
+      : gui_writer(0), os(_os), graph(_graph){}
 
 
     /// \brief Destruct the graph writer.
@@ -318,6 +323,10 @@
       return *this;
     }
 
+    GraphWriter& writeGUI(const GUIWriter& writer) {
+      gui_writer = &writer;
+    }
+
     /// \brief Executes the writer commands.
     ///
     /// Executes the writer commands.
@@ -328,6 +337,7 @@
       writeEdgeSet(nodeWriter, edgeWriter);
       writeNodes(nodeWriter);
       writeEdges(edgeWriter);
+      writeGUI();
       os << "@end" << std::endl;
     }
 
@@ -433,6 +443,12 @@
       } 
     }
     
+    void writeGUI() {      
+      if (gui_writer) {
+	os << "@gui" << std::endl;
+	gui_writer->write(os);
+      }
+    }
 
 
 
@@ -450,6 +466,8 @@
     typedef std::vector<std::pair<std::string, Edge> > EdgeWriters;
     EdgeWriters edge_writers;
 
+    GUIWriter* gui_writer;
+
     std::ostream& os;
     const Graph& graph;
 



More information about the Lemon-commits mailing list