...one of the most highly
regarded and expertly designed C++ library projects in the
world. — Herb Sutter and Andrei
All generator components (except the Alternative
|) generator) pass
their generated output directly to the underlying output stream. If a
generator fails halfway through, the output generated so far is not 'rolled
back'. The buffering generator directive allows to avoid this unwanted
output to be generated. It temporarily redirects the output produced
by the embedded generator into a buffer. This buffer is flushed to the
underlying stream only after the embedded generator succeeded, but is
// forwards to <boost/spirit/home/karma/directive/buffer.hpp> #include <boost/spirit/include/karma_buffer.hpp>
Also, see Include Structure.
A generator object
Attribute type of generator
Semantics of an expression is defined only where it differs from, or
is not defined in
The embedded generator
If you want to make the buffered generator succeed regardless of the
outcome of the embedded generator, simply wrap the
See Compound Attribute Notation.
a: A --> buffer[a]: A a: Unused --> buffer[a]: Unused
The overall complexity of the buffering generator directive is defined by the complexity of its embedded generator. The complexity of the buffering directive generator itself is O(N), where N is the number of characters buffered.
The test harness for the example(s) below is presented in the Basics Examples section.
#include <boost/spirit/include/karma.hpp> #include <boost/spirit/include/support_utree.hpp> #include <boost/phoenix/core.hpp> #include <boost/phoenix/operator.hpp> #include <boost/fusion/include/std_pair.hpp> #include <boost/proto/deep_copy.hpp> #include <iostream> #include <string>
Some using declarations:
using boost::spirit::karma::double_; using boost::spirit::karma::buffer;
Basic usage of a buffering generator directive. It shows how the partial
output generated in the first example does not show up in the generated
output as the plus generator fails (no data is available, see Plus
std::vector<double> v; // empty container test_generator_attr("", -buffer['[' << +double_ << ']'], v); v.push_back(1.0); // now, fill the container v.push_back(2.0); test_generator_attr("[1.02.0]", buffer['[' << +double_ << ']'], v);