1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*=============================================================================
Copyright (c) 1998-2003 Joel de Guzman
http://spirit.sourceforge.net/
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_MATCH_ATTR_TRAITS_IPP)
#define BOOST_SPIRIT_MATCH_ATTR_TRAITS_IPP
#include <boost/optional.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/is_same.hpp>
namespace boost { namespace spirit {
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
namespace impl
{
template <typename T>
struct match_attr_traits
{
typedef typename
boost::optional<T>::reference_const_type
const_reference;
// case where src *IS* convertible to T (dest)
template <typename T2>
static void
convert(boost::optional<T>& dest, T2 const& src, mpl::true_)
{
dest.reset(src);
}
// case where src *IS NOT* convertible to T (dest)
template <typename T2>
static void
convert(boost::optional<T>& dest, T2 const& /*src*/, mpl::false_)
{
dest.reset();
}
static void
convert(boost::optional<T>& dest, nil_t/*src*/)
{
dest.reset();
}
template <typename T2>
static void
convert(boost::optional<T>& dest, T2 const& src)
{
convert(dest, src, is_convertible<T2, T>());
}
template <typename OtherMatchT>
static void
copy(boost::optional<T>& dest, OtherMatchT const& src)
{
if (src.has_valid_attribute())
convert(dest, src.value());
}
template <typename OtherMatchT>
static void
assign(boost::optional<T>& dest, OtherMatchT const& src)
{
if (src.has_valid_attribute())
convert(dest, src.value());
else
dest.reset();
}
// T is not reference
template <typename ValueT>
static void
set_value(boost::optional<T>& dest, ValueT const& val, mpl::false_)
{
dest.reset(val);
}
// T is a reference
template <typename ValueT>
static void
set_value(boost::optional<T>& dest, ValueT const& val, mpl::true_)
{
dest.get() = val;
}
};
}
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace boost::spirit::impl
#endif
|