1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3 
4     Distributed under the Boost Software License, Version 1.0. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #ifndef BOOST_SPIRIT_QI_DETAIL_PERMUTE_FUNCTION_HPP
8 #define BOOST_SPIRIT_QI_DETAIL_PERMUTE_FUNCTION_HPP
9 
10 #if defined(_MSC_VER)
11 #pragma once
12 #endif
13 
14 #include <boost/spirit/home/support/unused.hpp>
15 #include <boost/optional.hpp>
16 
17 namespace boost { namespace spirit { namespace qi { namespace detail
18 {
19     template <typename Iterator, typename Context, typename Skipper>
20     struct permute_function
21     {
permute_functionboost::spirit::qi::detail::permute_function22         permute_function(
23             Iterator& first_, Iterator const& last_
24           , Context& context_, Skipper const& skipper_)
25           : first(first_)
26           , last(last_)
27           , context(context_)
28           , skipper(skipper_)
29         {
30         }
31 
32         template <typename Component, typename Attribute>
operator ()boost::spirit::qi::detail::permute_function33         bool operator()(Component const& component, Attribute& attr)
34         {
35             // return true if the parser succeeds and the slot is not yet taken
36             if (!*taken && component.parse(first, last, context, skipper, attr))
37             {
38                 *taken = true;
39                 ++taken;
40                 return true;
41             }
42             ++taken;
43             return false;
44         }
45 
46         template <typename Component>
operator ()boost::spirit::qi::detail::permute_function47         bool operator()(Component const& component)
48         {
49             // return true if the parser succeeds and the slot is not yet taken
50             if (!*taken && component.parse(first, last, context, skipper, unused))
51             {
52                 *taken = true;
53                 ++taken;
54                 return true;
55             }
56             ++taken;
57             return false;
58         }
59 
60         Iterator& first;
61         Iterator const& last;
62         Context& context;
63         Skipper const& skipper;
64         bool* taken;
65 
66         // silence MSVC warning C4512: assignment operator could not be generated
67         BOOST_DELETED_FUNCTION(permute_function& operator= (permute_function const&))
68     };
69 }}}}
70 
71 #endif
72