• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2004 Hartmut Kaiser
3     http://spirit.sourceforge.net/
4 
5     Use, modification and distribution is subject to the Boost Software
6     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7     http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 
10 //  This is a compile only test for verifying, whether the multi_pass<>
11 //  iterator works ok with an input iterator, which returns a value_type and not
12 //  a reference from its dereferencing operator.
13 
14 #include <cstdio>
15 #include <fstream>
16 #include <iterator>
17 
18 #include <boost/spirit/include/classic_core.hpp>
19 #include <boost/spirit/include/classic_multi_pass.hpp>
20 
21 using namespace BOOST_SPIRIT_CLASSIC_NS;
22 using namespace std;
23 
main()24 int main ()
25 {
26     // create a sample file
27     {
28         ofstream out("./input_file.txt");
29         out << 1.0 << "," << 2.0;
30     }
31 
32     int result = 0;
33 
34     // read in the values from the sample file
35     {
36         ifstream in("./input_file.txt"); // we get our input from this file
37 
38         typedef char char_t;
39         typedef multi_pass<istreambuf_iterator<char_t> > iterator_t;
40 
41         typedef skip_parser_iteration_policy<space_parser> it_policy_t;
42         typedef scanner_policies<it_policy_t> scan_policies_t;
43         typedef scanner<iterator_t, scan_policies_t> scanner_t;
44 
45         typedef rule<scanner_t> rule_t;
46 
47         it_policy_t iter_policy(space_p);
48         scan_policies_t policies(iter_policy);
49         iterator_t first(make_multi_pass(std::istreambuf_iterator<char_t>(in)));
50         scanner_t scan(first, make_multi_pass(std::istreambuf_iterator<char_t>()),
51             policies);
52 
53         rule_t n_list = real_p >> *(',' >> real_p);
54         match<> m = n_list.parse(scan);
55 
56         result = !m ? 1 : 0;
57     }
58 
59     std::remove("./input_file.txt");
60     return result;
61 }
62