/Src/Dependencies/Boost/boost/spirit/home/classic/meta/impl/parser_traits.ipp

http://hadesmem.googlecode.com/ · C++ Header · 191 lines · 125 code · 39 blank · 27 comment · 9 complexity · 7971c054f0b113e94bc3d4e47642d754 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2002-2003 Joel de Guzman
  3. Copyright (c) 2002-2003 Hartmut Kaiser
  4. Copyright (c) 2003 Martin Wille
  5. http://spirit.sourceforge.net/
  6. Use, modification and distribution is subject to the Boost Software
  7. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. http://www.boost.org/LICENSE_1_0.txt)
  9. =============================================================================*/
  10. #if !defined(BOOST_SPIRIT_PARSER_TRAITS_IPP)
  11. #define BOOST_SPIRIT_PARSER_TRAITS_IPP
  12. #include <boost/spirit/home/classic/core/composite/operators.hpp>
  13. ///////////////////////////////////////////////////////////////////////////////
  14. namespace boost { namespace spirit {
  15. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  16. namespace impl
  17. {
  18. #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  19. ///////////////////////////////////////////////////////////////////////////
  20. //
  21. // from spirit 1.1 (copyright (c) 2001 Bruce Florman)
  22. // various workarounds to support compile time decisions without partial
  23. // template specialization whether a given type is an instance of a
  24. // concrete parser type.
  25. //
  26. ///////////////////////////////////////////////////////////////////////////
  27. ///////////////////////////////////////////////////////////////////////////
  28. template <typename T>
  29. struct parser_type_traits
  30. {
  31. // Determine at compile time (without partial specialization)
  32. // whether a given type is an instance of the alternative<A,B>
  33. static T t();
  34. typedef struct { char dummy[1]; } size1_t;
  35. typedef struct { char dummy[2]; } size2_t;
  36. typedef struct { char dummy[3]; } size3_t;
  37. typedef struct { char dummy[4]; } size4_t;
  38. typedef struct { char dummy[5]; } size5_t;
  39. typedef struct { char dummy[6]; } size6_t;
  40. typedef struct { char dummy[7]; } size7_t;
  41. typedef struct { char dummy[8]; } size8_t;
  42. typedef struct { char dummy[9]; } size9_t;
  43. typedef struct { char dummy[10]; } size10_t;
  44. // the following functions need no implementation
  45. template <typename A, typename B>
  46. static size1_t test_(alternative<A, B> const&);
  47. template <typename A, typename B>
  48. static size2_t test_(sequence<A, B> const&);
  49. template <typename A, typename B>
  50. static size3_t test_(sequential_or<A, B> const&);
  51. template <typename A, typename B>
  52. static size4_t test_(intersection<A, B> const&);
  53. template <typename A, typename B>
  54. static size5_t test_(difference<A, B> const&);
  55. template <typename A, typename B>
  56. static size6_t test_(exclusive_or<A, B> const&);
  57. template <typename S>
  58. static size7_t test_(optional<S> const&);
  59. template <typename S>
  60. static size8_t test_(kleene_star<S> const&);
  61. template <typename S>
  62. static size9_t test_(positive<S> const&);
  63. static size10_t test_(...);
  64. BOOST_STATIC_CONSTANT(bool,
  65. is_alternative = (sizeof(size1_t) == sizeof(test_(t()))) );
  66. BOOST_STATIC_CONSTANT(bool,
  67. is_sequence = (sizeof(size2_t) == sizeof(test_(t()))) );
  68. BOOST_STATIC_CONSTANT(bool,
  69. is_sequential_or = (sizeof(size3_t) == sizeof(test_(t()))) );
  70. BOOST_STATIC_CONSTANT(bool,
  71. is_intersection = (sizeof(size4_t) == sizeof(test_(t()))) );
  72. BOOST_STATIC_CONSTANT(bool,
  73. is_difference = (sizeof(size5_t) == sizeof(test_(t()))) );
  74. BOOST_STATIC_CONSTANT(bool,
  75. is_exclusive_or = (sizeof(size6_t) == sizeof(test_(t()))) );
  76. BOOST_STATIC_CONSTANT(bool,
  77. is_optional = (sizeof(size7_t) == sizeof(test_(t()))) );
  78. BOOST_STATIC_CONSTANT(bool,
  79. is_kleene_star = (sizeof(size8_t) == sizeof(test_(t()))) );
  80. BOOST_STATIC_CONSTANT(bool,
  81. is_positive = (sizeof(size9_t) == sizeof(test_(t()))) );
  82. };
  83. #else
  84. ///////////////////////////////////////////////////////////////////////////
  85. struct parser_type_traits_base {
  86. BOOST_STATIC_CONSTANT(bool, is_alternative = false);
  87. BOOST_STATIC_CONSTANT(bool, is_sequence = false);
  88. BOOST_STATIC_CONSTANT(bool, is_sequential_or = false);
  89. BOOST_STATIC_CONSTANT(bool, is_intersection = false);
  90. BOOST_STATIC_CONSTANT(bool, is_difference = false);
  91. BOOST_STATIC_CONSTANT(bool, is_exclusive_or = false);
  92. BOOST_STATIC_CONSTANT(bool, is_optional = false);
  93. BOOST_STATIC_CONSTANT(bool, is_kleene_star = false);
  94. BOOST_STATIC_CONSTANT(bool, is_positive = false);
  95. };
  96. template <typename ParserT>
  97. struct parser_type_traits : public parser_type_traits_base {
  98. // no definition here, fallback for all not explicitly mentioned parser
  99. // types
  100. };
  101. template <typename A, typename B>
  102. struct parser_type_traits<alternative<A, B> >
  103. : public parser_type_traits_base {
  104. BOOST_STATIC_CONSTANT(bool, is_alternative = true);
  105. };
  106. template <typename A, typename B>
  107. struct parser_type_traits<sequence<A, B> >
  108. : public parser_type_traits_base {
  109. BOOST_STATIC_CONSTANT(bool, is_sequence = true);
  110. };
  111. template <typename A, typename B>
  112. struct parser_type_traits<sequential_or<A, B> >
  113. : public parser_type_traits_base {
  114. BOOST_STATIC_CONSTANT(bool, is_sequential_or = true);
  115. };
  116. template <typename A, typename B>
  117. struct parser_type_traits<intersection<A, B> >
  118. : public parser_type_traits_base {
  119. BOOST_STATIC_CONSTANT(bool, is_intersection = true);
  120. };
  121. template <typename A, typename B>
  122. struct parser_type_traits<difference<A, B> >
  123. : public parser_type_traits_base {
  124. BOOST_STATIC_CONSTANT(bool, is_difference = true);
  125. };
  126. template <typename A, typename B>
  127. struct parser_type_traits<exclusive_or<A, B> >
  128. : public parser_type_traits_base {
  129. BOOST_STATIC_CONSTANT(bool, is_exclusive_or = true);
  130. };
  131. template <typename S>
  132. struct parser_type_traits<optional<S> >
  133. : public parser_type_traits_base {
  134. BOOST_STATIC_CONSTANT(bool, is_optional = true);
  135. };
  136. template <typename S>
  137. struct parser_type_traits<kleene_star<S> >
  138. : public parser_type_traits_base {
  139. BOOST_STATIC_CONSTANT(bool, is_kleene_star = true);
  140. };
  141. template <typename S>
  142. struct parser_type_traits<positive<S> >
  143. : public parser_type_traits_base {
  144. BOOST_STATIC_CONSTANT(bool, is_positive = true);
  145. };
  146. #endif // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  147. } // namespace impl
  148. ///////////////////////////////////////////////////////////////////////////////
  149. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  150. }} // namespace boost::spirit
  151. #endif // !defined(BOOST_SPIRIT_PARSER_TRAITS_IPP)