COIN-OR::LEMON - Graph Library

Ticket #91: 70694e6bdcac.patch

File 70694e6bdcac.patch, 6.9 KB (added by Balazs Dezso, 16 years ago)
  • lemon/lgf_reader.h

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1215081604 -7200
    # Node ID 70694e6bdcac801824ae907587fb5f9000dc6b9a
    # Parent  84c2a2e5cfee5dea7cbd79afadee5df6463a8604
    New skip*() functions in (Dig|G)raphReader
    
    diff -r 84c2a2e5cfee -r 70694e6bdcac lemon/lgf_reader.h
    a b  
    479479    bool _use_nodes;
    480480    bool _use_arcs;
    481481
     482    bool _skip_nodes;
     483    bool _skip_arcs;
     484
    482485    int line_num;
    483486    std::istringstream line;
    484487
     
    490493    /// input stream.
    491494    DigraphReader(std::istream& is, Digraph& digraph)
    492495      : _is(&is), local_is(false), _digraph(digraph),
    493         _use_nodes(false), _use_arcs(false) {}
     496        _use_nodes(false), _use_arcs(false),
     497        _skip_nodes(false), _skip_arcs(false) {}
    494498
    495499    /// \brief Constructor
    496500    ///
     
    498502    /// file.
    499503    DigraphReader(const std::string& fn, Digraph& digraph)
    500504      : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
    501         _use_nodes(false), _use_arcs(false) {}
     505        _use_nodes(false), _use_arcs(false),
     506        _skip_nodes(false), _skip_arcs(false) {}
    502507   
    503508    /// \brief Constructor
    504509    ///
     
    506511    /// file.
    507512    DigraphReader(const char* fn, Digraph& digraph)
    508513      : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
    509         _use_nodes(false), _use_arcs(false) {}
     514        _use_nodes(false), _use_arcs(false),
     515        _skip_nodes(false), _skip_arcs(false) {}
    510516
    511517    /// \brief Copy constructor
    512518    ///
     
    514520    /// therefore the copied reader will not be usable more.
    515521    DigraphReader(DigraphReader& other)
    516522      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
    517         _use_nodes(other._use_nodes), _use_arcs(other._use_arcs) {
     523        _use_nodes(other._use_nodes), _use_arcs(other._use_arcs),
     524        _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
    518525
    519526      other._is = 0;
    520527      other.local_is = false;
     
    837844    /// std::string.
    838845    template <typename Map, typename Converter>
    839846    DigraphReader& useArcs(const Map& map,
    840                             const Converter& converter = Converter()) {
     847                           const Converter& converter = Converter()) {
    841848      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    842849      LEMON_ASSERT(!_use_arcs, "Multiple usage of useArcs() member");
    843850      _use_arcs = true;
    844851      for (ArcIt a(_digraph); a != INVALID; ++a) {
    845852        _arc_index.insert(std::make_pair(converter(map[a]), a));
    846853      }
     854      return *this;
     855    }
     856
     857    /// \brief Skips the reading of node section
     858    ///
     859    /// Omit the reading of the node section. This implies that each node
     860    /// map reading rule will be abanoned, and the nodes of the graph
     861    /// will not be constructed, which usually cause that the arc set
     862    /// could not be read due to lack of node name
     863    /// resolving. Therefore, the \c skipArcs() should be used too, or
     864    /// the useNodes() member function should be used to specify the
     865    /// label of the nodes.
     866    DigraphReader& skipNodes() {
     867      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
     868      _skip_nodes = true;
     869      return *this;
     870    }
     871
     872    /// \brief Skips the reading of arc section
     873    ///
     874    /// Omit the reading of the arc section. This implies that each arc
     875    /// map reading rule will be abanoned, and the arcs of the graph
     876    /// will not be constructed.
     877    DigraphReader& skipArcs() {
     878      LEMON_ASSERT(!_skip_arcs, "Skip arcs already set");
     879      _skip_arcs = true;
    847880      return *this;
    848881    }
    849882
     
    11521185        throw DataFormatError("Cannot find file");
    11531186      }
    11541187     
    1155       bool nodes_done = false;
    1156       bool arcs_done = false;
     1188      bool nodes_done = _skip_nodes;
     1189      bool arcs_done = _skip_arcs;
    11571190      bool attributes_done = false;
    11581191      std::set<std::string> extra_sections;
    11591192
     
    12951328    bool _use_nodes;
    12961329    bool _use_edges;
    12971330
     1331    bool _skip_nodes;
     1332    bool _skip_edges;
     1333
    12981334    int line_num;
    12991335    std::istringstream line;
    13001336
     
    13061342    /// input stream.
    13071343    GraphReader(std::istream& is, Graph& graph)
    13081344      : _is(&is), local_is(false), _graph(graph),
    1309         _use_nodes(false), _use_edges(false) {}
     1345        _use_nodes(false), _use_edges(false),
     1346        _skip_nodes(false), _skip_edges(false) {}
    13101347
    13111348    /// \brief Constructor
    13121349    ///
     
    13141351    /// file.
    13151352    GraphReader(const std::string& fn, Graph& graph)
    13161353      : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph),
    1317         _use_nodes(false), _use_edges(false) {}
     1354        _use_nodes(false), _use_edges(false),
     1355        _skip_nodes(false), _skip_edges(false) {}
    13181356   
    13191357    /// \brief Constructor
    13201358    ///
     
    13221360    /// file.
    13231361    GraphReader(const char* fn, Graph& graph)
    13241362      : _is(new std::ifstream(fn)), local_is(true), _graph(graph),
    1325         _use_nodes(false), _use_edges(false) {}
     1363        _use_nodes(false), _use_edges(false),
     1364        _skip_nodes(false), _skip_edges(false) {}
    13261365
    13271366    /// \brief Copy constructor
    13281367    ///
     
    13301369    /// therefore the copied reader will not be usable more.
    13311370    GraphReader(GraphReader& other)
    13321371      : _is(other._is), local_is(other.local_is), _graph(other._graph),
    1333         _use_nodes(other._use_nodes), _use_edges(other._use_edges) {
     1372        _use_nodes(other._use_nodes), _use_edges(other._use_edges),
     1373        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
    13341374
    13351375      other._is = 0;
    13361376      other.local_is = false;
     
    17061746      for (EdgeIt a(_graph); a != INVALID; ++a) {
    17071747        _edge_index.insert(std::make_pair(converter(map[a]), a));
    17081748      }
     1749      return *this;
     1750    }
     1751
     1752    /// \brief Skips the reading of node section
     1753    ///
     1754    /// Omit the reading of the node section. This implies that each node
     1755    /// map reading rule will be abanoned, and the nodes of the graph
     1756    /// will not be constructed, which usually cause that the edge set
     1757    /// could not be read due to lack of node name
     1758    /// resolving. Therefore, the \c skipEdges() should be used too, or
     1759    /// the useNodes() member function should be used to specify the
     1760    /// label of the nodes.
     1761    GraphReader& skipNodes() {
     1762      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
     1763      _skip_nodes = true;
     1764      return *this;
     1765    }
     1766
     1767    /// \brief Skips the reading of edge section
     1768    ///
     1769    /// Omit the reading of the edge section. This implies that each edge
     1770    /// map reading rule will be abanoned, and the edges of the graph
     1771    /// will not be constructed.
     1772    GraphReader& skipEdges() {
     1773      LEMON_ASSERT(!_skip_edges, "Skip edges already set");
     1774      _skip_edges = true;
    17091775      return *this;
    17101776    }
    17111777
     
    20122078     
    20132079      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
    20142080     
    2015       bool nodes_done = false;
    2016       bool edges_done = false;
     2081      bool nodes_done = _skip_nodes;
     2082      bool edges_done = _skip_edges;
    20172083      bool attributes_done = false;
    20182084      std::set<std::string> extra_sections;
    20192085