not_predicate.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_NOT_PREDICATE_MAR_21_2009_1132AM)
  7. #define SPIRIT_KARMA_NOT_PREDICATE_MAR_21_2009_1132AM
  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::logical_not> // enables !g
  26. : mpl::true_ {};
  27. }}
  28. namespace boost { namespace spirit { namespace karma
  29. {
  30. template <typename Subject>
  31. struct not_predicate : unary_generator<not_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. not_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("not-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::logical_not, Elements, Modifiers>
  65. : make_unary_composite<Elements, not_predicate> {};
  66. }}}
  67. namespace boost { namespace spirit { namespace traits
  68. {
  69. ///////////////////////////////////////////////////////////////////////////
  70. template <typename Subject>
  71. struct has_semantic_action<karma::not_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::not_predicate<Subject>, Attribute
  77. , Context, Iterator>
  78. : unary_handles_container<Subject, Attribute, Context, Iterator> {};
  79. }}}
  80. #endif