1 /*=============================================================================
2     Copyright (c) 2001-2011 Hartmut Kaiser
3     Copyright (c) 2011 Brian O'Kennedy
4 
5     Distributed under the Boost Software License, Version 1.0. (See accompanying
6     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 
9 #include <boost/config/warning_disable.hpp>
10 #include <boost/detail/lightweight_test.hpp>
11 
12 #include <boost/spirit/include/qi_char.hpp>
13 #include <boost/spirit/include/qi_numeric.hpp>
14 #include <boost/spirit/include/qi_stream.hpp>
15 #include <boost/spirit/include/qi_operator.hpp>
16 
17 #include "test.hpp"
18 
19 struct complex
20 {
complexcomplex21     complex (double a = 0.0, double b = 0.0) : a(a), b(b) {}
22     double a, b;
23 };
24 
operator >>(std::istream & is,complex & z)25 std::istream& operator>> (std::istream& is, complex& z)
26 {
27     char lbrace = '\0', comma = '\0', rbrace = '\0';
28     is >> lbrace >> z.a >> comma >> z.b >> rbrace;
29     if (lbrace != '{' || comma != ',' || rbrace != '}')
30         is.setstate(std::ios_base::failbit);
31 
32     return is;
33 }
34 
main()35 int main()
36 {
37     using spirit_test::test_attr;
38 
39     {
40         using boost::spirit::qi::blank;
41         using boost::spirit::qi::double_;
42         using boost::spirit::qi::stream;
43         using boost::spirit::qi::stream_parser;
44         using boost::fusion::at_c;
45 
46         complex c;
47         BOOST_TEST(test_attr("{1.0,2.5}",
48                 stream_parser<char, complex>(), c, blank) &&
49             c.a == 1.0 && c.b == 2.5);
50 
51         boost::fusion::vector<complex, double> d;
52         BOOST_TEST(test_attr("{1.0,2.5},123.456",
53                 stream >> ',' >> double_, d, blank) &&
54             at_c<0>(d).a == 1.0 && at_c<0>(d).b == 2.5 && at_c<1>(d) == 123.456);
55     }
56 
57     return boost::report_errors();
58 }
59 
60 
61