File indexing completed on 2025-01-19 09:47:34
0001
0002
0003
0004
0005
0006 #if !defined(BOOST_SPIRIT_KARMA_PADDING_MAY_06_2008_0436PM)
0007 #define BOOST_SPIRIT_KARMA_PADDING_MAY_06_2008_0436PM
0008
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012
0013 #include <boost/spirit/home/support/common_terminals.hpp>
0014 #include <boost/spirit/home/support/info.hpp>
0015
0016 #include <boost/spirit/home/karma/domain.hpp>
0017 #include <boost/spirit/home/karma/meta_compiler.hpp>
0018 #include <boost/spirit/home/karma/delimit_out.hpp>
0019 #include <boost/spirit/home/karma/auxiliary/lazy.hpp>
0020 #include <boost/spirit/home/karma/detail/generate_to.hpp>
0021 #include <boost/spirit/home/support/unused.hpp>
0022 #include <boost/fusion/include/at.hpp>
0023 #include <boost/fusion/include/vector.hpp>
0024
0025
0026 namespace boost { namespace spirit
0027 {
0028
0029
0030
0031
0032
0033 template <typename A0>
0034 struct use_terminal<karma::domain
0035 , terminal_ex<tag::pad, fusion::vector1<A0> > >
0036 : mpl::true_ {};
0037
0038
0039 template <>
0040 struct use_lazy_terminal<karma::domain, tag::pad, 1>
0041 : mpl::true_ {};
0042
0043 }}
0044
0045
0046 namespace boost { namespace spirit { namespace karma
0047 {
0048 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0049 using boost::spirit::pad;
0050 #endif
0051 using boost::spirit::pad_type;
0052
0053 struct binary_padding_generator
0054 : primitive_generator<binary_padding_generator>
0055 {
0056 typedef mpl::int_<generator_properties::tracking> properties;
0057
0058 template <typename Context, typename Unused>
0059 struct attribute
0060 {
0061 typedef unused_type type;
0062 };
0063
0064 binary_padding_generator(int numpadbytes)
0065 : numpadbytes_(numpadbytes)
0066 {}
0067
0068 template <
0069 typename OutputIterator, typename Context, typename Delimiter
0070 , typename Attribute>
0071 bool generate(OutputIterator& sink, Context&, Delimiter const& d
0072 , Attribute const& ) const
0073 {
0074 std::size_t count = sink.get_out_count() % numpadbytes_;
0075 if (count)
0076 count = numpadbytes_ - count;
0077
0078 bool result = true;
0079 while (result && count-- != 0)
0080 result = detail::generate_to(sink, '\0');
0081
0082 if (result)
0083 result = karma::delimit_out(sink, d);
0084 return result;
0085 }
0086
0087 template <typename Context>
0088 static info what(Context const&)
0089 {
0090 return info("pad");
0091 }
0092
0093 int numpadbytes_;
0094 };
0095
0096
0097
0098
0099 template <typename Modifiers, typename A0>
0100 struct make_primitive<
0101 terminal_ex<tag::pad, fusion::vector1<A0> >
0102 , Modifiers>
0103 {
0104 typedef binary_padding_generator result_type;
0105
0106 template <typename Terminal>
0107 result_type operator()(Terminal const& term, unused_type) const
0108 {
0109 return result_type(fusion::at_c<0>(term.args));
0110 }
0111 };
0112
0113 }}}
0114
0115 #endif