source: NonGTP/Boost/boost/spirit/core/impl/match_attr_traits.ipp @ 857

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