File indexing completed on 2025-01-18 09:53:49
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_SUB_MATCH_VECTOR_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_CORE_SUB_MATCH_VECTOR_HPP_EAN_10_04_2005
0010
0011
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015
0016 #include <boost/noncopyable.hpp>
0017 #include <boost/iterator_adaptors.hpp>
0018 #include <boost/xpressive/detail/detail_fwd.hpp>
0019 #include <boost/xpressive/detail/core/sub_match_impl.hpp>
0020
0021 namespace boost { namespace xpressive { namespace detail
0022 {
0023
0024 #if BOOST_ITERATOR_ADAPTORS_VERSION >= 0x0200
0025
0026
0027
0028
0029 template<typename Value, typename MainIter>
0030 struct sub_match_iterator
0031 : iterator_adaptor
0032 <
0033 sub_match_iterator<Value, MainIter>
0034 , MainIter
0035 , Value
0036 , std::random_access_iterator_tag
0037 >
0038 {
0039 typedef iterator_adaptor
0040 <
0041 sub_match_iterator<Value, MainIter>
0042 , MainIter
0043 , Value
0044 , std::random_access_iterator_tag
0045 > base_t;
0046
0047 sub_match_iterator(MainIter baseiter)
0048 : base_t(baseiter)
0049 {
0050 }
0051 };
0052
0053 #endif
0054
0055
0056
0057
0058 template<typename BidiIter>
0059 struct sub_match_vector
0060 : private noncopyable
0061 {
0062 private:
0063 struct dummy { int i_; };
0064 typedef int dummy::*bool_type;
0065
0066 public:
0067 typedef sub_match<BidiIter> value_type;
0068 typedef std::size_t size_type;
0069 typedef value_type const &const_reference;
0070 typedef const_reference reference;
0071 typedef typename iterator_difference<BidiIter>::type difference_type;
0072 typedef typename iterator_value<BidiIter>::type char_type;
0073 typedef typename sub_match<BidiIter>::string_type string_type;
0074
0075 #if BOOST_ITERATOR_ADAPTORS_VERSION >= 0x0200
0076
0077 typedef sub_match_iterator
0078 <
0079 value_type const
0080 , sub_match_impl<BidiIter> const *
0081 > const_iterator;
0082
0083 #else
0084
0085 typedef iterator_adaptor
0086 <
0087 sub_match_impl<BidiIter> const *
0088 , default_iterator_policies
0089 , value_type
0090 , value_type const &
0091 , value_type const *
0092 > const_iterator;
0093
0094 #endif
0095
0096 typedef const_iterator iterator;
0097
0098 sub_match_vector()
0099 : size_(0)
0100 , sub_matches_(0)
0101 {
0102 }
0103
0104 const_reference operator [](size_type index) const
0105 {
0106 static value_type const s_null;
0107 return (index >= this->size_)
0108 ? s_null
0109 : *static_cast<value_type const *>(&this->sub_matches_[ index ]);
0110 }
0111
0112 size_type size() const
0113 {
0114 return this->size_;
0115 }
0116
0117 bool empty() const
0118 {
0119 return 0 == this->size();
0120 }
0121
0122 const_iterator begin() const
0123 {
0124 return const_iterator(this->sub_matches_);
0125 }
0126
0127 const_iterator end() const
0128 {
0129 return const_iterator(this->sub_matches_ + this->size_);
0130 }
0131
0132 operator bool_type() const
0133 {
0134 return (!this->empty() && (*this)[0].matched) ? &dummy::i_ : 0;
0135 }
0136
0137 bool operator !() const
0138 {
0139 return this->empty() || !(*this)[0].matched;
0140 }
0141
0142 void swap(sub_match_vector<BidiIter> &that)
0143 {
0144 std::swap(this->size_, that.size_);
0145 std::swap(this->sub_matches_, that.sub_matches_);
0146 }
0147
0148 private:
0149 friend struct detail::core_access<BidiIter>;
0150
0151 void init_(sub_match_impl<BidiIter> *sub_matches, size_type size)
0152 {
0153 this->size_ = size;
0154 this->sub_matches_ = sub_matches;
0155 }
0156
0157 void init_(sub_match_impl<BidiIter> *sub_matches, size_type size, sub_match_vector<BidiIter> const &that)
0158 {
0159 BOOST_ASSERT(size == that.size_);
0160 this->size_ = size;
0161 this->sub_matches_ = sub_matches;
0162 std::copy(that.sub_matches_, that.sub_matches_ + that.size_, this->sub_matches_);
0163 }
0164
0165 size_type size_;
0166 sub_match_impl<BidiIter> *sub_matches_;
0167 };
0168
0169 }}}
0170
0171 #endif