1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 // Copyright (c) 2001-2011 Joel de Guzman
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)
7 #if !defined(SPIRIT_KARMA_DETAIL_ATTRIBUTES_APR_18_2010_0453PM)
8 #define SPIRIT_KARMA_DETAIL_ATTRIBUTES_APR_18_2010_0453PM
10 #include <boost/spirit/home/karma/domain.hpp>
11 #include <boost/spirit/home/support/attributes_fwd.hpp>
12 #include <boost/spirit/home/support/attributes.hpp>
14 ///////////////////////////////////////////////////////////////////////////////
15 namespace boost { namespace spirit { namespace karma
17 template <typename Exposed, typename Transformed, typename Enable = void>
18 struct transform_attribute
20 typedef Transformed type;
21 static Transformed pre(Exposed& val)
23 return Transformed(traits::extract_from<Transformed>(val, unused));
25 // Karma only, no post() and no fail() required
28 template <typename Exposed, typename Transformed>
29 struct transform_attribute<boost::optional<Exposed> const, Transformed
30 , typename disable_if<is_same<boost::optional<Exposed>, Transformed> >::type>
32 typedef Transformed const& type;
33 static Transformed const& pre(boost::optional<Exposed> const& val)
35 return boost::get<Transformed>(val);
39 template <typename Attribute>
40 struct transform_attribute<Attribute const, Attribute>
42 typedef Attribute const& type;
43 static Attribute const& pre(Attribute const& val) { return val; }
44 // Karma only, no post() and no fail() required
47 // reference types need special handling
48 template <typename Exposed, typename Transformed>
49 struct transform_attribute<Exposed&, Transformed>
50 : transform_attribute<Exposed, Transformed>
53 template <typename Exposed, typename Transformed>
54 struct transform_attribute<Exposed const&, Transformed>
55 : transform_attribute<Exposed const, Transformed>
58 template <typename Attribute>
59 struct transform_attribute<Attribute const&, Attribute>
60 : transform_attribute<Attribute const, Attribute>
63 // unused_type needs some special handling as well
65 struct transform_attribute<unused_type, unused_type>
67 typedef unused_type type;
68 static unused_type pre(unused_type) { return unused; }
72 struct transform_attribute<unused_type const, unused_type>
73 : transform_attribute<unused_type, unused_type>
76 template <typename Attribute>
77 struct transform_attribute<unused_type, Attribute>
78 : transform_attribute<unused_type, unused_type>
81 template <typename Attribute>
82 struct transform_attribute<unused_type const, Attribute>
83 : transform_attribute<unused_type, unused_type>
86 template <typename Attribute>
87 struct transform_attribute<Attribute, unused_type>
88 : transform_attribute<unused_type, unused_type>
91 template <typename Attribute>
92 struct transform_attribute<Attribute const, unused_type>
93 : transform_attribute<unused_type, unused_type>
97 ///////////////////////////////////////////////////////////////////////////////
98 namespace boost { namespace spirit { namespace traits
100 template <typename Exposed, typename Transformed>
101 struct transform_attribute<Exposed, Transformed, karma::domain>
102 : karma::transform_attribute<Exposed, Transformed>