1 // Copyright (c) 2001-2011 Hartmut Kaiser 2 // Copyright (c) 2001-2011 Joel de Guzman 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 #ifndef BOOST_SPIRIT_KARMA_OPERATOR_AND_PREDICATE_HPP 8 #define BOOST_SPIRIT_KARMA_OPERATOR_AND_PREDICATE_HPP 9 10 #if defined(_MSC_VER) 11 #pragma once 12 #endif 13 14 #include <boost/spirit/home/karma/domain.hpp> 15 #include <boost/spirit/home/karma/meta_compiler.hpp> 16 #include <boost/spirit/home/karma/generator.hpp> 17 #include <boost/spirit/home/karma/detail/output_iterator.hpp> 18 #include <boost/spirit/home/karma/detail/attributes.hpp> 19 #include <boost/spirit/home/support/info.hpp> 20 #include <boost/spirit/home/support/has_semantic_action.hpp> 21 #include <boost/spirit/home/support/handles_container.hpp> 22 #include <boost/proto/operators.hpp> 23 #include <boost/proto/tags.hpp> 24 25 namespace boost { namespace spirit 26 { 27 /////////////////////////////////////////////////////////////////////////// 28 // Enablers 29 /////////////////////////////////////////////////////////////////////////// 30 template <> 31 struct use_operator<karma::domain, proto::tag::address_of> // enables &g 32 : mpl::true_ {}; 33 }} 34 35 namespace boost { namespace spirit { namespace karma 36 { 37 template <typename Subject> 38 struct and_predicate : unary_generator<and_predicate<Subject> > 39 { 40 typedef Subject subject_type; 41 typedef mpl::int_< 42 generator_properties::disabling | subject_type::properties::value 43 > properties; 44 45 template <typename Context, typename Iterator> 46 struct attribute 47 : traits::attribute_of<subject_type, Context, Iterator> 48 {}; 49 and_predicateboost::spirit::karma::and_predicate50 and_predicate(Subject const& subject) 51 : subject(subject) {} 52 53 template < 54 typename OutputIterator, typename Context, typename Delimiter 55 , typename Attribute> generateboost::spirit::karma::and_predicate56 bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d 57 , Attribute const& attr) const 58 { 59 // inhibits output 60 detail::disable_output<OutputIterator> disable(sink); 61 return subject.generate(sink, ctx, d, attr); 62 } 63 64 template <typename Context> whatboost::spirit::karma::and_predicate65 info what(Context& context) const 66 { 67 return info("and-predicate", subject.what(context)); 68 } 69 70 Subject subject; 71 }; 72 73 /////////////////////////////////////////////////////////////////////////// 74 // Generator generators: make_xxx function (objects) 75 /////////////////////////////////////////////////////////////////////////// 76 template <typename Elements, typename Modifiers> 77 struct make_composite<proto::tag::address_of, Elements, Modifiers> 78 : make_unary_composite<Elements, and_predicate> {}; 79 80 }}} 81 82 namespace boost { namespace spirit { namespace traits 83 { 84 /////////////////////////////////////////////////////////////////////////// 85 template <typename Subject> 86 struct has_semantic_action<karma::and_predicate<Subject> > 87 : unary_has_semantic_action<Subject> {}; 88 89 /////////////////////////////////////////////////////////////////////////// 90 template <typename Subject, typename Attribute, typename Context 91 , typename Iterator> 92 struct handles_container<karma::and_predicate<Subject>, Attribute 93 , Context, Iterator> 94 : unary_handles_container<Subject, Attribute, Context, Iterator> {}; 95 }}} 96 97 #endif 98