1 // Copyright (c) 2001-2011 Hartmut Kaiser
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)
6 #if !defined(BOOST_PP_IS_ITERATING)
8 #if !defined(BOOST_SPIRIT_QI_TEST_MANIP_ATTR_APR_23_2009_0605PM)
9 #define BOOST_SPIRIT_QI_TEST_MANIP_ATTR_APR_23_2009_0605PM
17 #include <boost/spirit/include/qi_parse.hpp>
18 #include <boost/spirit/include/qi_stream.hpp>
19 #include <boost/spirit/include/qi_match_attr.hpp>
21 #include <boost/preprocessor/cat.hpp>
22 #include <boost/preprocessor/iterate.hpp>
23 #include <boost/preprocessor/repetition/repeat.hpp>
24 #include <boost/preprocessor/repetition/enum_params.hpp>
25 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
27 #define BOOST_PP_FILENAME_1 "test_manip_attr.hpp"
28 #define BOOST_PP_ITERATION_LIMITS (1, SPIRIT_ARGUMENTS_LIMIT)
29 #include BOOST_PP_ITERATE()
33 ///////////////////////////////////////////////////////////////////////////////
35 // Preprocessor vertical repetition code
37 ///////////////////////////////////////////////////////////////////////////////
38 #else // defined(BOOST_PP_IS_ITERATING)
40 #define N BOOST_PP_ITERATION()
41 #define DEFINE_ATTRIBUTE(z, n, _) \
42 BOOST_PP_CAT(A, n) BOOST_PP_CAT(attr, n) = BOOST_PP_CAT(A, n)();
43 #define COMPARE_ATTRIBUTE(z, n, _) \
44 BOOST_PP_CAT(attr, n) == BOOST_PP_CAT(val, n) &&
48 ///////////////////////////////////////////////////////////////////////////
49 template <typename Char, typename Parser
50 , BOOST_PP_ENUM_PARAMS(N, typename A)>
51 inline bool test(Char const *in, Parser const& p
52 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
54 namespace qi = boost::spirit::qi;
56 std::basic_stringstream<Char> strm(in);
57 BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
58 strm >> qi::match(p, BOOST_PP_ENUM_PARAMS(N, attr));
60 return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
63 ///////////////////////////////////////////////////////////////////////////
64 template <typename Char, typename Parser, typename Skipper
65 , BOOST_PP_ENUM_PARAMS(N, typename A)>
66 inline bool test_skipped(Char const *in, Parser const& p
67 , Skipper const& skipper, BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
69 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, BOOST_PP_ENUM_PARAMS(N, attr));
75 return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
78 ///////////////////////////////////////////////////////////////////////////
79 template <typename Char, typename Parser, typename Skipper
80 , BOOST_PP_ENUM_PARAMS(N, typename A)>
81 inline bool test_postskipped(Char const *in, Parser const& p
82 , Skipper const& skipper
83 , BOOST_SCOPED_ENUM(boost::spirit::qi::skip_flag) post_skip
84 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
86 namespace qi = boost::spirit::qi;
88 std::basic_stringstream<Char> strm(in);
89 BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
90 strm >> qi::phrase_match(p, skipper, post_skip
91 , BOOST_PP_ENUM_PARAMS(N, attr));
93 return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
96 } // namespace spirit_test
98 #undef COMPARE_ATTRIBUTE
99 #undef DEFINE_ATTRIBUTE