]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2014 Joel de Guzman | |
3 | Copyright (c) 2001-2012 Hartmut Kaiser | |
4 | http://spirit.sourceforge.net/ | |
5 | ||
6 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
7 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
8 | =============================================================================*/ | |
9 | #if !defined(BOOST_SPIRIT_X3_MAKE_ATTRIBUTE_JAN_8_2012_0721PM) | |
10 | #define BOOST_SPIRIT_X3_MAKE_ATTRIBUTE_JAN_8_2012_0721PM | |
11 | ||
12 | #include <boost/mpl/if.hpp> | |
13 | #include <boost/type_traits/remove_const.hpp> | |
14 | #include <boost/type_traits/add_reference.hpp> | |
15 | #include <boost/spirit/home/x3/support/unused.hpp> | |
16 | ||
17 | namespace boost { namespace spirit { namespace x3 { namespace traits | |
18 | { | |
19 | template <typename Attribute> | |
20 | struct make_attribute_base | |
21 | { | |
22 | static Attribute call(unused_type) | |
23 | { | |
24 | // synthesize the attribute/parameter | |
25 | return Attribute(); | |
26 | } | |
27 | ||
28 | template <typename T> | |
29 | static T& call(T& value) | |
30 | { | |
31 | return value; // just pass the one provided | |
32 | } | |
33 | }; | |
34 | ||
35 | template <typename Attribute, typename ActualAttribute> | |
36 | struct make_attribute : make_attribute_base<Attribute> | |
37 | { | |
38 | typedef ActualAttribute& type; | |
39 | typedef ActualAttribute value_type; | |
40 | }; | |
41 | ||
42 | template <typename Attribute> | |
43 | struct make_attribute<Attribute, unused_type> | |
44 | : make_attribute_base<Attribute> | |
45 | { | |
46 | typedef typename remove_const<Attribute>::type attribute_type; | |
47 | typedef attribute_type type; | |
48 | typedef attribute_type value_type; | |
49 | }; | |
50 | ||
51 | template <typename Attribute, typename ActualAttribute> | |
52 | struct make_attribute<Attribute&, ActualAttribute> | |
53 | : make_attribute<Attribute, ActualAttribute> {}; | |
54 | ||
55 | template <typename Attribute, typename ActualAttribute> | |
56 | struct make_attribute<Attribute const&, ActualAttribute> | |
57 | : make_attribute<Attribute const, ActualAttribute> {}; | |
58 | ||
59 | template <typename ActualAttribute> | |
60 | struct make_attribute<unused_type, ActualAttribute> | |
61 | { | |
62 | typedef unused_type type; | |
63 | typedef unused_type value_type; | |
64 | static unused_type call(unused_type) | |
65 | { | |
66 | return unused; | |
67 | } | |
68 | }; | |
69 | ||
70 | template <> | |
71 | struct make_attribute<unused_type, unused_type> | |
72 | { | |
73 | typedef unused_type type; | |
74 | typedef unused_type value_type; | |
75 | static unused_type call(unused_type) | |
76 | { | |
77 | return unused; | |
78 | } | |
79 | }; | |
80 | }}}} | |
81 | ||
82 | #endif |