Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:14

0001 // Boost.Range library
0002 //
0003 //  Copyright Thorsten Ottosen, Neil Groves 2006. Use, modification and
0004 //  distribution is subject to the Boost Software License, Version
0005 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0006 //  http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // For more information, see http://www.boost.org/libs/range/
0009 //
0010 
0011 #ifndef BOOST_RANGE_ADAPTOR_TOKENIZED_HPP
0012 #define BOOST_RANGE_ADAPTOR_TOKENIZED_HPP
0013 
0014 #include <boost/regex.hpp>
0015 #include <boost/range/iterator_range.hpp>
0016 
0017 namespace boost
0018 {
0019     namespace range_detail
0020     {
0021 
0022         template< class R >
0023         struct tokenized_range : 
0024             public boost::iterator_range< 
0025                       boost::regex_token_iterator< 
0026                           BOOST_DEDUCED_TYPENAME range_iterator<R>::type 
0027                                               >
0028                                          >
0029         {
0030         private:
0031             typedef           
0032                 boost::regex_token_iterator< 
0033                           BOOST_DEDUCED_TYPENAME range_iterator<R>::type 
0034                                             >
0035                 regex_iter;
0036             
0037             typedef BOOST_DEDUCED_TYPENAME regex_iter::regex_type 
0038                 regex_type;
0039         
0040             typedef boost::iterator_range<regex_iter> 
0041                 base;
0042 
0043         public:
0044             template< class Regex, class Submatch, class Flag >
0045             tokenized_range( R& r, const Regex& re, const Submatch& sub, Flag f )
0046               : base( regex_iter( boost::begin(r), boost::end(r), 
0047                                   regex_type(re), sub, f ),
0048                       regex_iter() )
0049             { }
0050         };
0051 
0052         template< class T, class U, class V >
0053         struct regex_holder
0054         {
0055             T  re;
0056             U  sub;
0057             V  f;
0058 
0059             regex_holder( const T& rex, const U& subm, V flag ) :
0060                 re(rex), sub(subm), f(flag)
0061             { }
0062         private:
0063             // Not assignable
0064             void operator=(const regex_holder&);
0065         };
0066 
0067         struct regex_forwarder
0068         {           
0069             template< class Regex >
0070             regex_holder<Regex,int,regex_constants::match_flag_type>
0071             operator()( const Regex& re, 
0072                         int submatch = 0,    
0073                         regex_constants::match_flag_type f = 
0074                             regex_constants::match_default ) const
0075             {
0076                 return regex_holder<Regex,int,
0077                            regex_constants::match_flag_type>( re, submatch, f );
0078             }
0079              
0080             template< class Regex, class Submatch >
0081             regex_holder<Regex,Submatch,regex_constants::match_flag_type> 
0082             operator()( const Regex& re, 
0083                         const Submatch& sub, 
0084                         regex_constants::match_flag_type f = 
0085                             regex_constants::match_default ) const
0086             {
0087                 return regex_holder<Regex,Submatch,
0088                            regex_constants::match_flag_type>( re, sub, f ); 
0089             }
0090         };
0091         
0092         template< class BidirectionalRng, class R, class S, class F >
0093         inline tokenized_range<BidirectionalRng> 
0094         operator|( BidirectionalRng& r, 
0095                    const regex_holder<R,S,F>& f )
0096         {
0097             return tokenized_range<BidirectionalRng>( r, f.re, f.sub, f.f );   
0098         }
0099 
0100         template< class BidirectionalRng, class R, class S, class F  >
0101         inline tokenized_range<const BidirectionalRng> 
0102         operator|( const BidirectionalRng& r, 
0103                    const regex_holder<R,S,F>& f )
0104         {
0105             return tokenized_range<const BidirectionalRng>( r, f.re, f.sub, f.f );
0106         }
0107         
0108     } // 'range_detail'
0109 
0110     using range_detail::tokenized_range;
0111 
0112     namespace adaptors
0113     { 
0114         namespace
0115         {
0116             const range_detail::regex_forwarder tokenized = 
0117                     range_detail::regex_forwarder();
0118         }
0119         
0120         template<class BidirectionalRange, class Regex, class Submatch, class Flag>
0121         inline tokenized_range<BidirectionalRange>
0122         tokenize(BidirectionalRange& rng, const Regex& reg, const Submatch& sub, Flag f)
0123         {
0124             return tokenized_range<BidirectionalRange>(rng, reg, sub, f);
0125         }
0126         
0127         template<class BidirectionalRange, class Regex, class Submatch, class Flag>
0128         inline tokenized_range<const BidirectionalRange>
0129         tokenize(const BidirectionalRange& rng, const Regex& reg, const Submatch& sub, Flag f)
0130         {
0131             return tokenized_range<const BidirectionalRange>(rng, reg, sub, f);
0132         }
0133     } // 'adaptors'
0134     
0135 }
0136 
0137 #endif