COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lgf_reader.h

    r190 r201  
    1919///\ingroup lemon_io
    2020///\file
    21 ///\brief Lemon Graph Format reader.
     21///\brief \ref lgf-format "Lemon Graph Format" reader.
    2222
    2323
     
    196196    };
    197197
    198     bool isWhiteSpace(char c) {
     198    inline bool isWhiteSpace(char c) {
    199199      return c == ' ' || c == '\t' || c == '\v' ||
    200200        c == '\n' || c == '\r' || c == '\f';
    201201    }
    202202   
    203     bool isOct(char c) {
     203    inline bool isOct(char c) {
    204204      return '0' <= c && c <='7';
    205205    }
    206206   
    207     int valueOct(char c) {
     207    inline int valueOct(char c) {
    208208      LEMON_ASSERT(isOct(c), "The character is not octal.");
    209209      return c - '0';
    210210    }
    211211
    212     bool isHex(char c) {
     212    inline bool isHex(char c) {
    213213      return ('0' <= c && c <= '9') ||
    214214        ('a' <= c && c <= 'z') ||
     
    216216    }
    217217   
    218     int valueHex(char c) {
     218    inline int valueHex(char c) {
    219219      LEMON_ASSERT(isHex(c), "The character is not hexadecimal.");
    220220      if ('0' <= c && c <= '9') return c - '0';
     
    223223    }
    224224
    225     bool isIdentifierFirstChar(char c) {
     225    inline bool isIdentifierFirstChar(char c) {
    226226      return ('a' <= c && c <= 'z') ||
    227227        ('A' <= c && c <= 'Z') || c == '_';
    228228    }
    229229
    230     bool isIdentifierChar(char c) {
     230    inline bool isIdentifierChar(char c) {
    231231      return isIdentifierFirstChar(c) ||
    232232        ('0' <= c && c <= '9');
    233233    }
    234234
    235     char readEscape(std::istream& is) {
     235    inline char readEscape(std::istream& is) {
    236236      char c;
    237237      if (!is.get(c))
     
    285285    }
    286286   
    287     std::istream& readToken(std::istream& is, std::string& str) {
     287    inline std::istream& readToken(std::istream& is, std::string& str) {
    288288      std::ostringstream os;
    289289
     
    401401  /// \ingroup lemon_io
    402402  /// 
    403   /// \brief LGF reader for directed graphs
     403  /// \brief \ref lgf-format "LGF" reader for directed graphs
    404404  ///
    405405  /// This utility reads an \ref lgf-format "LGF" file.
     
    411411  /// with the \c nodeMap() or \c arcMap() members. An optional
    412412  /// converter parameter can also be added as a standard functor
    413   /// converting from std::string to the value type of the map. If it
     413  /// converting from \c std::string to the value type of the map. If it
    414414  /// is set, it will determine how the tokens in the file should be
    415   /// is converted to the map's value type. If the functor is not set,
     415  /// converted to the value type of the map. If the functor is not set,
    416416  /// then a default conversion will be used. One map can be read into
    417417  /// multiple map objects at the same time. The \c attribute(), \c
     
    420420  ///
    421421  ///\code
    422   ///     DigraphReader<Digraph>(std::cin, digraph).
    423   ///       nodeMap("coordinates", coord_map).
    424   ///       arcMap("capacity", cap_map).
    425   ///       node("source", src).
    426   ///       node("target", trg).
    427   ///       attribute("caption", caption).
    428   ///       run();
     422  /// DigraphReader<Digraph>(std::cin, digraph).
     423  ///   nodeMap("coordinates", coord_map).
     424  ///   arcMap("capacity", cap_map).
     425  ///   node("source", src).
     426  ///   node("target", trg).
     427  ///   attribute("caption", caption).
     428  ///   run();
    429429  ///\endcode
    430430  ///
     
    438438  /// graph) during the reading, but instead the label map of the items
    439439  /// are given as a parameter of these functions. An
    440   /// application of these function is multipass reading, which is
    441   /// important if two \e \@arcs sections must be read from the
    442   /// file. In this example the first phase would read the node set and one
     440  /// application of these functions is multipass reading, which is
     441  /// important if two \c \@arcs sections must be read from the
     442  /// file. In this case the first phase would read the node set and one
    443443  /// of the arc sets, while the second phase would read the second arc
    444444  /// set into an \e ArcSet class (\c SmartArcSet or \c ListArcSet).
    445445  /// The previously read label node map should be passed to the \c
    446446  /// useNodes() functions. Another application of multipass reading when
    447   /// paths are given as a node map or an arc map. It is impossible read this in
     447  /// paths are given as a node map or an arc map. It is impossible to read this in
    448448  /// a single pass, because the arcs are not constructed when the node
    449449  /// maps are read.
     
    736736    /// Use previously constructed node set, and specify the node
    737737    /// label map and a functor which converts the label map values to
    738     /// std::string.
     738    /// \c std::string.
    739739    template <typename Map, typename Converter>
    740740    DigraphReader& useNodes(const Map& map,
     
    769769    /// Use previously constructed arc set, and specify the arc
    770770    /// label map and a functor which converts the label map values to
    771     /// std::string.
     771    /// \c std::string.
    772772    template <typename Map, typename Converter>
    773773    DigraphReader& useArcs(const Map& map,
     
    785785    ///
    786786    /// Omit the reading of the node section. This implies that each node
    787     /// map reading rule will be abanoned, and the nodes of the graph
     787    /// map reading rule will be abandoned, and the nodes of the graph
    788788    /// will not be constructed, which usually cause that the arc set
    789     /// could not be read due to lack of node name
    790     /// resolving. Therefore, the \c skipArcs() should be used too, or
    791     /// the useNodes() member function should be used to specify the
    792     /// label of the nodes.
     789    /// could not be read due to lack of node name resolving.
     790    /// Therefore \c skipArcs() function should also be used, or
     791    /// \c useNodes() should be used to specify the label of the nodes.
    793792    DigraphReader& skipNodes() {
    794793      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
     
    800799    ///
    801800    /// Omit the reading of the arc section. This implies that each arc
    802     /// map reading rule will be abanoned, and the arcs of the graph
     801    /// map reading rule will be abandoned, and the arcs of the graph
    803802    /// will not be constructed.
    804803    DigraphReader& skipArcs() {
     
    11761175  };
    11771176
     1177  /// \brief Return a \ref DigraphReader class
     1178  ///
     1179  /// This function just returns a \ref DigraphReader class.
    11781180  /// \relates DigraphReader
    11791181  template <typename Digraph>
     
    11831185  }
    11841186
     1187  /// \brief Return a \ref DigraphReader class
     1188  ///
     1189  /// This function just returns a \ref DigraphReader class.
    11851190  /// \relates DigraphReader
    11861191  template <typename Digraph>
     
    11911196  }
    11921197
     1198  /// \brief Return a \ref DigraphReader class
     1199  ///
     1200  /// This function just returns a \ref DigraphReader class.
    11931201  /// \relates DigraphReader
    11941202  template <typename Digraph>
     
    12121220  /// \ingroup lemon_io
    12131221  /// 
    1214   /// \brief LGF reader for undirected graphs
     1222  /// \brief \ref lgf-format "LGF" reader for undirected graphs
    12151223  ///
    12161224  /// This utility reads an \ref lgf-format "LGF" file.
     1225  ///
     1226  /// It can be used almost the same way as \c DigraphReader.
     1227  /// The only difference is that this class can handle edges and
     1228  /// edge maps as well as arcs and arc maps.
     1229  ///
     1230  /// The columns in the \c \@edges (or \c \@arcs) section are the
     1231  /// edge maps. However, if there are two maps with the same name
     1232  /// prefixed with \c '+' and \c '-', then these can be read into an
     1233  /// arc map.  Similarly, an attribute can be read into an arc, if
     1234  /// it's value is an edge label prefixed with \c '+' or \c '-'.
    12171235  template <typename _Graph>
    12181236  class GraphReader {
     
    12631281    /// \brief Constructor
    12641282    ///
    1265     /// Construct a undirected graph reader, which reads from the given
     1283    /// Construct an undirected graph reader, which reads from the given
    12661284    /// input stream.
    12671285    GraphReader(std::istream& is, Graph& graph)
     
    12721290    /// \brief Constructor
    12731291    ///
    1274     /// Construct a undirected graph reader, which reads from the given
     1292    /// Construct an undirected graph reader, which reads from the given
    12751293    /// file.
    12761294    GraphReader(const std::string& fn, Graph& graph)
     
    12811299    /// \brief Constructor
    12821300    ///
    1283     /// Construct a undirected graph reader, which reads from the given
     1301    /// Construct an undirected graph reader, which reads from the given
    12841302    /// file.
    12851303    GraphReader(const char* fn, Graph& graph)
     
    14981516    /// \brief Set \c \@nodes section to be read
    14991517    ///
    1500     /// Set \c \@nodes section to be read
     1518    /// Set \c \@nodes section to be read.
    15011519    GraphReader& nodes(const std::string& caption) {
    15021520      _nodes_caption = caption;
     
    15061524    /// \brief Set \c \@edges section to be read
    15071525    ///
    1508     /// Set \c \@edges section to be read
     1526    /// Set \c \@edges section to be read.
    15091527    GraphReader& edges(const std::string& caption) {
    15101528      _edges_caption = caption;
     
    15141532    /// \brief Set \c \@attributes section to be read
    15151533    ///
    1516     /// Set \c \@attributes section to be read
     1534    /// Set \c \@attributes section to be read.
    15171535    GraphReader& attributes(const std::string& caption) {
    15181536      _attributes_caption = caption;
     
    15451563    /// Use previously constructed node set, and specify the node
    15461564    /// label map and a functor which converts the label map values to
    1547     /// std::string.
     1565    /// \c std::string.
    15481566    template <typename Map, typename Converter>
    15491567    GraphReader& useNodes(const Map& map,
     
    15781596    /// Use previously constructed edge set, and specify the edge
    15791597    /// label map and a functor which converts the label map values to
    1580     /// std::string.
     1598    /// \c std::string.
    15811599    template <typename Map, typename Converter>
    15821600    GraphReader& useEdges(const Map& map,
     
    15911609    }
    15921610
    1593     /// \brief Skips the reading of node section
     1611    /// \brief Skip the reading of node section
    15941612    ///
    15951613    /// Omit the reading of the node section. This implies that each node
    1596     /// map reading rule will be abanoned, and the nodes of the graph
     1614    /// map reading rule will be abandoned, and the nodes of the graph
    15971615    /// will not be constructed, which usually cause that the edge set
    15981616    /// could not be read due to lack of node name
    1599     /// resolving. Therefore, the \c skipEdges() should be used too, or
    1600     /// the useNodes() member function should be used to specify the
    1601     /// label of the nodes.
     1617    /// could not be read due to lack of node name resolving.
     1618    /// Therefore \c skipEdges() function should also be used, or
     1619    /// \c useNodes() should be used to specify the label of the nodes.
    16021620    GraphReader& skipNodes() {
    16031621      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
     
    16061624    }
    16071625
    1608     /// \brief Skips the reading of edge section
     1626    /// \brief Skip the reading of edge section
    16091627    ///
    16101628    /// Omit the reading of the edge section. This implies that each edge
    1611     /// map reading rule will be abanoned, and the edges of the graph
     1629    /// map reading rule will be abandoned, and the edges of the graph
    16121630    /// will not be constructed.
    16131631    GraphReader& skipEdges() {
     
    19832001  };
    19842002
     2003  /// \brief Return a \ref GraphReader class
     2004  ///
     2005  /// This function just returns a \ref GraphReader class.
    19852006  /// \relates GraphReader
    19862007  template <typename Graph>
     
    19902011  }
    19912012
     2013  /// \brief Return a \ref GraphReader class
     2014  ///
     2015  /// This function just returns a \ref GraphReader class.
    19922016  /// \relates GraphReader
    19932017  template <typename Graph>
     
    19982022  }
    19992023
     2024  /// \brief Return a \ref GraphReader class
     2025  ///
     2026  /// This function just returns a \ref GraphReader class.
    20002027  /// \relates GraphReader
    20012028  template <typename Graph>
     
    20112038  SectionReader sectionReader(const char* fn);
    20122039 
     2040  /// \ingroup lemon_io
     2041  ///
    20132042  /// \brief Section reader class
    20142043  ///
    2015   /// In the \e LGF file extra sections can be placed, which contain
    2016   /// any data in arbitrary format. Such sections can be read with
    2017   /// this class. A reading rule can be added with two different
    2018   /// functions, with the \c sectionLines() function a functor can
    2019   /// process the section line-by-line. While with the \c
     2044  /// In the \ref lgf-format "LGF" file extra sections can be placed,
     2045  /// which contain any data in arbitrary format. Such sections can be
     2046  /// read with this class. A reading rule can be added to the class
     2047  /// with two different functions. With the \c sectionLines() function a
     2048  /// functor can process the section line-by-line, while with the \c
    20202049  /// sectionStream() member the section can be read from an input
    20212050  /// stream.
     
    21062135    ///\endcode
    21072136    ///
    2108     /// The functor is implemented as an struct:
     2137    /// The functor is implemented as a struct:
    21092138    ///\code
    21102139    ///  struct NumberSection {
     
    21242153    template <typename Functor>
    21252154    SectionReader& sectionLines(const std::string& type, Functor functor) {
    2126       LEMON_ASSERT(!type.empty(), "Type is not empty.");
     2155      LEMON_ASSERT(!type.empty(), "Type is empty.");
    21272156      LEMON_ASSERT(_sections.find(type) == _sections.end(),
    21282157                   "Multiple reading of section.");
     
    21362165    ///
    21372166    /// The first parameter is the type of the section, the second is
    2138     /// a functor, which takes an \c std::istream& and an int&
     2167    /// a functor, which takes an \c std::istream& and an \c int&
    21392168    /// parameter, the latter regard to the line number of stream. The
    21402169    /// functor can read the input while the section go on, and the
     
    21422171    template <typename Functor>
    21432172    SectionReader& sectionStream(const std::string& type, Functor functor) {
    2144       LEMON_ASSERT(!type.empty(), "Type is not empty.");
     2173      LEMON_ASSERT(!type.empty(), "Type is empty.");
    21452174      LEMON_ASSERT(_sections.find(type) == _sections.end(),
    21462175                   "Multiple reading of section.");
     
    21872216    /// \brief Start the batch processing
    21882217    ///
    2189     /// This function starts the batch processing
     2218    /// This function starts the batch processing.
    21902219    void run() {
    21912220     
     
    22402269  };
    22412270
     2271  /// \brief Return a \ref SectionReader class
     2272  ///
     2273  /// This function just returns a \ref SectionReader class.
    22422274  /// \relates SectionReader
    22432275  inline SectionReader sectionReader(std::istream& is) {
     
    22462278  }
    22472279
     2280  /// \brief Return a \ref SectionReader class
     2281  ///
     2282  /// This function just returns a \ref SectionReader class.
    22482283  /// \relates SectionReader
    22492284  inline SectionReader sectionReader(const std::string& fn) {
     
    22522287  }
    22532288
     2289  /// \brief Return a \ref SectionReader class
     2290  ///
     2291  /// This function just returns a \ref SectionReader class.
    22542292  /// \relates SectionReader
    22552293  inline SectionReader sectionReader(const char* fn) {
     
    22702308  /// reading the graph.
    22712309  ///
    2272   ///\code LgfContents contents("graph.lgf");
     2310  ///\code
     2311  /// LgfContents contents("graph.lgf");
    22732312  /// contents.run();
    22742313  ///
    2275   /// // does it contain any node section and arc section
     2314  /// // Does it contain any node section and arc section?
    22762315  /// if (contents.nodeSectionNum() == 0 || contents.arcSectionNum()) {
    2277   ///   std::cerr << "Failure, cannot find graph" << std::endl;
     2316  ///   std::cerr << "Failure, cannot find graph." << std::endl;
    22782317  ///   return -1;
    22792318  /// }
    2280   /// std::cout << "The name of the default node section : "
     2319  /// std::cout << "The name of the default node section: "
    22812320  ///           << contents.nodeSection(0) << std::endl;
    2282   /// std::cout << "The number of the arc maps : "
     2321  /// std::cout << "The number of the arc maps: "
    22832322  ///           << contents.arcMaps(0).size() << std::endl;
    2284   /// std::cout << "The name of second arc map : "
     2323  /// std::cout << "The name of second arc map: "
    22852324  ///           << contents.arcMaps(0)[1] << std::endl;
    22862325  ///\endcode
     
    23532392    }
    23542393
    2355     /// \brief Returns the section name at the given position.
    2356     ///
    2357     /// Returns the section name at the given position.
     2394    /// \brief Returns the node section name at the given position.
     2395    ///
     2396    /// Returns the node section name at the given position.
    23582397    const std::string& nodeSection(int i) const {
    23592398      return _node_sections[i];
     
    23802419    }
    23812420
    2382     /// \brief Returns the section name at the given position.
    2383     ///
    2384     /// Returns the section name at the given position.
     2421    /// \brief Returns the arc/edge section name at the given position.
     2422    ///
     2423    /// Returns the arc/edge section name at the given position.
    23852424    /// \note It is synonym of \c edgeSection().
    23862425    const std::string& arcSection(int i) const {
     
    24372476    }
    24382477
    2439     /// \brief Returns the section name at the given position.
    2440     ///
    2441     /// Returns the section name at the given position.
     2478    /// \brief Returns the attribute section name at the given position.
     2479    ///
     2480    /// Returns the attribute section name at the given position.
    24422481    const std::string& attributeSectionNames(int i) const {
    24432482      return _attribute_sections[i];
     
    25302569    /// @{
    25312570
    2532     /// \brief Start the reading
    2533     ///
    2534     /// This function starts the reading
     2571    /// \brief Starts the reading
     2572    ///
     2573    /// This function starts the reading.
    25352574    void run() {
    25362575
Note: See TracChangeset for help on using the changeset viewer.