In the LGF file extra sections can be placed, which contain any data in arbitrary format. Such sections can be written with this class. A writing rule can be added to the class with two different functions. With the sectionLines()
function a generator can write the section line-by-line, while with the sectionStream()
member the section can be written to an output stream.
SectionWriter& sectionLines |
( |
const std::string & |
type, |
|
|
Functor |
functor |
|
) |
| |
|
inline |
The first parameter is the type descriptor of the section, the second is a generator with std::string values. At the writing process, the returned std::string
will be written into the output file until it is an empty string.
For example, an integer vector is written into a section.
* @numbers
* 12 45 23 78
* 4 28 38 28
* 23 6 16
*
The generator is implemented as a struct.
* struct NumberSection {
* std::vector<int>::const_iterator _it, _end;
* NumberSection(const std::vector<int>& data)
* : _it(data.begin()), _end(data.end()) {}
* std::string operator()() {
* int rem_in_line = 4;
* std::ostringstream ls;
* while (rem_in_line > 0 && _it != _end) {
* ls << *(_it++) << ' ';
* --rem_in_line;
* }
* return ls.str();
* }
* };
*
*
*
* writer.sectionLines("numbers", NumberSection(vec));
*