SectionWriter

Declared in lemon/lgf_writer.h, in the group LEMON Graph Format; the same class on the Doxygen site.

class SectionWriter

Section writer class.

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.

Section Writers

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

Add a section writer with line oriented writing.

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 ) );

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

Add a section writer with stream oriented writing.

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.

Execution of the Writer

inline void run()

Start the batch processing.

This function starts the batch processing.

inline std::ostream & ostream()

Give back the stream of the writer.

Returns the stream of the writer

Public Functions

inline SectionWriter( std::ostream & os )

Constructor.

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

inline SectionWriter( const std::string & fn )

Constructor.

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

inline SectionWriter( const char * fn )

Constructor.

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

inline ~SectionWriter()

Destructor.

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

Return a SectionWriter class.

This function just returns a SectionWriter class.

See also

sectionWriter( std::ostream & os )

inline SectionWriter sectionWriter( const char * fn )

Return a SectionWriter class.

This function just returns a SectionWriter class.

See also

sectionWriter( std::ostream & os )