1 // Boost token_iterator.hpp -------------------------------------------------//
3 // Copyright John R. Bandela 2001
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org/libs/tokenizer for documentation.
11 // 16 Jul 2003 John Bandela
12 // Allowed conversions from convertible base iterators
13 // 03 Jul 2003 John Bandela
14 // Converted to new iterator adapter
18 #ifndef BOOST_TOKENIZER_POLICY_JRB070303_HPP_
19 #define BOOST_TOKENIZER_POLICY_JRB070303_HPP_
21 #include<boost/assert.hpp>
22 #include<boost/iterator/iterator_adaptor.hpp>
23 #include<boost/iterator/detail/minimum_category.hpp>
24 #include<boost/token_functions.hpp>
29 template <class TokenizerFunc
, class Iterator
, class Type
>
31 : public iterator_facade
<
32 token_iterator
<TokenizerFunc
, Iterator
, Type
>
34 , typename
detail::minimum_category
<
36 , typename iterator_traversal
<Iterator
>::type
42 friend class iterator_core_access
;
52 valid_
= f_(begin_
,end_
,tok_
);
55 const Type
& dereference() const {
60 bool equal(const Other
& a
) const{
61 return (a
.valid_
&& valid_
)
62 ?( (a
.begin_
==begin_
) && (a
.end_
== end_
) )
70 valid_
= (begin_
!= end_
)?
71 f_(begin_
,end_
,tok_
):false;
74 token_iterator():begin_(),end_(),valid_(false),tok_() { }
76 token_iterator(TokenizerFunc f
, Iterator begin
, Iterator e
= Iterator())
77 : f_(f
),begin_(begin
),end_(e
),valid_(false),tok_(){ initialize(); }
79 token_iterator(Iterator begin
, Iterator e
= Iterator())
80 : f_(),begin_(begin
),end_(e
),valid_(false),tok_() {initialize();}
82 template<class OtherIter
>
84 token_iterator
<TokenizerFunc
, OtherIter
,Type
> const& t
85 , typename enable_if_convertible
<OtherIter
, Iterator
>::type
* = 0)
86 : f_(t
.tokenizer_function()),begin_(t
.base())
87 ,end_(t
.end()),valid_(!t
.at_end()),tok_(t
.current_token()) {}
89 Iterator
base()const{return begin_
;}
91 Iterator
end()const{return end_
;};
93 TokenizerFunc
tokenizer_function()const{return f_
;}
95 Type
current_token()const{return tok_
;}
97 bool at_end()const{return !valid_
;}
104 class TokenizerFunc
= char_delimiters_separator
<char>,
105 class Iterator
= std::string::const_iterator
,
106 class Type
= std::string
108 class token_iterator_generator
{
112 typedef token_iterator
<TokenizerFunc
,Iterator
,Type
> type
;
116 // Type has to be first because it needs to be explicitly specified
117 // because there is no way the function can deduce it.
118 template<class Type
, class Iterator
, class TokenizerFunc
>
119 typename token_iterator_generator
<TokenizerFunc
,Iterator
,Type
>::type
120 make_token_iterator(Iterator begin
, Iterator end
,const TokenizerFunc
& fun
){
122 token_iterator_generator
<TokenizerFunc
,Iterator
,Type
>::type ret_type
;
123 return ret_type(fun
,begin
,end
);