File indexing completed on 2025-01-19 09:47:37
0001
0002
0003
0004
0005
0006
0007 #if !defined(BOOST_SPIRIT_KARMA_DEBUG_HANDLER_APR_21_2010_0148PM)
0008 #define BOOST_SPIRIT_KARMA_DEBUG_HANDLER_APR_21_2010_0148PM
0009
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013
0014 #include <boost/spirit/home/support/unused.hpp>
0015 #include <boost/spirit/home/karma/nonterminal/rule.hpp>
0016 #include <boost/spirit/home/karma/nonterminal/debug_handler_state.hpp>
0017 #include <boost/function.hpp>
0018
0019 namespace boost { namespace spirit { namespace karma
0020 {
0021 template <
0022 typename OutputIterator, typename Context, typename Delimiter
0023 , typename Properties, typename F>
0024 struct debug_handler
0025 {
0026 typedef detail::output_iterator<OutputIterator, Properties>
0027 output_iterator;
0028 typedef detail::enable_buffering<output_iterator> buffer_type;
0029
0030 typedef function<bool(output_iterator&, Context&, Delimiter const&)>
0031 function_type;
0032
0033 debug_handler(function_type subject, F f, std::string const& rule_name)
0034 : subject(subject)
0035 , f(f)
0036 , rule_name(rule_name)
0037 {}
0038
0039 bool operator()(output_iterator& sink, Context& context
0040 , Delimiter const& delim) const
0041 {
0042 buffer_type buffer(sink);
0043 bool r = false;
0044
0045 f (sink, context, pre_generate, rule_name, buffer);
0046 {
0047 detail::disable_counting<output_iterator> nocount(sink);
0048 r = subject(sink, context, delim);
0049 }
0050
0051 if (r)
0052 {
0053 f (sink, context, successful_generate, rule_name, buffer);
0054 buffer.buffer_copy();
0055 return true;
0056 }
0057 f (sink, context, failed_generate, rule_name, buffer);
0058 return false;
0059 }
0060
0061 function_type subject;
0062 F f;
0063 std::string rule_name;
0064 };
0065
0066 template <typename OutputIterator
0067 , typename T1, typename T2, typename T3, typename T4, typename F>
0068 void debug(rule<OutputIterator, T1, T2, T3, T4>& r, F f)
0069 {
0070 typedef rule<OutputIterator, T1, T2, T3, T4> rule_type;
0071
0072 typedef
0073 debug_handler<
0074 OutputIterator
0075 , typename rule_type::context_type
0076 , typename rule_type::delimiter_type
0077 , typename rule_type::properties
0078 , F>
0079 debug_handler;
0080 r.f = debug_handler(r.f, f, r.name());
0081 }
0082
0083 struct simple_trace;
0084
0085 namespace detail
0086 {
0087
0088
0089
0090
0091
0092 template<typename T>
0093 struct get_simple_trace
0094 {
0095 typedef simple_trace type;
0096 };
0097 }
0098
0099 template <typename OutputIterator
0100 , typename T1, typename T2, typename T3, typename T4>
0101 void debug(rule<OutputIterator, T1, T2, T3, T4>& r)
0102 {
0103 typedef rule<OutputIterator, T1, T2, T3, T4> rule_type;
0104
0105 typedef
0106 debug_handler<
0107 OutputIterator
0108 , typename rule_type::context_type
0109 , typename rule_type::delimiter_type
0110 , typename rule_type::properties
0111 , simple_trace>
0112 debug_handler;
0113 typedef typename karma::detail::get_simple_trace<OutputIterator>::type
0114 trace;
0115 r.f = debug_handler(r.f, trace(), r.name());
0116 }
0117
0118 }}}
0119
0120
0121
0122 #if !defined(BOOST_SPIRIT_DEBUG_NODE)
0123 #if defined(BOOST_SPIRIT_KARMA_DEBUG)
0124 #define BOOST_SPIRIT_DEBUG_NODE(r) r.name(#r); debug(r)
0125 #else
0126 #define BOOST_SPIRIT_DEBUG_NODE(r) r.name(#r);
0127 #endif
0128 #endif
0129
0130 #endif