and_predicate.hpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifndef BOOST_SPIRIT_KARMA_OPERATOR_AND_PREDICATE_HPP
  7. #define BOOST_SPIRIT_KARMA_OPERATOR_AND_PREDICATE_HPP
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/karma/domain.hpp>
  12. #include <boost/spirit/home/karma/meta_compiler.hpp>
  13. #include <boost/spirit/home/karma/generator.hpp>
  14. #include <boost/spirit/home/karma/detail/output_iterator.hpp>
  15. #include <boost/spirit/home/karma/detail/attributes.hpp>
  16. #include <boost/spirit/home/support/info.hpp>
  17. #include <boost/spirit/home/support/has_semantic_action.hpp>
  18. #include <boost/spirit/home/support/handles_container.hpp>
  19. #include <boost/proto/operators.hpp>
  20. #include <boost/proto/tags.hpp>
  21. namespace boost { namespace spirit
  22. {
  23. ///////////////////////////////////////////////////////////////////////////
  24. // Enablers
  25. ///////////////////////////////////////////////////////////////////////////
  26. template <>
  27. struct use_operator<karma::domain, proto::tag::address_of> // enables &g
  28. : mpl::true_ {};
  29. }}
  30. namespace boost { namespace spirit { namespace karma
  31. {
  32. template <typename Subject>
  33. struct and_predicate : unary_generator<and_predicate<Subject> >
  34. {
  35. typedef Subject subject_type;
  36. typedef mpl::int_<
  37. generator_properties::disabling | subject_type::properties::value
  38. > properties;
  39. template <typename Context, typename Iterator>
  40. struct attribute
  41. : traits::attribute_of<subject_type, Context, Iterator>
  42. {};
  43. and_predicate(Subject const& subject)
  44. : subject(subject) {}
  45. template <
  46. typename OutputIterator, typename Context, typename Delimiter
  47. , typename Attribute>
  48. bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
  49. , Attribute const& attr) const
  50. {
  51. // inhibits output
  52. detail::disable_output<OutputIterator> disable(sink);
  53. return subject.generate(sink, ctx, d, attr);
  54. }
  55. template <typename Context>
  56. info what(Context& context) const
  57. {
  58. return info("and-predicate", subject.what(context));
  59. }
  60. Subject subject;
  61. };
  62. ///////////////////////////////////////////////////////////////////////////
  63. // Generator generators: make_xxx function (objects)
  64. ///////////////////////////////////////////////////////////////////////////
  65. template <typename Elements, typename Modifiers>
  66. struct make_composite<proto::tag::address_of, Elements, Modifiers>
  67. : make_unary_composite<Elements, and_predicate> {};
  68. }}}
  69. namespace boost { namespace spirit { namespace traits
  70. {
  71. ///////////////////////////////////////////////////////////////////////////
  72. template <typename Subject>
  73. struct has_semantic_action<karma::and_predicate<Subject> >
  74. : unary_has_semantic_action<Subject> {};
  75. ///////////////////////////////////////////////////////////////////////////
  76. template <typename Subject, typename Attribute, typename Context
  77. , typename Iterator>
  78. struct handles_container<karma::and_predicate<Subject>, Attribute
  79. , Context, Iterator>
  80. : unary_handles_container<Subject, Attribute, Context, Iterator> {};
  81. }}}
  82. #endif