Public Member Functions | Friends

DigraphReader< DGR > Class Template Reference


Detailed Description

template<typename DGR>
class lemon::DigraphReader< DGR >

This utility reads an LGF file.

The reading method does a batch processing. The user creates a reader object, then various reading rules can be added to the reader, and eventually the reading is executed with the run() member function. A map reading rule can be added to the reader with the nodeMap() or arcMap() members. An optional converter parameter can also be added as a standard functor converting from std::string to the value type of the map. If it is set, it will determine how the tokens in the file should be converted to the value type of the map. If the functor is not set, then a default conversion will be used. One map can be read into multiple map objects at the same time. The attribute(), node() and arc() functions are used to add attribute reading rules.

      DigraphReader<DGR>(digraph, std::cin).
        nodeMap("coordinates", coord_map).
        arcMap("capacity", cap_map).
        node("source", src).
        node("target", trg).
        attribute("caption", caption).
        run();

By default, the reader uses the first section in the file of the proper type. If a section has an optional name, then it can be selected for reading by giving an optional name parameter to the nodes(), arcs() or attributes() functions.

The useNodes() and useArcs() functions are used to tell the reader that the nodes or arcs should not be constructed (added to the graph) during the reading, but instead the label map of the items are given as a parameter of these functions. An application of these functions is multipass reading, which is important if two @arcs sections must be read from the file. In this case the first phase would read the node set and one of the arc sets, while the second phase would read the second arc set into an ArcSet class (SmartArcSet or ListArcSet). The previously read label node map should be passed to the useNodes() functions. Another application of multipass reading when paths are given as a node map or an arc map. It is impossible to read this in a single pass, because the arcs are not constructed when the node maps are read.

#include <lemon/lgf_reader.h>

List of all members.

Public Member Functions

 DigraphReader (DGR &digraph, std::istream &is=std::cin)
 Constructor.
 DigraphReader (DGR &digraph, const std::string &fn)
 Constructor.
 DigraphReader (DGR &digraph, const char *fn)
 Constructor.
 ~DigraphReader ()
 Destructor.
Reading Rules
template<typename Map >
DigraphReadernodeMap (const std::string &caption, Map &map)
 Node map reading rule.
template<typename Map , typename Converter >
DigraphReadernodeMap (const std::string &caption, Map &map, const Converter &converter=Converter())
 Node map reading rule.
template<typename Map >
DigraphReaderarcMap (const std::string &caption, Map &map)
 Arc map reading rule.
template<typename Map , typename Converter >
DigraphReaderarcMap (const std::string &caption, Map &map, const Converter &converter=Converter())
 Arc map reading rule.
template<typename Value >
DigraphReaderattribute (const std::string &caption, Value &value)
 Attribute reading rule.
template<typename Value , typename Converter >
DigraphReaderattribute (const std::string &caption, Value &value, const Converter &converter=Converter())
 Attribute reading rule.
DigraphReadernode (const std::string &caption, Node &node)
 Node reading rule.
DigraphReaderarc (const std::string &caption, Arc &arc)
 Arc reading rule.
Select Section by Name
DigraphReadernodes (const std::string &caption)
 Set @nodes section to be read.
DigraphReaderarcs (const std::string &caption)
 Set @arcs section to be read.
DigraphReaderattributes (const std::string &caption)
 Set @attributes section to be read.
Using Previously Constructed Node or Arc Set
template<typename Map >
DigraphReaderuseNodes (const Map &map)
 Use previously constructed node set.
template<typename Map , typename Converter >
DigraphReaderuseNodes (const Map &map, const Converter &converter=Converter())
 Use previously constructed node set.
template<typename Map >
DigraphReaderuseArcs (const Map &map)
 Use previously constructed arc set.
template<typename Map , typename Converter >
DigraphReaderuseArcs (const Map &map, const Converter &converter=Converter())
 Use previously constructed arc set.
DigraphReaderskipNodes ()
 Skips the reading of node section.
DigraphReaderskipArcs ()
 Skips the reading of arc section.
Execution of the Reader
void run ()
 Start the batch processing.

Friends

template<typename TDGR >
DigraphReader< TDGR > digraphReader (TDGR &digraph, std::istream &is)
 Return a DigraphReader class.
template<typename TDGR >
DigraphReader< TDGR > digraphReader (TDGR &digraph, const std::string &fn)
 Return a DigraphReader class.
template<typename TDGR >
DigraphReader< TDGR > digraphReader (TDGR &digraph, const char *fn)
 Return a DigraphReader class.

Constructor & Destructor Documentation

DigraphReader ( DGR &  digraph,
std::istream &  is = std::cin 
) [inline]

Construct a directed graph reader, which reads from the given input stream.

DigraphReader ( DGR &  digraph,
const std::string &  fn 
) [inline]

Construct a directed graph reader, which reads from the given file.

DigraphReader ( DGR &  digraph,
const char *  fn 
) [inline]

Construct a directed graph reader, which reads from the given file.


Member Function Documentation

DigraphReader& nodeMap ( const std::string &  caption,
Map &  map 
) [inline]

Add a node map reading rule to the reader.

DigraphReader& nodeMap ( const std::string &  caption,
Map &  map,
const Converter &  converter = Converter() 
) [inline]

Add a node map reading rule with specialized converter to the reader.

DigraphReader& arcMap ( const std::string &  caption,
Map &  map 
) [inline]

Add an arc map reading rule to the reader.

DigraphReader& arcMap ( const std::string &  caption,
Map &  map,
const Converter &  converter = Converter() 
) [inline]

Add an arc map reading rule with specialized converter to the reader.

DigraphReader& attribute ( const std::string &  caption,
Value &  value 
) [inline]

Add an attribute reading rule to the reader.

DigraphReader& attribute ( const std::string &  caption,
Value &  value,
const Converter &  converter = Converter() 
) [inline]

Add an attribute reading rule with specialized converter to the reader.

DigraphReader& node ( const std::string &  caption,
Node &  node 
) [inline]

Add a node reading rule to reader.

DigraphReader& arc ( const std::string &  caption,
Arc &  arc 
) [inline]

Add an arc reading rule to reader.

DigraphReader& nodes ( const std::string &  caption) [inline]

Set @nodes section to be read

DigraphReader& arcs ( const std::string &  caption) [inline]

Set @arcs section to be read

DigraphReader& attributes ( const std::string &  caption) [inline]

Set @attributes section to be read

DigraphReader& useNodes ( const Map &  map) [inline]

Use previously constructed node set, and specify the node label map.

DigraphReader& useNodes ( const Map &  map,
const Converter &  converter = Converter() 
) [inline]

Use previously constructed node set, and specify the node label map and a functor which converts the label map values to std::string.

DigraphReader& useArcs ( const Map &  map) [inline]

Use previously constructed arc set, and specify the arc label map.

DigraphReader& useArcs ( const Map &  map,
const Converter &  converter = Converter() 
) [inline]

Use previously constructed arc set, and specify the arc label map and a functor which converts the label map values to std::string.

DigraphReader& skipNodes ( ) [inline]

Omit the reading of the node section. This implies that each node map reading rule will be abandoned, and the nodes of the graph will not be constructed, which usually cause that the arc set could not be read due to lack of node name resolving. Therefore skipArcs() function should also be used, or useNodes() should be used to specify the label of the nodes.

DigraphReader& skipArcs ( ) [inline]

Omit the reading of the arc section. This implies that each arc map reading rule will be abandoned, and the arcs of the graph will not be constructed.

void run ( ) [inline]

This function starts the batch processing


Friends And Related Function Documentation

DigraphReader< TDGR > digraphReader ( TDGR &  digraph,
const std::string &  fn 
) [friend]

This function just returns a DigraphReader class.

See also:
digraphReader(TDGR& digraph, std::istream& is)
DigraphReader< TDGR > digraphReader ( TDGR &  digraph,
const char *  fn 
) [friend]

This function just returns a DigraphReader class.

See also:
digraphReader(TDGR& digraph, std::istream& is)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines