GUI section handling.
1.1 --- a/src/lemon/graph_reader.h Wed Apr 27 16:49:04 2005 +0000
1.2 +++ b/src/lemon/graph_reader.h Thu Apr 28 09:54:38 2005 +0000
1.3 @@ -181,6 +181,11 @@
1.4 bool escaped;
1.5 };
1.6
1.7 + class GUIReader {
1.8 + public:
1.9 + virtual void read(std::istream& is) = 0;
1.10 + };
1.11 +
1.12 /// \brief The graph reader class.
1.13 ///
1.14 ///
1.15 @@ -263,7 +268,8 @@
1.16 /// and it use the given reader as the default skipper.
1.17 GraphReader(std::istream& _is, Graph& _graph,
1.18 const DefaultReader& _reader = DefaultReader())
1.19 - : is(_is), graph(_graph), nodeSkipper(_reader), edgeSkipper(_reader) {}
1.20 + : gui_reader(0), is(_is), graph(_graph),
1.21 + nodeSkipper(_reader), edgeSkipper(_reader) {}
1.22
1.23 /// \brief Destruct the graph reader.
1.24 ///
1.25 @@ -411,6 +417,9 @@
1.26 if (line.find("@edges") == 0) {
1.27 line = readEdges(line_num, edgeInverter);
1.28 }
1.29 + if (line.find("@gui") == 0) {
1.30 + line = readGUI(line_num);
1.31 + }
1.32 if (line.find("@end") != 0) {
1.33 throw DataFormatError("Invalid control sequence error");
1.34 }
1.35 @@ -420,6 +429,11 @@
1.36 }
1.37 }
1.38
1.39 + GraphReader& readGUI(GUIReader& reader) {
1.40 + gui_reader = &reader;
1.41 + return *this;
1.42 + }
1.43 +
1.44 private:
1.45
1.46 template <typename Item> class InverterBase;
1.47 @@ -544,6 +558,18 @@
1.48 return line;
1.49 }
1.50
1.51 + std::string readGUI(int& line_num) {
1.52 + std::stringstream section;
1.53 + std::string line;
1.54 + while (line = readNotEmptyLine(is, line_num), line[0] != '@') {
1.55 + section << line << std::endl;
1.56 + }
1.57 + if (gui_reader != 0) {
1.58 + gui_reader->read(section);
1.59 + }
1.60 + return line;
1.61 + }
1.62 +
1.63 std::string readNotEmptyLine(std::istream& is, int& line_num) {
1.64 std::string line;
1.65 while (++line_num, getline(is, line)) {
1.66 @@ -732,6 +758,8 @@
1.67 typedef std::map<std::string, Edge*> EdgeReaders;
1.68 EdgeReaders edge_readers;
1.69
1.70 + GUIReader* gui_reader;
1.71 +
1.72 std::istream& is;
1.73 Graph& graph;
1.74
2.1 --- a/src/lemon/graph_writer.h Wed Apr 27 16:49:04 2005 +0000
2.2 +++ b/src/lemon/graph_writer.h Thu Apr 28 09:54:38 2005 +0000
2.3 @@ -156,6 +156,11 @@
2.4 bool escaped;
2.5 };
2.6
2.7 + class GUIWriter {
2.8 + public:
2.9 + virtual void write(std::ostream& os) = 0;
2.10 + };
2.11 +
2.12
2.13 /// \brief The graph writer class.
2.14 ///
2.15 @@ -238,7 +243,7 @@
2.16 /// it constructs the given map and it use the given writer as the
2.17 /// default skipper.
2.18 GraphWriter(std::ostream& _os, const Graph& _graph)
2.19 - : os(_os), graph(_graph) {}
2.20 + : gui_writer(0), os(_os), graph(_graph){}
2.21
2.22
2.23 /// \brief Destruct the graph writer.
2.24 @@ -318,6 +323,10 @@
2.25 return *this;
2.26 }
2.27
2.28 + GraphWriter& writeGUI(const GUIWriter& writer) {
2.29 + gui_writer = &writer;
2.30 + }
2.31 +
2.32 /// \brief Executes the writer commands.
2.33 ///
2.34 /// Executes the writer commands.
2.35 @@ -328,6 +337,7 @@
2.36 writeEdgeSet(nodeWriter, edgeWriter);
2.37 writeNodes(nodeWriter);
2.38 writeEdges(edgeWriter);
2.39 + writeGUI();
2.40 os << "@end" << std::endl;
2.41 }
2.42
2.43 @@ -433,6 +443,12 @@
2.44 }
2.45 }
2.46
2.47 + void writeGUI() {
2.48 + if (gui_writer) {
2.49 + os << "@gui" << std::endl;
2.50 + gui_writer->write(os);
2.51 + }
2.52 + }
2.53
2.54
2.55
2.56 @@ -450,6 +466,8 @@
2.57 typedef std::vector<std::pair<std::string, Edge> > EdgeWriters;
2.58 EdgeWriters edge_writers;
2.59
2.60 + GUIWriter* gui_writer;
2.61 +
2.62 std::ostream& os;
2.63 const Graph& graph;
2.64