inline static bool center_generate(OutputIterator& sink, Context& ctx, Delimiter const& d, Parameter const& param, Embedded const& e, unsigned int const width, Padding const& p) { // make sure all generator parameters are valid BOOST_MPL_ASSERT_MSG( (spirit::traits::is_component<karma::domain, Embedded>::value), embedded_is_not_convertible_to_a_generator, (Context, Embedded)); BOOST_MPL_ASSERT_MSG( (spirit::traits::is_component<karma::domain, Padding>::value), padding_is_not_convertible_to_a_generator, (Context, Padding)); typedef typename result_of::as_component<karma::domain, Embedded>::type embedded; typedef typename result_of::as_component<karma::domain, Padding>::type padding; // wrap the given output iterator to allow left padding detail::enable_buffering<OutputIterator> buffering(sink, width); // first generate the embedded output embedded ec = spirit::as_component(karma::domain(), e); typedef typename embedded::director director; bool r = director::generate(ec, sink, ctx, d, param); buffering.disable(); // do not perform buffering any more // generate the left padding detail::enable_counting<OutputIterator> counting(sink, (sink.buffer_size() + width) / 2); padding pc = spirit::as_component(karma::domain(), p); typedef typename padding::director padding_director; while (r && sink.count() < width) r = padding_director::generate(pc, sink, ctx, unused, unused); if (r) { // copy the embedded output to the target output iterator sink.buffer_copy(); // generate the right padding std::size_t const max_count = width + (width - sink.buffer_size()) / 2; while (r && sink.count() < max_count) r = padding_director::generate(pc, sink, ctx, unused, unused); } return r; }
inline static bool left_align_generate(OutputIterator& sink, Context& ctx, Delimiter const& d, Parameter const& param, Embedded const& e, unsigned int const width, Padding const& p) { // make sure all generator parameters are valid BOOST_MPL_ASSERT_MSG( (spirit::traits::is_component<karma::domain, Embedded>::value), embedded_is_not_convertible_to_a_generator, (Context, Embedded)); BOOST_MPL_ASSERT_MSG( (spirit::traits::is_component<karma::domain, Padding>::value), padding_is_not_convertible_to_a_generator, (Context, Padding)); typedef typename result_of::as_component<karma::domain, Embedded>::type embedded; typedef typename result_of::as_component<karma::domain, Padding>::type padding; // wrap the given output iterator to allow counting detail::enable_counting<OutputIterator> counting(sink); // first generate the underlying output embedded ec = spirit::as_component(karma::domain(), e); typedef typename embedded::director director; bool r = director::generate(ec, sink, ctx, d, param); // pad the output until the max width is reached padding pc = spirit::as_component(karma::domain(), p); while(r && sink.count() < width) { typedef typename padding::director padding_director; r = padding_director::generate(pc, sink, ctx, unused, unused); } return r; }