Loading...
Searching...
No Matches
DigraphReader< DGR > Class Template Reference
Input-Output » LEMON Graph Format

## 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();
lemon::DigraphReader::run
void run()
Start the batch processing.
Definition lgf_reader.h:1164
lemon::DigraphReader::attribute
DigraphReader & attribute(const std::string &caption, Value &value)
Attribute reading rule.
Definition lgf_reader.h:687
lemon::DigraphReader::arcMap
DigraphReader & arcMap(const std::string &caption, Map &map)
Arc map reading rule.
Definition lgf_reader.h:661
lemon::DigraphReader::nodeMap
DigraphReader & nodeMap(const std::string &caption, Map &map)
Node map reading rule.
Definition lgf_reader.h:635
lemon::DigraphReader::DigraphReader
DigraphReader(DGR &digraph, std::istream &is=std::cin)
Constructor.
Definition lgf_reader.h:535
lemon::DigraphReader::node
DigraphReader & node(const std::string &caption, Node &node)
Node reading rule.
Definition lgf_reader.h:710

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>`

## 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>
DigraphReader & | nodeMap (const std::string &caption, Map &map)
| Node map reading rule.
template<typename Map, typename Converter>
DigraphReader & | nodeMap (const std::string &caption, Map &map, const Converter &converter=Converter())
| Node map reading rule.
template<typename Map>
DigraphReader & | arcMap (const std::string &caption, Map &map)
| Arc map reading rule.
template<typename Map, typename Converter>
DigraphReader & | arcMap (const std::string &caption, Map &map, const Converter &converter=Converter())
| Arc map reading rule.
template<typename Value>
DigraphReader & | attribute (const std::string &caption, Value &value)
| Attribute reading rule.
template<typename Value, typename Converter>
DigraphReader & | attribute (const std::string &caption, Value &value, const Converter &converter=Converter())
| Attribute reading rule.
DigraphReader & | node (const std::string &caption, Node &node)
| Node reading rule.
DigraphReader & | arc (const std::string &caption, Arc &arc)
| Arc reading rule.
Select Section by Name
DigraphReader & | nodes (const std::string &caption)
| Set `@nodes` section to be read.
DigraphReader & | arcs (const std::string &caption)
| Set `@arcs` section to be read.
DigraphReader & | attributes (const std::string &caption)
| Set `@attributes` section to be read.
Using Previously Constructed Node or Arc Set
template<typename Map>
DigraphReader & | useNodes (const Map &map)
| Use previously constructed node set.
template<typename Map, typename Converter>
DigraphReader & | useNodes (const Map &map, const Converter &converter=Converter())
| Use previously constructed node set.
template<typename Map>
DigraphReader & | useArcs (const Map &map)
| Use previously constructed arc set.
template<typename Map, typename Converter>
DigraphReader & | useArcs (const Map &map, const Converter &converter=Converter())
| Use previously constructed arc set.
DigraphReader & | skipNodes ()
| Skips the reading of node section.
DigraphReader & | skipArcs ()
| Skips the reading of arc section.
Execution of the Reader
void | run ()
| Start the batch processing.

## Related Symbols

(Note that these are not member symbols.)
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() [1/3]

template<typename DGR>

DigraphReader | ( | DGR & | digraph,
|  | std::istream & | is = std::cin )

inline

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

## DigraphReader() [2/3]

template<typename DGR>

DigraphReader | ( | DGR & | digraph,
|  | const std::string & | fn )

inline

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

## DigraphReader() [3/3]

template<typename DGR>

DigraphReader | ( | DGR & | digraph,
|  | const char * | fn )

inline

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

## Member Function Documentation

## nodeMap() [1/2]

template<typename DGR>
template<typename Map>

DigraphReader & nodeMap | ( | const std::string & | caption,
|  | Map & | map )

inline

Add a node map reading rule to the reader.

## nodeMap() [2/2]

template<typename DGR>
template<typename Map, typename Converter>

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.

## arcMap() [1/2]

template<typename DGR>
template<typename Map>

DigraphReader & arcMap | ( | const std::string & | caption,
|  | Map & | map )

inline

Add an arc map reading rule to the reader.

## arcMap() [2/2]

template<typename DGR>
template<typename Map, typename Converter>

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.

## attribute() [1/2]

template<typename DGR>
template<typename Value>

DigraphReader & attribute | ( | const std::string & | caption,
|  | Value & | value )

inline

Add an attribute reading rule to the reader.

## attribute() [2/2]

template<typename DGR>
template<typename Value, typename Converter>

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

inline

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

## node()

template<typename DGR>

DigraphReader & node | ( | const std::string & | caption,
|  | Node & | node )

inline

Add a node reading rule to reader.

## arc()

template<typename DGR>

DigraphReader & arc | ( | const std::string & | caption,
|  | Arc & | arc )

inline

Add an arc reading rule to reader.

## nodes()

template<typename DGR>

DigraphReader & nodes | ( | const std::string & | caption | ) |

inline

Set `@nodes` section to be read

## arcs()

template<typename DGR>

DigraphReader & arcs | ( | const std::string & | caption | ) |

inline

Set `@arcs` section to be read

## attributes()

template<typename DGR>

DigraphReader & attributes | ( | const std::string & | caption | ) |

inline

Set `@attributes` section to be read

## useNodes() [1/2]

template<typename DGR>
template<typename Map>

DigraphReader & useNodes | ( | const Map & | map | ) |

inline

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

## useNodes() [2/2]

template<typename DGR>
template<typename Map, typename Converter>

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`.

## useArcs() [1/2]

template<typename DGR>
template<typename Map>

DigraphReader & useArcs | ( | const Map & | map | ) |

inline

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

## useArcs() [2/2]

template<typename DGR>
template<typename Map, typename Converter>

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`.

## skipNodes()

template<typename DGR>

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.

## skipArcs()

template<typename DGR>

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.

## run()

template<typename DGR>

void run | ( |  | ) |

inline

This function starts the batch processing

## Friends And Related Symbol Documentation

## digraphReader() [1/2]

template<typename TDGR>

DigraphReader< TDGR > digraphReader | ( | TDGR & | digraph,
|  | const std::string & | fn )

related

This function just returns a DigraphReader class.

See also
  digraphReader(TDGR& digraph, std::istream& is)

## digraphReader() [2/2]

template<typename TDGR>

DigraphReader< TDGR > digraphReader | ( | TDGR & | digraph,
|  | const char * | fn )

related

This function just returns a DigraphReader class.

See also
  digraphReader(TDGR& digraph, std::istream& is)