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