and_predicate.hpp 3.3 KB

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