COIN-OR::LEMON - Graph Library

Changeset 156:e561aa7675de in lemon-main for lemon/lgf_writer.h


Ignore:
Timestamp:
05/17/08 07:30:02 (17 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

More flexible header names in .lgf + largely improved doc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lgf_writer.h

    r148 r156  
    205205
    206206    bool requireEscape(const std::string& str) {
     207      if (str.empty() || str[0] == '@') return true;
    207208      std::istringstream is(str);
    208209      char c;
     
    232233  }
    233234 
    234   /// \e
     235  /// \ingroup lemon_io
     236  /// 
     237  /// \brief LGF writer for directed graphs
     238  ///
     239  /// This utility writes an \ref lgf-format "LGF" file.
     240  ///
     241  /// The writing method does a batch processing. The user creates a
     242  /// writer object, then various writing rules can be added to the
     243  /// writer, and eventually the writing is executed with the \c run()
     244  /// member function. A map writing rule can be added to the writer
     245  /// 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.
     252  ///
     253  ///\code
     254  ///     DigraphWriter<Digraph>(std::cout, digraph).
     255  ///       nodeMap("coordinates", coord_map).
     256  ///       nodeMap("size", size).
     257  ///       nodeMap("title", title).
     258  ///       arcMap("capacity", cap_map).
     259  ///       node("source", src).
     260  ///       node("target", trg).
     261  ///       attribute("caption", caption).
     262  ///       run();
     263  ///\endcode
     264  ///
     265  ///
     266  /// By default, the writer does not write additional captions to the
     267  /// sections, but they can be give as an optional parameter of
     268  /// the \c nodes(), \c arcs() or \c
     269  /// attributes() functions.
     270  ///
     271  /// 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.
    235279  template <typename _Digraph>
    236280  class DigraphWriter {
     
    274318  public:
    275319
    276     /// \e
     320    /// \brief Constructor
     321    ///
     322    /// Construct a directed graph writer, which writes to the given
     323    /// output stream.
    277324    DigraphWriter(std::ostream& is, Digraph& digraph)
    278325      : _os(&is), local_os(false), _digraph(digraph),
    279326        _skip_nodes(false), _skip_arcs(false) {}
    280327
    281     /// \e
     328    /// \brief Constructor
     329    ///
     330    /// Construct a directed graph writer, which writes to the given
     331    /// output file.
    282332    DigraphWriter(const std::string& fn, Digraph& digraph)
    283333      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
    284334        _skip_nodes(false), _skip_arcs(false) {}
    285335
    286     /// \e
     336    /// \brief Constructor
     337    ///
     338    /// Construct a directed graph writer, which writes to the given
     339    /// output file.
    287340    DigraphWriter(const char* fn, Digraph& digraph)
    288341      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
    289342        _skip_nodes(false), _skip_arcs(false) {}
    290343
     344    /// \brief Copy constructor
     345    ///
     346    /// The copy constructor transfers all data from the other writer,
     347    /// therefore the copied writer will not be usable more.
    291348    DigraphWriter(DigraphWriter& other)
    292349      : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
     
    308365    }
    309366
    310     /// \e
     367    /// \brief Destructor
    311368    ~DigraphWriter() {
    312369      for (typename NodeMaps::iterator it = _node_maps.begin();
     
    336393  public:
    337394
    338     /// \e
     395    /// \name Writing rules
     396    /// @{
     397   
     398    /// \brief Node map reading rule
     399    ///
     400    /// Add a node map reading rule to the writer.
    339401    template <typename Map>
    340402    DigraphWriter& nodeMap(const std::string& caption, const Map& map) {
     
    346408    }
    347409
    348     /// \e
     410    /// \brief Node map writing rule
     411    ///
     412    /// Add a node map writing rule with specialized converter to the
     413    /// writer.
    349414    template <typename Map, typename Converter>
    350415    DigraphWriter& nodeMap(const std::string& caption, const Map& map,
     
    357422    }
    358423
    359     /// \e
     424    /// \brief Arc map writing rule
     425    ///
     426    /// Add an arc map writing rule to the writer.
    360427    template <typename Map>
    361428    DigraphWriter& arcMap(const std::string& caption, const Map& map) {
     
    367434    }
    368435
    369     /// \e
     436    /// \brief Arc map writing rule
     437    ///
     438    /// Add an arc map writing rule with specialized converter to the
     439    /// writer.
    370440    template <typename Map, typename Converter>
    371441    DigraphWriter& arcMap(const std::string& caption, const Map& map,
     
    378448    }
    379449
    380     /// \e
     450    /// \brief Attribute writing rule
     451    ///
     452    /// Add an attribute writing rule to the writer.
    381453    template <typename Value>
    382454    DigraphWriter& attribute(const std::string& caption, const Value& value) {
     
    387459    }
    388460
    389     /// \e
     461    /// \brief Attribute writing rule
     462    ///
     463    /// Add an attribute writing rule with specialized converter to the
     464    /// writer.
    390465    template <typename Value, typename Converter>
    391466    DigraphWriter& attribute(const std::string& caption, const Value& value,
     
    397472    }
    398473
    399     /// \e
     474    /// \brief Node writing rule
     475    ///
     476    /// Add a node writing rule to the writer.
    400477    DigraphWriter& node(const std::string& caption, const Node& node) {
    401478      typedef _writer_bits::MapLookUpConverter<Node> Converter;
     
    407484    }
    408485
    409     /// \e
     486    /// \brief Arc writing rule
     487    ///
     488    /// Add an arc writing rule to writer.
    410489    DigraphWriter& arc(const std::string& caption, const Arc& arc) {
    411490      typedef _writer_bits::MapLookUpConverter<Arc> Converter;
     
    417496    }
    418497
    419     /// \e
     498    /// \name Select section by name
     499    /// @{
     500
     501    /// \brief Set \c \@nodes section to be read
     502    ///
     503    /// Set \c \@nodes section to be read
    420504    DigraphWriter& nodes(const std::string& caption) {
    421505      _nodes_caption = caption;
     
    423507    }
    424508
    425     /// \e
     509    /// \brief Set \c \@arcs section to be read
     510    ///
     511    /// Set \c \@arcs section to be read
    426512    DigraphWriter& arcs(const std::string& caption) {
    427513      _arcs_caption = caption;
     
    429515    }
    430516
    431     /// \e
     517    /// \brief Set \c \@attributes section to be read
     518    ///
     519    /// Set \c \@attributes section to be read
    432520    DigraphWriter& attributes(const std::string& caption) {
    433521      _attributes_caption = caption;
     
    435523    }
    436524
     525    /// \name Skipping section
     526    /// @{
     527
     528    /// \brief Skip writing the node set
     529    ///
     530    /// The \c \@nodes section will be not written to the stream.
    437531    DigraphWriter& skipNodes() {
    438532      LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member");
     
    440534    }
    441535
     536    /// \brief Skip writing arc set
     537    ///
     538    /// The \c \@arcs section will be not written to the stream.
    442539    DigraphWriter& skipArcs() {
    443540      LEMON_ASSERT(!_skip_arcs, "Multiple usage of skipArcs() member");
    444541      return *this;
    445542    }
     543
     544    /// @}
    446545
    447546  private:
     
    459558      *_os << "@nodes";
    460559      if (!_nodes_caption.empty()) {
    461         *_os << ' ' << _nodes_caption;
     560        _writer_bits::writeToken(*_os << ' ', _nodes_caption);
    462561      }
    463562      *_os << std::endl;
     
    468567      for (typename NodeMaps::iterator it = _node_maps.begin();
    469568           it != _node_maps.end(); ++it) {
    470         *_os << it->first << '\t';
     569        _writer_bits::writeToken(*_os, it->first) << '\t';
    471570      }
    472571      *_os << std::endl;
     
    519618      *_os << "@arcs";
    520619      if (!_arcs_caption.empty()) {
    521         *_os << ' ' << _arcs_caption;
     620        _writer_bits::writeToken(*_os << ' ', _arcs_caption);
    522621      }
    523622      *_os << std::endl;
     
    529628      for (typename ArcMaps::iterator it = _arc_maps.begin();
    530629           it != _arc_maps.end(); ++it) {
    531         *_os << it->first << '\t';
     630        _writer_bits::writeToken(*_os, it->first) << '\t';
    532631      }
    533632      *_os << std::endl;
     
    578677      *_os << "@attributes";
    579678      if (!_attributes_caption.empty()) {
    580         *_os << ' ' << _attributes_caption;
     679        _writer_bits::writeToken(*_os << ' ', _attributes_caption);
    581680      }
    582681      *_os << std::endl;
    583682      for (typename Attributes::iterator it = _attributes.begin();
    584683           it != _attributes.end(); ++it) {
    585         *_os << it->first << ' ';
     684        _writer_bits::writeToken(*_os, it->first) << ' ';
    586685        _writer_bits::writeToken(*_os, it->second->get());
    587686        *_os << std::endl;
     
    591690  public:
    592691   
    593     /// \e
     692    /// \name Execution of the writer   
     693    /// @{
     694
     695    /// \brief Start the batch processing
     696    ///
     697    /// This function starts the batch processing
    594698    void run() {
    595699      if (!_skip_nodes) {
     
    602706    }
    603707
    604     /// \e
    605     std::ostream& stream() {
     708    /// \brief Gives back the stream of the writer
     709    ///
     710    /// Gives back the stream of the writer
     711    std::ostream& ostream() {
    606712      return *_os;
    607713    }
     714
     715    /// @}
    608716  };
    609717
     718  /// \relates DigraphWriter
    610719  template <typename Digraph>
    611720  DigraphWriter<Digraph> digraphWriter(std::istream& is, Digraph& digraph) {
     
    613722  }
    614723
     724  /// \relates DigraphWriter
    615725  template <typename Digraph>
    616726  DigraphWriter<Digraph> digraphWriter(const std::string& fn,
     
    619729  }
    620730
     731  /// \relates DigraphWriter
    621732  template <typename Digraph>
    622733  DigraphWriter<Digraph> digraphWriter(const char* fn, Digraph& digraph) {
Note: See TracChangeset for help on using the changeset viewer.