All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
List of all members | Public Member Functions | Related Functions
SectionWriter Class Reference

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.

#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 >
SectionWritersectionLines (const std::string &type, Functor functor)
 Add a section writer with line oriented writing.
 
template<typename Functor >
SectionWritersectionStream (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.
 

Related Functions

(Note that these are not member functions.)

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.
 

Constructor & Destructor Documentation

SectionWriter ( std::ostream &  os)
inline

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

SectionWriter ( const std::string &  fn)
inline

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

SectionWriter ( const char *  fn)
inline

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

Member Function Documentation

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));
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.
void run ( )
inline

This function starts the batch processing.

std::ostream& ostream ( )
inline

Returns the stream of the writer

Friends And Related Function Documentation

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

This function just returns a SectionWriter class.

See Also
sectionWriter(std::ostream& os)
SectionWriter sectionWriter ( const char *  fn)
related

This function just returns a SectionWriter class.

See Also
sectionWriter(std::ostream& os)