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