strict_relaxed.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #if !defined(SPIRIT_STRICT_RELAXED_APR_22_2010_0959AM)
  6. #define SPIRIT_STRICT_RELAXED_APR_22_2010_0959AM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/home/support/common_terminals.hpp>
  11. #include <boost/spirit/home/support/modify.hpp>
  12. #include <boost/spirit/home/karma/domain.hpp>
  13. #include <boost/spirit/home/karma/meta_compiler.hpp>
  14. namespace boost { namespace spirit
  15. {
  16. ///////////////////////////////////////////////////////////////////////////
  17. // Enablers
  18. ///////////////////////////////////////////////////////////////////////////
  19. template <>
  20. struct use_directive<karma::domain, tag::strict> // enables strict[]
  21. : mpl::true_ {};
  22. template <>
  23. struct use_directive<karma::domain, tag::relaxed> // enables relaxed[]
  24. : mpl::true_ {};
  25. ///////////////////////////////////////////////////////////////////////////
  26. template <>
  27. struct is_modifier_directive<karma::domain, tag::strict>
  28. : mpl::true_ {};
  29. template <>
  30. struct is_modifier_directive<karma::domain, tag::relaxed>
  31. : mpl::true_ {};
  32. ///////////////////////////////////////////////////////////////////////////
  33. // Don't add tag::strict or tag::relaxed if there is already one of those
  34. // in the modifier list
  35. template <typename Current>
  36. struct compound_modifier<Current, tag::strict
  37. , typename enable_if<has_modifier<Current, tag::relaxed> >::type>
  38. : Current
  39. {
  40. compound_modifier()
  41. : Current() {}
  42. compound_modifier(Current const& current, tag::strict const&)
  43. : Current(current) {}
  44. };
  45. template <typename Current>
  46. struct compound_modifier<Current, tag::relaxed
  47. , typename enable_if<has_modifier<Current, tag::strict> >::type>
  48. : Current
  49. {
  50. compound_modifier()
  51. : Current() {}
  52. compound_modifier(Current const& current, tag::relaxed const&)
  53. : Current(current) {}
  54. };
  55. namespace karma
  56. {
  57. #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  58. using boost::spirit::strict;
  59. using boost::spirit::relaxed;
  60. #endif
  61. using boost::spirit::strict_type;
  62. using boost::spirit::relaxed_type;
  63. }
  64. }}
  65. #endif