string.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #ifndef BOOST_METAPARSE_V1_CPP98_STRING_HPP
  2. #define BOOST_METAPARSE_V1_CPP98_STRING_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/metaparse/v1/cpp98/fwd/string.hpp>
  8. #include <boost/metaparse/v1/string_tag.hpp>
  9. #include <boost/metaparse/v1/impl/string_iterator.hpp>
  10. #include <boost/metaparse/v1/cpp98/impl/empty_string.hpp>
  11. #include <boost/metaparse/v1/cpp98/impl/size.hpp>
  12. #include <boost/metaparse/v1/cpp98/impl/pop_front.hpp>
  13. #include <boost/metaparse/v1/cpp98/impl/push_front_c.hpp>
  14. #include <boost/metaparse/v1/cpp98/impl/push_back_c.hpp>
  15. #include <boost/metaparse/v1/cpp98/impl/pop_back.hpp>
  16. #include <boost/preprocessor/arithmetic/sub.hpp>
  17. #include <boost/preprocessor/punctuation/comma_if.hpp>
  18. #include <boost/preprocessor/repetition/enum.hpp>
  19. #include <boost/preprocessor/repetition/enum_params.hpp>
  20. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  21. #include <boost/preprocessor/tuple/eat.hpp>
  22. #include <boost/type_traits/is_same.hpp>
  23. /*
  24. * The string type
  25. */
  26. namespace boost
  27. {
  28. namespace metaparse
  29. {
  30. namespace v1
  31. {
  32. template <BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C)>
  33. struct string
  34. {
  35. typedef string type;
  36. typedef string_tag tag;
  37. };
  38. }
  39. }
  40. }
  41. /*
  42. * Boost.MPL overloads
  43. */
  44. namespace boost
  45. {
  46. namespace mpl
  47. {
  48. // push_back
  49. template <class S>
  50. struct push_back_impl;
  51. template <>
  52. struct push_back_impl<boost::metaparse::v1::string_tag>
  53. {
  54. typedef push_back_impl type;
  55. template <class S, class C>
  56. struct apply :
  57. boost::metaparse::v1::impl::push_back_c<
  58. typename S::type,
  59. C::type::value
  60. >
  61. {};
  62. };
  63. // pop_back
  64. template <class S>
  65. struct pop_back_impl;
  66. template <>
  67. struct pop_back_impl<boost::metaparse::v1::string_tag>
  68. {
  69. typedef pop_back_impl type;
  70. template <class S>
  71. struct apply : boost::metaparse::v1::impl::pop_back<S> {};
  72. };
  73. // push_front
  74. template <class S>
  75. struct push_front_impl;
  76. template <>
  77. struct push_front_impl<boost::metaparse::v1::string_tag>
  78. {
  79. typedef push_front_impl type;
  80. template <class S, class C>
  81. struct apply :
  82. boost::metaparse::v1::impl::push_front_c<
  83. typename S::type,
  84. C::type::value
  85. >
  86. {};
  87. };
  88. // pop_front
  89. template <class S>
  90. struct pop_front_impl;
  91. template <>
  92. struct pop_front_impl<boost::metaparse::v1::string_tag>
  93. {
  94. typedef pop_front_impl type;
  95. template <class S>
  96. struct apply : boost::metaparse::v1::impl::pop_front<S> {};
  97. };
  98. // clear
  99. template <class S>
  100. struct clear_impl;
  101. template <>
  102. struct clear_impl<boost::metaparse::v1::string_tag>
  103. {
  104. typedef clear_impl type;
  105. template <class S>
  106. struct apply : boost::metaparse::v1::string<> {};
  107. };
  108. // begin
  109. template <class S>
  110. struct begin_impl;
  111. template <>
  112. struct begin_impl<boost::metaparse::v1::string_tag>
  113. {
  114. typedef begin_impl type;
  115. template <class S>
  116. struct apply :
  117. boost::metaparse::v1::impl::string_iterator<typename S::type, 0>
  118. {};
  119. };
  120. // end
  121. template <class S>
  122. struct end_impl;
  123. template <>
  124. struct end_impl<boost::metaparse::v1::string_tag>
  125. {
  126. typedef end_impl type;
  127. template <class S>
  128. struct apply :
  129. boost::metaparse::v1::impl::string_iterator<
  130. typename S::type,
  131. boost::metaparse::v1::impl::size<typename S::type>::type::value
  132. >
  133. {};
  134. };
  135. // equal_to
  136. template <class A, class B>
  137. struct equal_to_impl;
  138. template <>
  139. struct equal_to_impl<
  140. boost::metaparse::v1::string_tag,
  141. boost::metaparse::v1::string_tag
  142. >
  143. {
  144. typedef equal_to_impl type;
  145. template <class A, class B>
  146. struct apply : boost::is_same<typename A::type, typename B::type> {};
  147. };
  148. template <class T>
  149. struct equal_to_impl<boost::metaparse::v1::string_tag, T>
  150. {
  151. typedef equal_to_impl type;
  152. template <class, class>
  153. struct apply : false_ {};
  154. };
  155. template <class T>
  156. struct equal_to_impl<T, boost::metaparse::v1::string_tag> :
  157. equal_to_impl<boost::metaparse::v1::string_tag, T>
  158. {};
  159. // c_str
  160. template <class S>
  161. struct c_str;
  162. template <BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C)>
  163. struct c_str<
  164. boost::metaparse::v1::string<
  165. BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C)
  166. >
  167. >
  168. {
  169. typedef c_str type;
  170. static const char value[BOOST_METAPARSE_LIMIT_STRING_SIZE + 1];
  171. };
  172. template <BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C)>
  173. const char
  174. c_str<
  175. boost::metaparse::v1::string<
  176. BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C)
  177. >
  178. >::value[BOOST_METAPARSE_LIMIT_STRING_SIZE + 1]
  179. = {BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C), 0};
  180. template <>
  181. struct c_str<boost::metaparse::v1::string<> > :
  182. boost::metaparse::v1::impl::empty_string<>
  183. {
  184. typedef c_str type;
  185. };
  186. #ifdef BOOST_METAPARSE_STRING_CASE
  187. # error BOOST_METAPARSE_STRING_CASE is already defined
  188. #endif
  189. #define BOOST_METAPARSE_STRING_CASE(z, n, unused) \
  190. template <BOOST_PP_ENUM_PARAMS(n, int C)> \
  191. struct \
  192. c_str< \
  193. boost::metaparse::v1::string< \
  194. BOOST_PP_ENUM_PARAMS(n, C) BOOST_PP_COMMA_IF(n) \
  195. BOOST_PP_ENUM( \
  196. BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \
  197. BOOST_NO_CHAR BOOST_PP_TUPLE_EAT(3), \
  198. ~ \
  199. ) \
  200. > \
  201. > \
  202. { \
  203. typedef c_str type; \
  204. static const char value[n + 1]; \
  205. }; \
  206. \
  207. template <BOOST_PP_ENUM_PARAMS(n, int C)> \
  208. const char c_str< \
  209. boost::metaparse::v1::string< \
  210. BOOST_PP_ENUM_PARAMS(n, C) BOOST_PP_COMMA_IF(n) \
  211. BOOST_PP_ENUM( \
  212. BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \
  213. BOOST_NO_CHAR BOOST_PP_TUPLE_EAT(3), \
  214. ~ \
  215. ) \
  216. > \
  217. >::value[n + 1] = {BOOST_PP_ENUM_PARAMS(n, C) BOOST_PP_COMMA_IF(n) 0};
  218. BOOST_PP_REPEAT_FROM_TO(
  219. 1,
  220. BOOST_METAPARSE_LIMIT_STRING_SIZE,
  221. BOOST_METAPARSE_STRING_CASE,
  222. ~
  223. )
  224. #undef BOOST_METAPARSE_STRING_CASE
  225. }
  226. }
  227. #define BOOST_METAPARSE_V1_CONFIG_NO_BOOST_METAPARSE_STRING 1
  228. #endif