COIN-OR::LEMON - Graph Library

Ticket #35: lgf_bug_fix.patch

File lgf_bug_fix.patch, 5.5 KB (added by Balazs Dezso, 16 years ago)
  • lemon/lgf_reader.h

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1212229881 -7200
    # Node ID c82fd9568d756001cc5aabe28571b247e7e190bb
    # Parent  33247f6fff166e4f31556176cd5c3b18627e6332
    Bug fixes and improvements in LGF IO
    
    diff -r 33247f6fff16 -r c82fd9568d75 lemon/lgf_reader.h
    a b  
    467467      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
    468468        _use_nodes(other._use_nodes), _use_arcs(other._use_arcs) {
    469469
    470       other.is = 0;
     470      other._is = 0;
    471471      other.local_is = false;
    472472     
    473473      _node_index.swap(other._node_index);
     
    10781078    ///
    10791079    /// This function starts the batch processing
    10801080    void run() {
    1081      
    10821081      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
     1082      if (!*_is) {
     1083        throw DataFormatError("Cannot find file");
     1084      }
    10831085     
    10841086      bool nodes_done = false;
    10851087      bool arcs_done = false;
     
    11601162  /// \relates DigraphReader
    11611163  template <typename Digraph>
    11621164  DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph) {
    1163     return DigraphReader<Digraph>(is, digraph);
     1165    DigraphReader<Digraph> tmp(is, digraph);
     1166    return tmp;
    11641167  }
    11651168
    11661169  /// \relates DigraphReader
    11671170  template <typename Digraph>
    11681171  DigraphReader<Digraph> digraphReader(const std::string& fn,
    11691172                                       Digraph& digraph) {
    1170     return DigraphReader<Digraph>(fn, digraph);
     1173    DigraphReader<Digraph> tmp(fn, digraph);
     1174    return tmp;
    11711175  }
    11721176
    11731177  /// \relates DigraphReader
    11741178  template <typename Digraph>
    11751179  DigraphReader<Digraph> digraphReader(const char* fn, Digraph& digraph) {
    1176     return DigraphReader<Digraph>(fn, digraph);
     1180    DigraphReader<Digraph> tmp(fn, digraph);
     1181    return tmp;
    11771182  }
    11781183}
    11791184
  • lemon/lgf_writer.h

    diff -r 33247f6fff16 -r c82fd9568d75 lemon/lgf_writer.h
    a b  
    195195        return;
    196196      default:
    197197        if (c < 0x20) {
     198          std::ios::fmtflags flags = os.flags();
    198199          os << '\\' << std::oct << static_cast<int>(c);
     200          os.flags(flags);
    199201        } else {
    200202          os << c;
    201203        }
     
    243245  /// writer, and eventually the writing is executed with the \c run()
    244246  /// member function. A map writing rule can be added to the writer
    245247  /// with the \c nodeMap() or \c arcMap() members. An optional
    246   /// converter parameter can also be added as a standard functor converting from
    247   /// the value type of the map to std::string. If it is set, it will
    248   /// determine how the map's value type is written to the output
    249   /// stream. If the functor is not set, then a default conversion
    250   /// will be used. The \c attribute(), \c node() and \c arc() functions
    251   /// are used to add attribute writing rules.
     248  /// converter parameter can also be added as a standard functor
     249  /// converting from the value type of the map to std::string. If it
     250  /// is set, it will determine how the map's value type is written to
     251  /// the output stream. If the functor is not set, then a default
     252  /// conversion will be used. The \c attribute(), \c node() and \c
     253  /// arc() functions are used to add attribute writing rules.
    252254  ///
    253255  ///\code
    254256  ///     DigraphWriter<Digraph>(std::cout, digraph).
     
    269271  /// attributes() functions.
    270272  ///
    271273  /// The \c skipNodes() and \c skipArcs() functions forbid the
    272   /// writing of the sections. If two arc sections should be written to the
    273   /// output, it can be done in two passes, the first pass writes the
    274   /// node section and the first arc section, then the second pass
    275   /// skips the node section and writes just the arc section to the
    276   /// stream. The output stream can be retrieved with the \c ostream()
    277   /// function, hence the second pass can append its output to the output of the
    278   /// first pass.
     274  /// writing of the sections. If two arc sections should be written
     275  /// to the output, it can be done in two passes, the first pass
     276  /// writes the node section and the first arc section, then the
     277  /// second pass skips the node section and writes just the arc
     278  /// section to the stream. The output stream can be retrieved with
     279  /// the \c ostream() function, hence the second pass can append its
     280  /// output to the output of the first pass.
    279281  template <typename _Digraph>
    280282  class DigraphWriter {
    281283  public:
     
    349351      : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
    350352        _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
    351353
    352       other.is = 0;
     354      other._os = 0;
    353355      other.local_os = false;
    354356
    355357      _node_index.swap(other._node_index);
     
    717719
    718720  /// \relates DigraphWriter
    719721  template <typename Digraph>
    720   DigraphWriter<Digraph> digraphWriter(std::istream& is, Digraph& digraph) {
    721     return DigraphWriter<Digraph>(is, digraph);
     722  DigraphWriter<Digraph> digraphWriter(std::ostream& os, Digraph& digraph) {
     723    DigraphWriter<Digraph> tmp(os, digraph);
     724    return tmp;
    722725  }
    723726
    724727  /// \relates DigraphWriter
    725728  template <typename Digraph>
    726729  DigraphWriter<Digraph> digraphWriter(const std::string& fn,
    727730                                       Digraph& digraph) {
    728     return DigraphWriter<Digraph>(fn, digraph);
     731    DigraphWriter<Digraph> tmp(fn, digraph);
     732    return tmp;
    729733  }
    730734
    731735  /// \relates DigraphWriter
    732736  template <typename Digraph>
    733737  DigraphWriter<Digraph> digraphWriter(const char* fn, Digraph& digraph) {
    734     return DigraphWriter<Digraph>(fn, digraph);
     738    DigraphWriter<Digraph> tmp(fn, digraph);
     739    return tmp;
    735740  }
    736741}
    737742