Loading...
Searching...
No Matches
SectionReader Class Reference
Input-Output » LEMON Graph Format

## Detailed Description

In the LGF file extra sections can be placed, which contain any data in arbitrary format. Such sections can be read with this class. A reading rule can be added to the class with two different functions. With the `sectionLines()` function a functor can process the section line-by-line, while with the `sectionStream()` member the section can be read from an input stream.

`#include <lemon/lgf_reader.h>`

## Public Member Functions

| SectionReader (std::istream &is)
| Constructor.
| SectionReader (const std::string &fn)
| Constructor.
| SectionReader (const char *fn)
| Constructor.
| ~SectionReader ()
| Destructor.
Section Readers
template<typename Functor>
SectionReader & | sectionLines (const std::string &type, Functor functor)
| Add a section processor with line oriented reading.
template<typename Functor>
SectionReader & | sectionStream (const std::string &type, Functor functor)
| Add a section processor with stream oriented reading.
Execution of the Reader
void | run ()
| Start the batch processing.

## Related Symbols

(Note that these are not member symbols.)
SectionReader | sectionReader (std::istream &is)
| Return a SectionReader class.
SectionReader | sectionReader (const std::string &fn)
| Return a SectionReader class.
SectionReader | sectionReader (const char *fn)
| Return a SectionReader class.

## Constructor & Destructor Documentation

## SectionReader() [1/3]

SectionReader | ( | std::istream & | is | ) |

inline

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

## SectionReader() [2/3]

SectionReader | ( | const std::string & | fn | ) |

inline

Construct a section reader, which reads from the given file.

## SectionReader() [3/3]

SectionReader | ( | const char * | fn | ) |

inline

Construct a section reader, which reads from the given file.

## Member Function Documentation

## sectionLines()

template<typename Functor>

SectionReader & sectionLines | ( | const std::string & | type,
|  | Functor | functor )

inline

The first parameter is the type descriptor of the section, the second is a functor, which takes just one `std::string` parameter. At the reading process, each line of the section will be given to the functor object. However, the empty lines and the comment lines are filtered out, and the leading whitespaces are trimmed from each processed string.

For example, let's see a section, which contain several integers, which should be inserted into a vector.

@numbers
12 45 23
4
23 6

The functor is implemented as a struct:

struct NumberSection {
std::vector<int>& _data;
NumberSection(std::vector<int>& data) : _data(data) {}
void operator()(const std::string& line) {
std::istringstream ls(line);
int value;
while (ls >> value) _data.push_back(value);
}
};
// ...
reader.sectionLines("numbers", NumberSection(vec));

## sectionStream()

template<typename Functor>

SectionReader & sectionStream | ( | const std::string & | type,
|  | Functor | functor )

inline

The first parameter is the type of the section, the second is a functor, which takes an `std::istream&` and an `int&` parameter, the latter regard to the line number of stream. The functor can read the input while the section go on, and the line number should be modified accordingly.

## run()

void run | ( |  | ) |

inline

This function starts the batch processing.

## Friends And Related Symbol Documentation

## sectionReader() [1/2]

SectionReader sectionReader | ( | const std::string & | fn | ) |

related

This function just returns a SectionReader class.

See also
  sectionReader(std::istream& is)

## sectionReader() [2/2]

SectionReader sectionReader | ( | const char * | fn | ) |

related

This function just returns a SectionReader class.

See also
  sectionReader(std::istream& is)