1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/token_iterator.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,128 @@
1.4 +// Boost token_iterator.hpp -------------------------------------------------//
1.5 +
1.6 +// Copyright John R. Bandela 2001
1.7 +// Distributed under the Boost Software License, Version 1.0. (See
1.8 +// accompanying file LICENSE_1_0.txt or copy at
1.9 +// http://www.boost.org/LICENSE_1_0.txt)
1.10 +
1.11 +// See http://www.boost.org/libs/tokenizer for documentation.
1.12 +
1.13 +// Revision History:
1.14 +// 16 Jul 2003 John Bandela
1.15 +// Allowed conversions from convertible base iterators
1.16 +// 03 Jul 2003 John Bandela
1.17 +// Converted to new iterator adapter
1.18 +
1.19 +
1.20 +
1.21 +#ifndef BOOST_TOKENIZER_POLICY_JRB070303_HPP_
1.22 +#define BOOST_TOKENIZER_POLICY_JRB070303_HPP_
1.23 +
1.24 +#include<boost/assert.hpp>
1.25 +#include<boost/iterator/iterator_adaptor.hpp>
1.26 +#include<boost/iterator/detail/minimum_category.hpp>
1.27 +#include<boost/token_functions.hpp>
1.28 +#include<utility>
1.29 +
1.30 +namespace boost
1.31 +{
1.32 + template <class TokenizerFunc, class Iterator, class Type>
1.33 + class token_iterator
1.34 + : public iterator_facade<
1.35 + token_iterator<TokenizerFunc, Iterator, Type>
1.36 + , Type
1.37 + , typename detail::minimum_category<
1.38 + forward_traversal_tag
1.39 + , typename iterator_traversal<Iterator>::type
1.40 + >::type
1.41 + , const Type&
1.42 + >
1.43 + {
1.44 +
1.45 + friend class iterator_core_access;
1.46 +
1.47 + TokenizerFunc f_;
1.48 + Iterator begin_;
1.49 + Iterator end_;
1.50 + bool valid_;
1.51 + Type tok_;
1.52 +
1.53 + void increment(){
1.54 + BOOST_ASSERT(valid_);
1.55 + valid_ = f_(begin_,end_,tok_);
1.56 + }
1.57 +
1.58 + const Type& dereference() const {
1.59 + BOOST_ASSERT(valid_);
1.60 + return tok_;
1.61 + }
1.62 + template<class Other>
1.63 + bool equal(const Other& a) const{
1.64 + return (a.valid_ && valid_)
1.65 + ?( (a.begin_==begin_) && (a.end_ == end_) )
1.66 + :(a.valid_==valid_);
1.67 +
1.68 + }
1.69 +
1.70 + void initialize(){
1.71 + if(valid_) return;
1.72 + f_.reset();
1.73 + valid_ = (begin_ != end_)?
1.74 + f_(begin_,end_,tok_):false;
1.75 + }
1.76 + public:
1.77 + token_iterator():begin_(),end_(),valid_(false),tok_() { }
1.78 +
1.79 + token_iterator(TokenizerFunc f, Iterator begin, Iterator e = Iterator())
1.80 + : f_(f),begin_(begin),end_(e),valid_(false),tok_(){ initialize(); }
1.81 +
1.82 + token_iterator(Iterator begin, Iterator e = Iterator())
1.83 + : f_(),begin_(begin),end_(e),valid_(false),tok_() {initialize();}
1.84 +
1.85 + template<class OtherIter>
1.86 + token_iterator(
1.87 + token_iterator<TokenizerFunc, OtherIter,Type> const& t
1.88 + , typename enable_if_convertible<OtherIter, Iterator>::type* = 0)
1.89 + : f_(t.tokenizer_function()),begin_(t.base())
1.90 + ,end_(t.end()),valid_(t.at_end()),tok_(t.current_token()) {}
1.91 +
1.92 + Iterator base()const{return begin_;}
1.93 +
1.94 + Iterator end()const{return end_;};
1.95 +
1.96 + TokenizerFunc tokenizer_function()const{return f_;}
1.97 +
1.98 + Type current_token()const{return tok_;}
1.99 +
1.100 + bool at_end()const{return valid_;}
1.101 +
1.102 +
1.103 +
1.104 +
1.105 + };
1.106 + template <
1.107 + class TokenizerFunc = char_delimiters_separator<char>,
1.108 + class Iterator = std::string::const_iterator,
1.109 + class Type = std::string
1.110 + >
1.111 + class token_iterator_generator {
1.112 +
1.113 + private:
1.114 + public:
1.115 + typedef token_iterator<TokenizerFunc,Iterator,Type> type;
1.116 + };
1.117 +
1.118 +
1.119 + // Type has to be first because it needs to be explicitly specified
1.120 + // because there is no way the function can deduce it.
1.121 + template<class Type, class Iterator, class TokenizerFunc>
1.122 + typename token_iterator_generator<TokenizerFunc,Iterator,Type>::type
1.123 + make_token_iterator(Iterator begin, Iterator end,const TokenizerFunc& fun){
1.124 + typedef typename
1.125 + token_iterator_generator<TokenizerFunc,Iterator,Type>::type ret_type;
1.126 + return ret_type(fun,begin,end);
1.127 + }
1.128 +
1.129 +} // namespace boost
1.130 +
1.131 +#endif