COIN-OR::LEMON - Graph Library

Changeset 1396:56f9a4ba9149 in lemon-0.x


Ignore:
Timestamp:
04/28/05 11:54:38 (15 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1856
Message:

GUI section handling.

Location:
src/lemon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/graph_reader.h

    r1394 r1396  
    182182  };
    183183
     184  class GUIReader {
     185  public:
     186    virtual void read(std::istream& is) = 0;
     187  };
     188
    184189  /// \brief The graph reader class.
    185190  ///
     
    264269    GraphReader(std::istream& _is, Graph& _graph,
    265270                const DefaultReader& _reader = DefaultReader())
    266       : is(_is), graph(_graph), nodeSkipper(_reader), edgeSkipper(_reader) {}
     271      : gui_reader(0), is(_is), graph(_graph),
     272        nodeSkipper(_reader), edgeSkipper(_reader) {}
    267273
    268274    /// \brief Destruct the graph reader.
     
    412418          line = readEdges(line_num, edgeInverter);
    413419        }
     420        if (line.find("@gui") == 0) {
     421          line = readGUI(line_num);
     422        }
    414423        if (line.find("@end") != 0) {
    415424          throw DataFormatError("Invalid control sequence error");
     
    419428        throw e;
    420429      }
     430    }
     431
     432    GraphReader& readGUI(GUIReader& reader) {
     433      gui_reader = &reader;
     434      return *this;
    421435    }
    422436
     
    545559    }
    546560
     561    std::string readGUI(int& line_num) {
     562      std::stringstream section;
     563      std::string line;
     564      while (line = readNotEmptyLine(is, line_num), line[0] != '@') {
     565        section << line << std::endl;
     566      }
     567      if (gui_reader != 0) {
     568        gui_reader->read(section);
     569      }
     570      return line;
     571    }
     572
    547573    std::string readNotEmptyLine(std::istream& is, int& line_num) {
    548574      std::string line;
     
    732758    typedef std::map<std::string, Edge*> EdgeReaders;
    733759    EdgeReaders edge_readers;
     760
     761    GUIReader* gui_reader;
    734762
    735763    std::istream& is;
  • src/lemon/graph_writer.h

    r1394 r1396  
    155155  private:
    156156    bool escaped;
     157  };
     158
     159  class GUIWriter {
     160  public:
     161    virtual void write(std::ostream& os) = 0;
    157162  };
    158163
     
    239244    /// default skipper.
    240245    GraphWriter(std::ostream& _os, const Graph& _graph)
    241       : os(_os), graph(_graph) {}
     246      : gui_writer(0), os(_os), graph(_graph){}
    242247
    243248
     
    317322      edge_writers.push_back(make_pair(name, edge));
    318323      return *this;
     324    }
     325
     326    GraphWriter& writeGUI(const GUIWriter& writer) {
     327      gui_writer = &writer;
    319328    }
    320329
     
    329338      writeNodes(nodeWriter);
    330339      writeEdges(edgeWriter);
     340      writeGUI();
    331341      os << "@end" << std::endl;
    332342    }
     
    434444    }
    435445   
     446    void writeGUI() {     
     447      if (gui_writer) {
     448        os << "@gui" << std::endl;
     449        gui_writer->write(os);
     450      }
     451    }
    436452
    437453
     
    450466    typedef std::vector<std::pair<std::string, Edge> > EdgeWriters;
    451467    EdgeWriters edge_writers;
     468
     469    GUIWriter* gui_writer;
    452470
    453471    std::ostream& os;
Note: See TracChangeset for help on using the changeset viewer.