test_manip_attr.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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(BOOST_PP_IS_ITERATING)
  6. #if !defined(BOOST_SPIRIT_QI_TEST_MANIP_ATTR_APR_23_2009_0605PM)
  7. #define BOOST_SPIRIT_QI_TEST_MANIP_ATTR_APR_23_2009_0605PM
  8. #include <cstring>
  9. #include <string>
  10. #include <iterator>
  11. #include <iostream>
  12. #include <typeinfo>
  13. #include <boost/spirit/include/qi_parse.hpp>
  14. #include <boost/spirit/include/qi_stream.hpp>
  15. #include <boost/spirit/include/qi_match_attr.hpp>
  16. #include <boost/preprocessor/cat.hpp>
  17. #include <boost/preprocessor/iterate.hpp>
  18. #include <boost/preprocessor/repetition/repeat.hpp>
  19. #include <boost/preprocessor/repetition/enum_params.hpp>
  20. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  21. #define BOOST_PP_FILENAME_1 "test_manip_attr.hpp"
  22. #define BOOST_PP_ITERATION_LIMITS (1, SPIRIT_ARGUMENTS_LIMIT)
  23. #include BOOST_PP_ITERATE()
  24. #endif
  25. ///////////////////////////////////////////////////////////////////////////////
  26. //
  27. // Preprocessor vertical repetition code
  28. //
  29. ///////////////////////////////////////////////////////////////////////////////
  30. #else // defined(BOOST_PP_IS_ITERATING)
  31. #define N BOOST_PP_ITERATION()
  32. #define DEFINE_ATTRIBUTE(z, n, _) \
  33. BOOST_PP_CAT(A, n) BOOST_PP_CAT(attr, n) = BOOST_PP_CAT(A, n)();
  34. #define COMPARE_ATTRIBUTE(z, n, _) \
  35. BOOST_PP_CAT(attr, n) == BOOST_PP_CAT(val, n) &&
  36. namespace spirit_test
  37. {
  38. ///////////////////////////////////////////////////////////////////////////
  39. template <typename Char, typename Parser
  40. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  41. inline bool test(Char const *in, Parser const& p
  42. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
  43. {
  44. namespace qi = boost::spirit::qi;
  45. std::basic_stringstream<Char> strm(in);
  46. BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
  47. strm >> qi::match(p, BOOST_PP_ENUM_PARAMS(N, attr));
  48. return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
  49. }
  50. ///////////////////////////////////////////////////////////////////////////
  51. template <typename Char, typename Parser, typename Skipper
  52. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  53. inline bool test_skipped(Char const *in, Parser const& p
  54. , Skipper const& skipper, BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
  55. {
  56. namespace qi = boost::spirit::qi;
  57. std::basic_stringstream<Char> strm(in);
  58. BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
  59. strm >> qi::phrase_match(p, skipper, BOOST_PP_ENUM_PARAMS(N, attr));
  60. return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
  61. }
  62. ///////////////////////////////////////////////////////////////////////////
  63. template <typename Char, typename Parser, typename Skipper
  64. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  65. inline bool test_postskipped(Char const *in, Parser const& p
  66. , Skipper const& skipper
  67. , BOOST_SCOPED_ENUM(boost::spirit::qi::skip_flag) post_skip
  68. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
  69. {
  70. namespace qi = boost::spirit::qi;
  71. std::basic_stringstream<Char> strm(in);
  72. BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
  73. strm >> qi::phrase_match(p, skipper, post_skip
  74. , BOOST_PP_ENUM_PARAMS(N, attr));
  75. return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
  76. }
  77. } // namespace spirit_test
  78. #undef COMPARE_ATTRIBUTE
  79. #undef DEFINE_ATTRIBUTE
  80. #undef N
  81. #endif