1 // Boost token_iterator.hpp -------------------------------------------------//
3 // Copyright John R. Bandela 2001
4 // Permission to copy, use, modify, sell and distribute this software
5 // is granted provided this copyright notice appears in all
6 // copies. This software is provided "as is" without express or
7 // implied warranty, and with no claim as to its suitability for any
10 // See http://www.boost.org/libs/tokenizer for documentation.
13 // 16 Jul 2003 John Bandela
14 // Allowed conversions from convertible base iterators
15 // 03 Jul 2003 John Bandela
16 // Converted to new iterator adapter
20 #ifndef BOOST_TOKENIZER_POLICY_JRB070303_HPP_
21 #define BOOST_TOKENIZER_POLICY_JRB070303_HPP_
23 #include<boost/iterator/iterator_adaptor.hpp>
24 #include<boost/iterator/detail/minimum_category.hpp>
25 #include<boost/token_functions.hpp>
32 template <class TokenizerFunc, class Iterator, class Type>
34 : public iterator_facade<
35 token_iterator<TokenizerFunc, Iterator, Type>
37 , typename detail::minimum_category<
39 , typename iterator_traversal<Iterator>::type
45 friend class iterator_core_access;
55 valid_ = f_(begin_,end_,tok_);
58 const Type& dereference() const {
63 bool equal(const Other& a) const{
64 return (a.valid_ && valid_)
65 ?( (a.begin_==begin_) && (a.end_ == end_) )
73 valid_ = (begin_ != end_)?
74 f_(begin_,end_,tok_):false;
77 token_iterator():begin_(),end_(),valid_(false),tok_() { }
79 token_iterator(TokenizerFunc f, Iterator begin, Iterator e = Iterator())
80 : f_(f),begin_(begin),end_(e),valid_(false),tok_(){ initialize(); }
82 token_iterator(Iterator begin, Iterator e = Iterator())
83 : f_(),begin_(begin),end_(e),valid_(false),tok_() {initialize();}
85 template<class OtherIter>
87 token_iterator<TokenizerFunc, OtherIter,Type> const& t
88 , typename enable_if_convertible<OtherIter, Iterator>::type* = 0)
89 : f_(t.tokenizer_function()),begin_(t.base())
90 ,end_(t.end()),valid_(t.at_end()),tok_(t.current_token()) {}
92 Iterator base()const{return begin_;}
94 Iterator end()const{return end_;};
96 TokenizerFunc tokenizer_function()const{return f_;}
98 Type current_token()const{return tok_;}
100 bool at_end()const{return valid_;}
107 class TokenizerFunc = char_delimiters_separator<char>,
108 class Iterator = std::string::const_iterator,
109 class Type = std::string
111 class token_iterator_generator {
115 typedef token_iterator<TokenizerFunc,Iterator,Type> type;
119 // Type has to be first because it needs to be explicitly specified
120 // because there is no way the function can deduce it.
121 template<class Type, class Iterator, class TokenizerFunc>
122 typename token_iterator_generator<TokenizerFunc,Iterator,Type>::type
123 make_token_iterator(Iterator begin, Iterator end,const TokenizerFunc& fun){
125 token_iterator_generator<TokenizerFunc,Iterator,Type>::type ret_type;
126 return ret_type(fun,begin,end);