1// Copyright (c) 2001-2011 Hartmut Kaiser
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_KARMA_DETAIL_ATTRIBUTES_HPP
8#define BOOST_SPIRIT_KARMA_DETAIL_ATTRIBUTES_HPP
9
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>
13
14///////////////////////////////////////////////////////////////////////////////
15namespace boost { namespace spirit { namespace karma
16{
17 template <typename Exposed, typename Transformed, typename Enable = void>
18 struct transform_attribute
19 {
20 typedef Transformed type;
21 static Transformed pre(Exposed& val)
22 {
23 return Transformed(traits::extract_from<Transformed>(val, unused));
24 }
25 // Karma only, no post() and no fail() required
26 };
27
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>
31 {
32 typedef Transformed const& type;
33 static Transformed const& pre(boost::optional<Exposed> const& val)
34 {
35 return boost::get<Transformed>(val);
36 }
37 };
38
39 template <typename Attribute>
40 struct transform_attribute<Attribute const, Attribute>
41 {
42 typedef Attribute const& type;
43 static Attribute const& pre(Attribute const& val) { return val; }
44 // Karma only, no post() and no fail() required
45 };
46
47 // unused_type needs some special handling as well
48 template <>
49 struct transform_attribute<unused_type, unused_type>
50 {
51 typedef unused_type type;
52 static unused_type pre(unused_type) { return unused; }
53 };
54
55 template <>
56 struct transform_attribute<unused_type const, unused_type>
57 : transform_attribute<unused_type, unused_type>
58 {};
59
60 template <typename Attribute>
61 struct transform_attribute<Attribute, unused_type>
62 : transform_attribute<unused_type, unused_type>
63 {};
64
65 template <typename Attribute>
66 struct transform_attribute<Attribute const, unused_type>
67 : transform_attribute<unused_type, unused_type>
68 {};
69}}}
70
71///////////////////////////////////////////////////////////////////////////////
72namespace boost { namespace spirit { namespace traits { namespace detail
73{
74 template <typename Exposed, typename Transformed>
75 struct transform_attribute_base<Exposed, Transformed, karma::domain>
76 : karma::transform_attribute<Exposed, Transformed>
77 {};
78}}}}
79
80#endif
81

source code of boost/libs/spirit/include/boost/spirit/home/karma/detail/attributes.hpp