# HG changeset patch # User deba # Date 1114682078 0 # Node ID 56f9a4ba9149045bcbe696b84947d89fc228c60e # Parent 746db68ca035c05d22a7cd172ee4757ac3f42644 GUI section handling. diff -r 746db68ca035 -r 56f9a4ba9149 src/lemon/graph_reader.h --- a/src/lemon/graph_reader.h Wed Apr 27 16:49:04 2005 +0000 +++ b/src/lemon/graph_reader.h Thu Apr 28 09:54:38 2005 +0000 @@ -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 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 EdgeReaders; EdgeReaders edge_readers; + GUIReader* gui_reader; + std::istream& is; Graph& graph; diff -r 746db68ca035 -r 56f9a4ba9149 src/lemon/graph_writer.h --- a/src/lemon/graph_writer.h Wed Apr 27 16:49:04 2005 +0000 +++ b/src/lemon/graph_writer.h Thu Apr 28 09:54:38 2005 +0000 @@ -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 > EdgeWriters; EdgeWriters edge_writers; + GUIWriter* gui_writer; + std::ostream& os; const Graph& graph;