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_IPP)
10#define BOOST_SPIRIT_MATCH_IPP
11#include <algorithm>
12
13namespace boost { namespace spirit {
14
15BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
16
17    template <typename T>
18    inline match<T>::match()
19    : len(-1), val() {}
20
21    template <typename T>
22    inline match<T>::match(std::size_t length_)
23    : len(length_), val() {}
24
25    template <typename T>
26    inline match<T>::match(std::size_t length_, ctor_param_t val_)
27    : len(length_), val(val_) {}
28
29    template <typename T>
30    inline bool
31    match<T>::operator!() const
32    {
33        return len < 0;
34    }
35
36    template <typename T>
37    inline std::ptrdiff_t
38    match<T>::length() const
39    {
40        return len;
41    }
42
43    template <typename T>
44    inline bool
45    match<T>::has_valid_attribute() const
46    {
47        return val.is_initialized();
48    }
49
50    template <typename T>
51    inline typename match<T>::return_t
52    match<T>::value() const
53    {
54        BOOST_SPIRIT_ASSERT(val.is_initialized());
55        return *val;
56    }
57
58    template <typename T>
59    inline void
60    match<T>::swap(match& other)
61    {
62        std::swap(len, other.len);
63        std::swap(val, other.val);
64    }
65
66    inline match<nil_t>::match()
67    : len(-1) {}
68
69    inline match<nil_t>::match(std::size_t length_)
70    : len(length_) {}
71
72    inline match<nil_t>::match(std::size_t length_, nil_t)
73    : len(length_) {}
74
75    inline bool
76    match<nil_t>::operator!() const
77    {
78        return len < 0;
79    }
80
81    inline bool
82    match<nil_t>::has_valid_attribute() const
83    {
84        return false;
85    }
86
87    inline std::ptrdiff_t
88    match<nil_t>::length() const
89    {
90        return len;
91    }
92
93    inline nil_t
94    match<nil_t>::value() const
95    {
96        return nil_t();
97    }
98
99    inline void
100    match<nil_t>::value(nil_t) {}
101
102    inline void
103    match<nil_t>::swap(match<nil_t>& other)
104    {
105        std::swap(len, other.len);
106    }
107
108BOOST_SPIRIT_CLASSIC_NAMESPACE_END
109
110}} // namespace boost::spirit
111
112#endif
113
114