abLEMON 1.9.0-101-gccb8629
A maintained fork of LEMON
Loading...
Searching...
No Matches
SectionWriter Class Reference

Section writer class. More...

#include <lemon/lgf_writer.h>

Public Member Functions

 SectionWriter (std::ostream &os)
 Constructor.
 SectionWriter (const std::string &fn)
 Constructor.
 SectionWriter (const char *fn)
 Constructor.
 ~SectionWriter ()
 Destructor.
Section Writers
template< typename Functor >
SectionWriter & sectionLines (const std::string &type, Functor functor)
 Add a section writer with line oriented writing.
template< typename Functor >
SectionWriter & sectionStream (const std::string &type, Functor functor)
 Add a section writer with stream oriented writing.
Execution of the Writer
void run ()
 Start the batch processing.
std::ostream & ostream ()
 Give back the stream of the writer.

(Note that these are not member symbols.)

SectionWriter sectionWriter (std::ostream &os)
 Return a SectionWriter class.
SectionWriter sectionWriter (const std::string &fn)
 Return a SectionWriter class.
SectionWriter sectionWriter (const char *fn)
 Return a SectionWriter class.

Detailed Description

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.

Constructor & Destructor Documentation

◆ SectionWriter() [1/3]

SectionWriter ( std::ostream & os)
inline

Construct a section writer, which writes to the given output stream.

◆ SectionWriter() [2/3]

SectionWriter ( const std::string & fn)
inline

Construct a section writer, which writes into the given file.

◆ SectionWriter() [3/3]

SectionWriter ( const char * fn)
inline

Construct a section writer, which writes into the given file.

Member Function Documentation

◆ sectionLines()

template< typename Functor >
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 ) );

◆ sectionStream()

template< typename Functor >
SectionWriter & sectionStream ( const std::string & type,
Functor functor )
inline

The first parameter is the type of the section, the second is a functor, which takes a std::ostream& parameter. The functor writes the section to the output stream.

Warning
The last line must be closed with end-line character.

◆ run()

void run ( )
inline

This function starts the batch processing.

◆ ostream()

std::ostream & ostream ( )
inline

Returns the stream of the writer

◆ sectionWriter() [1/2]

SectionWriter sectionWriter ( const std::string & fn)
related

This function just returns a SectionWriter class.

See also
sectionWriter( std::ostream & os )

◆ sectionWriter() [2/2]

SectionWriter sectionWriter ( const char * fn)
related

This function just returns a SectionWriter class.

See also
sectionWriter( std::ostream & os )