COIN-OR::LEMON - Graph Library

Ticket #35: digraph_reader_doc.2.patch

File digraph_reader_doc.2.patch, 12.6 KB (added by Balazs Dezso, 17 years ago)
  • lemon/lgf_reader.h

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1210585936 -7200
    # Node ID ca6187a8a44be3b44e0292fc39c515c1ea5cd58e
    # Parent  5c3604513ed0256e35e5fd50c54cd0e37362397e
    Documentation for DigraphReader
    
    diff -r 5c3604513ed0 -r ca6187a8a44b lemon/lgf_reader.h
    a b  
    295295    }
    296296   
    297297  }
    298  
    299   /// \e
     298
     299  /// \ingroup lemon_io
     300  /// 
     301  /// \brief LGF reader for directed graphs
     302  ///
     303  /// The \e LGF (LEMON graph file) format is the default file format
     304  /// of the LEMON library. It is a text based, section oriented
     305  /// format, which defines some standard sections for storing graphs
     306  /// in text files. Each line with \c '#' first non-whitespace
     307  /// character is considered as a comment line. Each section starts with
     308  /// a header line, these lines starts with \c '@' character and the
     309  /// name of section type.  The standard sections are \c \@nodes, \c
     310  /// \@arcs and \c \@edges (these two names are completely equivalent)
     311  /// and \@attributes. Each header line may also have an optional
     312  /// name, which can be use to distinguish the sections of the same
     313  /// type.
     314  ///
     315  /// The \@nodes section describes a set of nodes and associated
     316  /// maps. The first is a header line consisting of the names of the
     317  /// maps, each of them is a sequence of underscore, letter and digit
     318  /// characters. One of the maps must be called \c "label", which
     319  /// plays special role in the file.  Each following non-empty line
     320  /// until the next section describes a node in the graph. These
     321  /// lines contain the values of the node maps associated to the
     322  /// current node. The values are plain or quoted tokens, a plain
     323  /// token is a sequence of non-whitespace characters. A quoted
     324  /// token is a character sequence surrounded by double quotes, and
     325  /// the sequence may contain escape sequences.
     326  ///
     327  /// The \c \@arcs section is very similar to the \c \@nodes section,
     328  /// it starts with a header line consists from the names of the arc
     329  /// maps, the \c "label" map is also necessary. The following lines
     330  /// contain the description of the arcs. The first two tokens are
     331  /// the source and the target node of the edge, then comes the map
     332  /// values. The source and target tokens must be node labels.
     333  ///
     334  /// The \c \@attrbiutes section contains key-value pairs, each line
     335  /// starts with an attribute name, and then an attribute value. The
     336  /// name is a sequence of underscore, letter and digit characters,
     337  /// while the value is plain or quoted string literal. The value
     338  /// could be a node or an arc label.
     339  ///
     340  ///\code
     341  /// @nodes
     342  /// label   coordinates size    title
     343  /// 1       (10,20)     10      "First node"
     344  /// 2       (80,80)     8       "Second node"
     345  /// 3       (40,10)     10      "Third node"
     346  /// @arcs
     347  ///         capacity
     348  /// 1   2   16
     349  /// 1   3   12
     350  /// 2   3   18
     351  /// @attributes
     352  /// source 1
     353  /// target 3
     354  /// caption "LEMON test digraph"
     355  ///\endcode
     356  ///
     357  /// The reading method does a batch processing. The user creates a
     358  /// reader object, then several reading rules can be added to the
     359  /// reader, and eventually the reading is executed with the \c run()
     360  /// member function. A map reading rule can be added to the reader
     361  /// with the \c nodeMap() or \c arcMap() members. The optional
     362  /// converter parameter can be a standard functor, which converts an
     363  /// std::string to the value type of the map, if it is set, it
     364  /// determines how the read string literal is converted to the map's
     365  /// value type. If the functor is not set, then a default conversion
     366  /// will be used. One map can be read in multiple map objects at the
     367  /// same time. The \c attribute(), \c node() and \c arc() functions
     368  /// are used to add attribute reading rules.
     369  ///
     370  ///\code
     371  ///     DigraphReader<Digraph>(std::cin, digraph).
     372  ///       nodeMap("coordinates", coord_map).
     373  ///       arcMap("capacity", cap_map).
     374  ///       node("source", src).
     375  ///       node("target", trg).
     376  ///       attribute("caption", caption).
     377  ///       run();
     378  ///\endcode
     379  ///
     380  /// By default the reader uses the first section in the file of the
     381  /// proper type. If a section has an optional name, then it can be
     382  /// selected to read with the \c nodes(), \c arcs() or \c attributes()
     383  /// functions.
     384  ///
     385  /// The \c useNodes() and \c useArcs() functions are used to specify
     386  /// that the nodes or arcs should not be constructed(added to the
     387  /// graph) during the reading, the argument of these functions is a
     388  /// node map or arc map determining the label map for the items. An
     389  /// application of these function is the multipass reading, which is
     390  /// important if two \e \@arcs section should be read from the
     391  /// file. In this example the first phase reads the node set and one
     392  /// of the arc set, while the second phase will read the second arc
     393  /// set into an \e ArcSet class (\c SmartArcSet or \c ListArcSet),
     394  /// the previously read label node map should be given to the \c
     395  /// useNodes() functions. An other multipass application is reading
     396  /// paths into a node map or an arc map. It is impossible in
     397  /// single pass, because the arcs are not constructed when the node
     398  /// maps are read.
    300399  template <typename _Digraph>
    301400  class DigraphReader {
    302401  public:
     
    341440
    342441  public:
    343442
    344     /// \e
     443    /// \brief Constructor
     444    ///
     445    /// Construct a directed graph reader, which reads from the given
     446    /// input stream.
    345447    DigraphReader(std::istream& is, Digraph& digraph)
    346448      : _is(&is), local_is(false), _digraph(digraph),
    347449        _use_nodes(false), _use_arcs(false) {}
    348450
    349     /// \e
     451    /// \brief Constructor
     452    ///
     453    /// Construct a directed graph reader, which reads from the given
     454    /// file.
    350455    DigraphReader(const std::string& fn, Digraph& digraph)
    351456      : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
    352457        _use_nodes(false), _use_arcs(false) {}
    353 
    354 
    355     /// \e
     458   
     459    /// \brief Constructor
     460    ///
     461    /// Construct a directed graph reader, which reads from the given
     462    /// file.
    356463    DigraphReader(const char* fn, Digraph& digraph)
    357464      : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
    358465        _use_nodes(false), _use_arcs(false) {}
    359466
    360     /// \e
     467    /// \brief Copy constructor
     468    ///
     469    /// The copy constructor transfers all data from the other reader,
     470    /// therefore the copied reader will not be useable more.
    361471    DigraphReader(DigraphReader& other)
    362472      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
    363473        _use_nodes(other._use_nodes), _use_arcs(other._use_arcs) {
     
    377487      _attributes_caption = other._attributes_caption;
    378488    }
    379489
    380     /// \e
     490    /// \brief Destructor
    381491    ~DigraphReader() {
    382492      for (typename NodeMaps::iterator it = _node_maps.begin();
    383493           it != _node_maps.end(); ++it) {
     
    406516
    407517  public:
    408518
    409     /// \e
     519    /// \name Reading rules
     520    /// @{
     521   
     522    /// \brief Node map reading rule
     523    ///
     524    /// Add a node map reading rule to the reader.
    410525    template <typename Map>
    411526    DigraphReader& nodeMap(const std::string& caption, Map& map) {
    412527      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
     
    416531      return *this;
    417532    }
    418533
    419     /// \e
     534    /// \brief Node map reading rule
     535    ///
     536    /// Add a node map reading rule with specialized converter to the
     537    /// reader.
    420538    template <typename Map, typename Converter>
    421539    DigraphReader& nodeMap(const std::string& caption, Map& map,
    422540                           const Converter& converter = Converter()) {
     
    427545      return *this;
    428546    }
    429547
    430     /// \e
     548    /// \brief Arc map reading rule
     549    ///
     550    /// Add an arc map reading rule to the reader.
    431551    template <typename Map>
    432552    DigraphReader& arcMap(const std::string& caption, Map& map) {
    433553      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
     
    437557      return *this;
    438558    }
    439559
    440     /// \e
     560    /// \brief Arc map reading rule
     561    ///
     562    /// Add an arc map reading rule with specialized converter to the
     563    /// reader.
    441564    template <typename Map, typename Converter>
    442565    DigraphReader& arcMap(const std::string& caption, Map& map,
    443566                          const Converter& converter = Converter()) {
     
    448571      return *this;
    449572    }
    450573
    451     /// \e
     574    /// \brief Attribute reading rule
     575    ///
     576    /// Add an attribute reading rule to the reader.
    452577    template <typename Value>
    453578    DigraphReader& attribute(const std::string& caption, Value& value) {
    454579      _reader_bits::ValueStorageBase* storage =
     
    457582      return *this;
    458583    }
    459584
    460     /// \e
     585    /// \brief Attribute reading rule
     586    ///
     587    /// Add an attribute reading rule with specialized converter to the
     588    /// reader.
    461589    template <typename Value, typename Converter>
    462590    DigraphReader& attribute(const std::string& caption, Value& value,
    463591                             const Converter& converter = Converter()) {
     
    467595      return *this;
    468596    }
    469597
    470     /// \e
     598    /// \brief Node reading rule
     599    ///
     600    /// Add a node reading rule with specialized converter to the
     601    /// reader.
    471602    DigraphReader& node(const std::string& caption, Node& node) {
    472603      typedef _reader_bits::MapLookUpConverter<Node> Converter;
    473604      Converter converter(_node_index);
     
    477608      return *this;
    478609    }
    479610
    480     /// \e
     611    /// \brief Arc reading rule
     612    ///
     613    /// Add an arc reading rule with specialized converter to the
     614    /// reader.
    481615    DigraphReader& arc(const std::string& caption, Arc& arc) {
    482616      typedef _reader_bits::MapLookUpConverter<Arc> Converter;
    483617      Converter converter(_arc_index);
     
    487621      return *this;
    488622    }
    489623
    490     /// \e
     624    /// @}
     625
     626    /// \name Select section by name
     627    /// @{
     628
     629    /// \brief Set \c \@nodes section to be read
     630    ///
     631    /// Set \c \@nodes section to be read
    491632    DigraphReader& nodes(const std::string& caption) {
    492633      _nodes_caption = caption;
    493634      return *this;
    494635    }
    495636
    496     /// \e
     637    /// \brief Set \c \@arcs section to be read
     638    ///
     639    /// Set \c \@arcs section to be read
    497640    DigraphReader& arcs(const std::string& caption) {
    498641      _arcs_caption = caption;
    499642      return *this;
    500643    }
    501644
    502     /// \e
     645    /// \brief Set \c \@attributes section to be read
     646    ///
     647    /// Set \c \@attributes section to be read
    503648    DigraphReader& attributes(const std::string& caption) {
    504649      _attributes_caption = caption;
    505650      return *this;
    506651    }
    507652
    508     /// \e
     653    /// @}
     654
     655    /// \name Using previously constructed node or arc set
     656    /// @{
     657
     658    /// \brief Use previously constructed node set
     659    ///
     660    /// Use previously constructed node set, and specify the node
     661    /// label map.
    509662    template <typename Map>
    510663    DigraphReader& useNodes(const Map& map) {
    511664      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
     
    518671      return *this;
    519672    }
    520673
    521     /// \e
     674    /// \brief Use previously constructed node set
     675    ///
     676    /// Use previously constructed node set, and specify the node
     677    /// label map and a functor which converts the label map values to
     678    /// std::string.
    522679    template <typename Map, typename Converter>
    523680    DigraphReader& useNodes(const Map& map,
    524681                            const Converter& converter = Converter()) {
     
    531688      return *this;
    532689    }
    533690
    534     /// \e
     691    /// \brief Use previously constructed arc set
     692    ///
     693    /// Use previously constructed arc set, and specify the arc
     694    /// label map.
    535695    template <typename Map>
    536696    DigraphReader& useArcs(const Map& map) {
    537697      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
     
    544704      return *this;
    545705    }
    546706
    547     /// \e
     707    /// \brief Use previously constructed arc set
     708    ///
     709    /// Use previously constructed arc set, and specify the arc
     710    /// label map and a functor which converts the label map values to
     711    /// std::string.
    548712    template <typename Map, typename Converter>
    549713    DigraphReader& useArcs(const Map& map,
    550714                            const Converter& converter = Converter()) {
     
    556720      }
    557721      return *this;
    558722    }
     723
     724    /// @}
    559725
    560726  private:
    561727
     
    827993    }
    828994
    829995  public:
    830    
    831     /// \e
     996
     997    /// \name Execution of the reader   
     998    /// @{
     999
     1000    /// \brief Start the batch processing
     1001    ///
     1002    /// This function starts the batch processing
    8321003    void run() {
    8331004     
    8341005      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
     
    8911062      }
    8921063
    8931064    }
     1065
     1066    /// @}
    8941067   
    8951068  };
    8961069