quant_style.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // quant_style.hpp
  3. //
  4. // Copyright 2008 Eric Niebler. Distributed under the Boost
  5. // Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_XPRESSIVE_DETAIL_CORE_QUANT_STYLE_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_QUANT_STYLE_HPP_EAN_10_04_2005
  9. // MS compatible compilers support #pragma once
  10. #if defined(_MSC_VER)
  11. # pragma once
  12. #endif
  13. #include <boost/config.hpp>
  14. #include <boost/mpl/has_xxx.hpp>
  15. #include <boost/xpressive/detail/utility/width.hpp>
  16. #include <boost/xpressive/detail/detail_fwd.hpp>
  17. namespace boost { namespace xpressive { namespace detail
  18. {
  19. BOOST_MPL_HAS_XXX_TRAIT_DEF(is_boost_xpressive_xpression_)
  20. ///////////////////////////////////////////////////////////////////////////////
  21. // is_xpr
  22. //
  23. template<typename Xpr>
  24. struct is_xpr
  25. : has_is_boost_xpressive_xpression_<Xpr>
  26. {};
  27. ///////////////////////////////////////////////////////////////////////////////
  28. // quant_enum
  29. //
  30. enum quant_enum
  31. {
  32. quant_none,
  33. quant_fixed_width,
  34. quant_variable_width
  35. };
  36. ///////////////////////////////////////////////////////////////////////////////
  37. // quant_style
  38. //
  39. template<quant_enum QuantStyle, std::size_t Width = unknown_width::value, bool Pure = true>
  40. struct quant_style
  41. {
  42. typedef void is_boost_xpressive_xpression_;
  43. // Which quantification strategy to use?
  44. BOOST_STATIC_CONSTANT(int, quant = QuantStyle);
  45. // how many characters this matcher consumes
  46. BOOST_STATIC_CONSTANT(std::size_t, width = Width);
  47. // whether this matcher has observable side-effects
  48. BOOST_STATIC_CONSTANT(bool, pure = Pure);
  49. static detail::width get_width()
  50. {
  51. return width;
  52. }
  53. };
  54. #define BOOST_XPR_QUANT_STYLE(Style, Width, Pure) \
  55. typedef void is_boost_xpressive_xpression_; \
  56. BOOST_STATIC_CONSTANT(int, quant = Style); \
  57. BOOST_STATIC_CONSTANT(std::size_t, width = Width); \
  58. BOOST_STATIC_CONSTANT(bool, pure = Pure); \
  59. static detail::width get_width() { return width; } \
  60. /**/
  61. // // Replace transmogrify stupidity with rebindable matchers/placeholders
  62. //#define BOOST_XPR_IDENTITY_REBIND(TYPE) \/
  63. // template<typename BidiIter, typename ICase, typename Traits> \/
  64. // struct rebind \/
  65. // { \/
  66. // typedef TYPE type; \/
  67. // }; \/
  68. // /**/
  69. ///////////////////////////////////////////////////////////////////////////////
  70. // quant_style_none
  71. // this sub-expression cannot be quantified
  72. typedef quant_style<quant_none> quant_style_none;
  73. ///////////////////////////////////////////////////////////////////////////////
  74. // quant_style_fixed_unknown_width
  75. // this sub-expression is fixed width for the purpose of quantification, but
  76. // the width cannot be determined at compile time. An example would be the
  77. // string_matcher or the mark_matcher.
  78. typedef quant_style<quant_fixed_width> quant_style_fixed_unknown_width;
  79. ///////////////////////////////////////////////////////////////////////////////
  80. // quant_style_variable_width
  81. // this sub-expression can match a variable number of characters
  82. typedef quant_style<quant_variable_width> quant_style_variable_width;
  83. ///////////////////////////////////////////////////////////////////////////////
  84. // quant_style_fixed_width
  85. // for when the sub-expression has a fixed width that is known at compile time
  86. template<std::size_t Width>
  87. struct quant_style_fixed_width
  88. : quant_style<quant_fixed_width, Width>
  89. {
  90. };
  91. ///////////////////////////////////////////////////////////////////////////////
  92. // quant_style_assertion
  93. // a zero-width assertion.
  94. struct quant_style_assertion
  95. : quant_style<quant_none, 0>
  96. {
  97. };
  98. ///////////////////////////////////////////////////////////////////////////////
  99. // quant_type
  100. //
  101. template<typename Matcher>
  102. struct quant_type
  103. : mpl::int_<Matcher::quant>
  104. {
  105. };
  106. }}} // namespace boost::xpressive::detail
  107. #endif