generator.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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(BOOST_SPIRIT_GENERATOR_JANUARY_13_2009_1002AM)
  7. #define BOOST_SPIRIT_GENERATOR_JANUARY_13_2009_1002AM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/mpl/has_xxx.hpp>
  12. #include <boost/mpl/int.hpp>
  13. #include <boost/spirit/home/karma/domain.hpp>
  14. namespace boost { namespace spirit { namespace karma
  15. {
  16. struct generator_properties
  17. {
  18. enum enum_type {
  19. no_properties = 0,
  20. buffering = 0x01, // generator requires buffering
  21. counting = 0x02, // generator requires counting
  22. tracking = 0x04, // generator requires position tracking
  23. disabling = 0x08, // generator requires disabling of output
  24. countingbuffer = 0x03, // buffering | counting
  25. all_properties = 0x0f // buffering | counting | tracking | disabling
  26. };
  27. };
  28. template <typename Derived>
  29. struct generator
  30. {
  31. struct generator_id;
  32. typedef mpl::int_<generator_properties::no_properties> properties;
  33. typedef Derived derived_type;
  34. typedef karma::domain domain;
  35. // Requirement: g.generate(o, context, delimiter, attr) -> bool
  36. //
  37. // g: a generator
  38. // o: output iterator
  39. // context: enclosing rule context (can be unused_type)
  40. // delimit: delimiter (can be unused_type)
  41. // attr: attribute (can be unused_type)
  42. // Requirement: g.what(context) -> info
  43. //
  44. // g: a generator
  45. // context: enclosing rule context (can be unused_type)
  46. // Requirement: G::template attribute<Ctx, Iter>::type
  47. //
  48. // G: a generator type
  49. // Ctx: A context type (can be unused_type)
  50. // Iter: An iterator type (always unused_type)
  51. Derived const& derived() const
  52. {
  53. return *static_cast<Derived const*>(this);
  54. }
  55. };
  56. template <typename Derived>
  57. struct primitive_generator : generator<Derived>
  58. {
  59. struct primitive_generator_id;
  60. };
  61. template <typename Derived>
  62. struct nary_generator : generator<Derived>
  63. {
  64. struct nary_generator_id;
  65. // Requirement: g.elements -> fusion sequence
  66. //
  67. // g: a composite generator
  68. // Requirement: G::elements_type -> fusion sequence
  69. //
  70. // G: a composite generator type
  71. };
  72. template <typename Derived>
  73. struct unary_generator : generator<Derived>
  74. {
  75. struct unary_generator_id;
  76. // Requirement: g.subject -> subject generator
  77. //
  78. // g: a unary generator
  79. // Requirement: G::subject_type -> subject generator type
  80. //
  81. // G: a unary generator type
  82. };
  83. template <typename Derived>
  84. struct binary_generator : generator<Derived>
  85. {
  86. struct binary_generator_id;
  87. // Requirement: g.left -> left generator
  88. //
  89. // g: a binary generator
  90. // Requirement: G::left_type -> left generator type
  91. //
  92. // G: a binary generator type
  93. // Requirement: g.right -> right generator
  94. //
  95. // g: a binary generator
  96. // Requirement: G::right_type -> right generator type
  97. //
  98. // G: a binary generator type
  99. };
  100. }}}
  101. namespace boost { namespace spirit { namespace traits // classification
  102. {
  103. namespace detail
  104. {
  105. // generator tags
  106. BOOST_MPL_HAS_XXX_TRAIT_DEF(generator_id)
  107. BOOST_MPL_HAS_XXX_TRAIT_DEF(primitive_generator_id)
  108. BOOST_MPL_HAS_XXX_TRAIT_DEF(nary_generator_id)
  109. BOOST_MPL_HAS_XXX_TRAIT_DEF(unary_generator_id)
  110. BOOST_MPL_HAS_XXX_TRAIT_DEF(binary_generator_id)
  111. }
  112. // check for generator tags
  113. template <typename T>
  114. struct is_generator : detail::has_generator_id<T> {};
  115. template <typename T>
  116. struct is_primitive_generator : detail::has_primitive_generator_id<T> {};
  117. template <typename T>
  118. struct is_nary_generator : detail::has_nary_generator_id<T> {};
  119. template <typename T>
  120. struct is_unary_generator : detail::has_unary_generator_id<T> {};
  121. template <typename T>
  122. struct is_binary_generator : detail::has_binary_generator_id<T> {};
  123. // check for generator properties
  124. template <typename T>
  125. struct properties_of : T::properties {};
  126. }}}
  127. #endif