• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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>
20 
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>
26 
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()
30 
31 #endif
32 
33 ///////////////////////////////////////////////////////////////////////////////
34 //
35 //  Preprocessor vertical repetition code
36 //
37 ///////////////////////////////////////////////////////////////////////////////
38 #else // defined(BOOST_PP_IS_ITERATING)
39 
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) &&
45 
46 namespace spirit_test
47 {
48     ///////////////////////////////////////////////////////////////////////////
49     template <typename Char, typename Parser
50       , BOOST_PP_ENUM_PARAMS(N, typename A)>
test(Char const * in,Parser const & p,BOOST_PP_ENUM_BINARY_PARAMS (N,A,val))51     inline bool test(Char const *in, Parser const& p
52       , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
53     {
54         namespace qi = boost::spirit::qi;
55 
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));
59 
60         return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
61     }
62 
63     ///////////////////////////////////////////////////////////////////////////
64     template <typename Char, typename Parser, typename Skipper
65       , BOOST_PP_ENUM_PARAMS(N, typename A)>
test_skipped(Char const * in,Parser const & p,Skipper const & skipper,BOOST_PP_ENUM_BINARY_PARAMS (N,A,val))66     inline bool test_skipped(Char const *in, Parser const& p
67       , Skipper const& skipper, BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
68     {
69         namespace qi = boost::spirit::qi;
70 
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));
74 
75         return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
76     }
77 
78     ///////////////////////////////////////////////////////////////////////////
79     template <typename Char, typename Parser, typename Skipper
80       , BOOST_PP_ENUM_PARAMS(N, typename A)>
test_postskipped(Char const * in,Parser const & p,Skipper const & skipper,BOOST_SCOPED_ENUM (boost::spirit::qi::skip_flag)post_skip,BOOST_PP_ENUM_BINARY_PARAMS (N,A,val))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))
85     {
86         namespace qi = boost::spirit::qi;
87 
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));
92 
93         return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
94     }
95 
96 }   // namespace spirit_test
97 
98 #undef COMPARE_ATTRIBUTE
99 #undef DEFINE_ATTRIBUTE
100 #undef N
101 
102 #endif
103