File indexing completed on 2025-01-31 10:01:56
0001
0002
0003
0004
0005
0006
0007
0008 #if !defined(BOOST_SPIRIT_MATCH_HPP)
0009 #define BOOST_SPIRIT_MATCH_HPP
0010
0011 #include <boost/spirit/home/classic/namespace.hpp>
0012 #include <boost/spirit/home/classic/core/config.hpp>
0013 #include <boost/spirit/home/classic/core/nil.hpp>
0014 #include <boost/call_traits.hpp>
0015 #include <boost/optional.hpp>
0016 #include <boost/spirit/home/classic/core/assert.hpp>
0017 #include <boost/spirit/home/classic/core/safe_bool.hpp>
0018 #include <boost/spirit/home/classic/core/impl/match_attr_traits.ipp>
0019 #include <boost/type_traits/add_const.hpp>
0020 #include <boost/type_traits/add_reference.hpp>
0021 #include <boost/type_traits/conditional.hpp>
0022 #include <boost/type_traits/is_reference.hpp>
0023
0024 namespace boost { namespace spirit {
0025
0026 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 template <typename T = nil_t>
0065 class match : public safe_bool<match<T> >
0066 {
0067 typedef typename
0068 conditional<
0069 is_reference<T>::value
0070 , T
0071 , typename add_reference<
0072 typename add_const<T>::type
0073 >::type
0074 >::type attr_ref_t;
0075
0076 public:
0077
0078 typedef typename boost::optional<T> optional_type;
0079 typedef attr_ref_t ctor_param_t;
0080 typedef attr_ref_t return_t;
0081 typedef T attr_t;
0082
0083 match();
0084 explicit match(std::size_t length);
0085 match(std::size_t length, ctor_param_t val);
0086
0087 bool operator!() const;
0088 std::ptrdiff_t length() const;
0089 bool has_valid_attribute() const;
0090 return_t value() const;
0091 void swap(match& other);
0092
0093 template <typename T2>
0094 match(match<T2> const& other)
0095 : len(other.length()), val()
0096 {
0097 impl::match_attr_traits<T>::copy(val, other);
0098 }
0099
0100 template <typename T2>
0101 match&
0102 operator=(match<T2> const& other)
0103 {
0104 impl::match_attr_traits<T>::assign(val, other);
0105 len = other.length();
0106 return *this;
0107 }
0108
0109 template <typename MatchT>
0110 void
0111 concat(MatchT const& other)
0112 {
0113 BOOST_SPIRIT_ASSERT(*this && other);
0114 len += other.length();
0115 }
0116
0117 template <typename ValueT>
0118 void
0119 value(ValueT const& val_)
0120 {
0121 impl::match_attr_traits<T>::set_value(val, val_, is_reference<T>());
0122 }
0123
0124 bool operator_bool() const
0125 {
0126 return len >= 0;
0127 }
0128
0129 private:
0130
0131 std::ptrdiff_t len;
0132 optional_type val;
0133 };
0134
0135
0136
0137
0138
0139
0140 template <>
0141 class match<nil_t> : public safe_bool<match<nil_t> >
0142 {
0143 public:
0144
0145 typedef nil_t attr_t;
0146 typedef nil_t return_t;
0147
0148 match();
0149 explicit match(std::size_t length);
0150 match(std::size_t length, nil_t);
0151
0152 bool operator!() const;
0153 bool has_valid_attribute() const;
0154 std::ptrdiff_t length() const;
0155 nil_t value() const;
0156 void value(nil_t);
0157 void swap(match& other);
0158
0159 template <typename T>
0160 match(match<T> const& other)
0161 : len(other.length()) {}
0162
0163 template <typename T>
0164 match<>&
0165 operator=(match<T> const& other)
0166 {
0167 len = other.length();
0168 return *this;
0169 }
0170
0171 template <typename T>
0172 void
0173 concat(match<T> const& other)
0174 {
0175 BOOST_SPIRIT_ASSERT(*this && other);
0176 len += other.length();
0177 }
0178
0179 bool operator_bool() const
0180 {
0181 return len >= 0;
0182 }
0183
0184 private:
0185
0186 std::ptrdiff_t len;
0187 };
0188
0189 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0190
0191 }}
0192
0193 #endif
0194 #include <boost/spirit/home/classic/core/impl/match.ipp>
0195