1 ///////////////////////////////////////////////////////////////////////////////
2 // sub_match_vector.hpp
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_XPRESSIVE_DETAIL_CORE_SUB_MATCH_VECTOR_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_CORE_SUB_MATCH_VECTOR_HPP_EAN_10_04_2005
11 // MS compatible compilers support #pragma once
16 #include <boost/noncopyable.hpp>
17 #include <boost/iterator_adaptors.hpp>
18 #include <boost/xpressive/detail/detail_fwd.hpp>
19 #include <boost/xpressive/detail/core/sub_match_impl.hpp>
21 namespace boost { namespace xpressive { namespace detail
24 #if BOOST_ITERATOR_ADAPTORS_VERSION >= 0x0200
26 //////////////////////////////////////////////////////////////////////////
29 template<typename Value, typename MainIter>
30 struct sub_match_iterator
33 sub_match_iterator<Value, MainIter>
36 , std::random_access_iterator_tag
39 typedef iterator_adaptor
41 sub_match_iterator<Value, MainIter>
44 , std::random_access_iterator_tag
47 sub_match_iterator(MainIter baseiter)
55 //////////////////////////////////////////////////////////////////////////
58 template<typename BidiIter>
59 struct sub_match_vector
63 struct dummy { int i_; };
64 typedef int dummy::*bool_type;
67 typedef sub_match<BidiIter> value_type;
68 typedef std::size_t size_type;
69 typedef value_type const &const_reference;
70 typedef const_reference reference;
71 typedef typename iterator_difference<BidiIter>::type difference_type;
72 typedef typename iterator_value<BidiIter>::type char_type;
73 typedef typename sub_match<BidiIter>::string_type string_type;
75 #if BOOST_ITERATOR_ADAPTORS_VERSION >= 0x0200
77 typedef sub_match_iterator
80 , sub_match_impl<BidiIter> const *
85 typedef iterator_adaptor
87 sub_match_impl<BidiIter> const *
88 , default_iterator_policies
94 #endif // BOOST_ITERATOR_ADAPTORS_VERSION < 0x0200
96 typedef const_iterator iterator;
104 const_reference operator [](size_type index) const
106 static value_type const s_null;
107 return (index >= this->size_)
109 : *static_cast<value_type const *>(&this->sub_matches_[ index ]);
112 size_type size() const
119 return 0 == this->size();
122 const_iterator begin() const
124 return const_iterator(this->sub_matches_);
127 const_iterator end() const
129 return const_iterator(this->sub_matches_ + this->size_);
132 operator bool_type() const
134 return (!this->empty() && (*this)[0].matched) ? &dummy::i_ : 0;
137 bool operator !() const
139 return this->empty() || !(*this)[0].matched;
142 void swap(sub_match_vector<BidiIter> &that)
144 std::swap(this->size_, that.size_);
145 std::swap(this->sub_matches_, that.sub_matches_);
149 friend struct detail::core_access<BidiIter>;
151 void init_(sub_match_impl<BidiIter> *sub_matches, size_type size)
154 this->sub_matches_ = sub_matches;
157 void init_(sub_match_impl<BidiIter> *sub_matches, size_type size, sub_match_vector<BidiIter> const &that)
159 BOOST_ASSERT(size == that.size_);
161 this->sub_matches_ = sub_matches;
162 std::copy(that.sub_matches_, that.sub_matches_ + that.size_, this->sub_matches_);
166 sub_match_impl<BidiIter> *sub_matches_;
169 }}} // namespace boost::xpressive::detail