6 #ifndef PRE_SPIRIT_KARMA_CRC_OF_HPP 7 #define PRE_SPIRIT_KARMA_CRC_OF_HPP 13 #include <boost/spirit/home/karma/meta_compiler.hpp> 14 #include <boost/spirit/home/karma/generator.hpp> 15 #include <boost/spirit/home/karma/domain.hpp> 16 #include <boost/spirit/home/karma/detail/output_iterator.hpp> 17 #include <boost/spirit/home/support/unused.hpp> 18 #include <boost/spirit/home/support/info.hpp> 19 #include <boost/spirit/home/support/common_terminals.hpp> 20 #include <boost/spirit/home/support/has_semantic_action.hpp> 21 #include <boost/spirit/home/support/handles_container.hpp> 22 #include <boost/spirit/home/karma/detail/attributes.hpp> 25 #include <boost/crc.hpp> 29 namespace pre {
namespace spirit {
namespace karma {
30 BOOST_SPIRIT_TERMINAL_EX(crc_of);
33 namespace boost {
namespace spirit {
39 struct use_directive<karma::domain
40 , terminal_ex<pre::spirit::karma::tag::crc_of
41 , fusion::vector1<T> >
46 namespace pre {
namespace spirit {
namespace karma {
47 namespace mpl = boost::mpl;
49 using boost::spirit::buffer_type;
55 template <
typename Subject>
56 struct crc_of_directive : boost::spirit::karma::unary_generator<crc_of_directive<Subject> >
58 typedef Subject subject_type;
60 subject_type::properties::value |
61 boost::spirit::karma::generator_properties::countingbuffer
65 : subject(subject), crc(crc) {}
67 template <
typename Context,
typename Iterator>
69 : boost::spirit::traits::attribute_of<subject_type, Context, Iterator>
72 template <
typename OutputIterator,
typename Context,
typename Delimiter
74 bool generate(OutputIterator& sink, Context& ctx, Delimiter
const& d
75 , Attribute
const& attr)
const 78 boost::spirit::karma::detail::enable_buffering<OutputIterator> buffering(sink);
79 boost::spirit::karma::detail::enable_counting<OutputIterator> counting(sink);
80 bool r = subject.generate(sink, ctx, d, attr);
82 std::string buffered_data;
83 std::back_insert_iterator<std::string> crc_sink(buffered_data);
84 buffering.buffer_copy_to(crc_sink);
86 boost::crc_ccitt_type crc_ccitt;
88 crc_ccitt.process_bytes(buffered_data.data(), buffered_data.size());
89 crc = crc_ccitt.checksum();
91 buffering.buffer_copy();
95 template <
typename Context>
96 boost::spirit::info what(Context& context)
const 98 return info(
"crc_of", subject.what(context));
107 namespace boost {
namespace spirit {
namespace karma {
112 template <
typename T,
typename Subject,
typename Modifiers>
113 struct make_directive<
114 terminal_ex<
pre::spirit::karma::tag::crc_of, fusion::vector1<T> >,
119 template <
typename Terminal>
120 result_type operator()(Terminal & term, Subject
const& subject
123 return result_type(subject, fusion::at_c<0>(term.args));
129 namespace boost {
namespace spirit {
namespace traits
132 template <
typename Subject>
133 struct has_semantic_action<
pre::spirit::karma::crc_of_directive<Subject> >
134 : unary_has_semantic_action<Subject> {};
137 template <
typename Subject,
typename Attribute,
typename Context
139 struct handles_container<pre::spirit::karma::crc_of_directive<Subject>, Attribute
141 : unary_handles_container<Subject, Attribute, Context, Iterator> {};
Definition: crc_of.hpp:56
Definition: crc_of.hpp:68