| 1 | <html> | 
|---|
| 2 |  | 
|---|
| 3 | <head> | 
|---|
| 4 | <meta http-equiv="Content-Type" | 
|---|
| 5 | content="text/html; charset=iso-8859-1"> | 
|---|
| 6 | <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0"> | 
|---|
| 7 | <title>Boost Token Iterator</title> | 
|---|
| 8 | <!-- | 
|---|
| 9 |   -- Copyright © John Bandela 2001 | 
|---|
| 10 |   -- | 
|---|
| 11 |   -- Permission to use, copy, modify, distribute and sell this software | 
|---|
| 12 |   -- and its documentation for any purpose is hereby granted without fee, | 
|---|
| 13 |   -- provided that the above copyright notice appears in all copies and | 
|---|
| 14 |   -- that both that copyright notice and this permission notice appear | 
|---|
| 15 |   -- in supporting documentation.  Jeremy Siek makes no | 
|---|
| 16 |   -- representations about the suitability of this software for any | 
|---|
| 17 |   -- purpose.  It is provided "as is" without express or implied warranty. | 
|---|
| 18 |   --> | 
|---|
| 19 | </head> | 
|---|
| 20 |  | 
|---|
| 21 | <body bgcolor="#FFFFFF" text="#000000" link="#0000EE" | 
|---|
| 22 | vlink="#551A8B" alink="#FF0000"> | 
|---|
| 23 |  | 
|---|
| 24 | <p><img src="../../boost.png" alt="C++ Boost" width="277" | 
|---|
| 25 | height="86"> <br> | 
|---|
| 26 | </p> | 
|---|
| 27 |  | 
|---|
| 28 | <h1 align="center">Token Iterator</h1> | 
|---|
| 29 |  | 
|---|
| 30 | <pre> | 
|---|
| 31 | template < | 
|---|
| 32 |         class TokenizerFunc = char_delimiters_separator<char>,  | 
|---|
| 33 |         class Iterator = std::string::const_iterator, | 
|---|
| 34 |         class Type = std::string | 
|---|
| 35 | > | 
|---|
| 36 | class token_iterator_generator </pre> | 
|---|
| 37 |  | 
|---|
| 38 | <pre>template<class Type, class Iterator, class TokenizerFunc> | 
|---|
| 39 | typename token_iterator_generator<TokenizerFunc,Iterator,Type>::type  | 
|---|
| 40 | make_token_iterator(Iterator begin, Iterator end,const TokenizerFunc& fun) | 
|---|
| 41 |  | 
|---|
| 42 | </pre> | 
|---|
| 43 |  | 
|---|
| 44 | <p>The token iterator serves to provide an iterator view of the | 
|---|
| 45 | tokens in a parsed sequence.</p> | 
|---|
| 46 |  | 
|---|
| 47 | <h2>Example</h2> | 
|---|
| 48 |  | 
|---|
| 49 | <pre> | 
|---|
| 50 | /// simple_example_5.cpp | 
|---|
| 51 | #include<iostream> | 
|---|
| 52 | #include<boost/token_iterator.hpp> | 
|---|
| 53 | #include<string> | 
|---|
| 54 |  | 
|---|
| 55 | int main(){ | 
|---|
| 56 |    using namespace std; | 
|---|
| 57 |    using namespace boost; | 
|---|
| 58 |    string s = "12252001"; | 
|---|
| 59 |    int offsets[] = {2,2,4}; | 
|---|
| 60 |    offset_separator f(offsets, offsets+3); | 
|---|
| 61 |    typedef token_iterator_generator<offset_separator>::type Iter; | 
|---|
| 62 |    Iter beg = make_token_iterator<string>(s.begin(),s.end(),f); | 
|---|
| 63 |    Iter end = make_token_iterator<string>(s.end(),s.end(),f);  | 
|---|
| 64 |    // The above statement could also have been what is below | 
|---|
| 65 |    // Iter end; | 
|---|
| 66 |    for(;beg!=end;++beg){ | 
|---|
| 67 |      cout << *beg << "\n"; | 
|---|
| 68 |    } | 
|---|
| 69 | } | 
|---|
| 70 | </pre> | 
|---|
| 71 |  | 
|---|
| 72 | <pre> | 
|---|
| 73 | </pre> | 
|---|
| 74 |  | 
|---|
| 75 | <p> </p> | 
|---|
| 76 |  | 
|---|
| 77 | <h3>Template Parameters</h3> | 
|---|
| 78 |  | 
|---|
| 79 | <table border="1"> | 
|---|
| 80 |     <tr> | 
|---|
| 81 |         <th>Parameter</th> | 
|---|
| 82 |         <th>Description</th> | 
|---|
| 83 |     </tr> | 
|---|
| 84 |     <tr> | 
|---|
| 85 |         <td><tt>TokenizerFunc</tt></td> | 
|---|
| 86 |         <td>The TokenizerFunction used to parse the sequence.</td> | 
|---|
| 87 |     </tr> | 
|---|
| 88 |     <tr> | 
|---|
| 89 |         <td><tt>Iterator</tt></td> | 
|---|
| 90 |         <td>The type of the iterator the specifies the sequence.</td> | 
|---|
| 91 |     </tr> | 
|---|
| 92 |     <tr> | 
|---|
| 93 |         <td><tt>Type</tt></td> | 
|---|
| 94 |         <td>The type of the token, typically string.</td> | 
|---|
| 95 |     </tr> | 
|---|
| 96 | </table> | 
|---|
| 97 |  | 
|---|
| 98 | <h2>Model of</h2> | 
|---|
| 99 |  | 
|---|
| 100 | <p>The category of Iterator, up to and including Forward Iterator. | 
|---|
| 101 | Anything higher will get scaled down to Forward Iterator.</p> | 
|---|
| 102 |  | 
|---|
| 103 | <h2>Related Types</h2> | 
|---|
| 104 |  | 
|---|
| 105 | <table border="1"> | 
|---|
| 106 |     <tr> | 
|---|
| 107 |         <td><p align="center"><strong>Type</strong></p> | 
|---|
| 108 |         </td> | 
|---|
| 109 |         <td><p align="center"><strong>Remarks</strong></p> | 
|---|
| 110 |         </td> | 
|---|
| 111 |     </tr> | 
|---|
| 112 |     <tr> | 
|---|
| 113 |         <td>token_iterator_generator::type</td> | 
|---|
| 114 |         <td>The type of the token iterator.</td> | 
|---|
| 115 |     </tr> | 
|---|
| 116 | </table> | 
|---|
| 117 |  | 
|---|
| 118 | <h2>Creation</h2> | 
|---|
| 119 |  | 
|---|
| 120 | <pre>template<class Type, class Iterator, class TokenizerFunc> | 
|---|
| 121 | typename token_iterator_generator<TokenizerFunc,Iterator,Type>::type  | 
|---|
| 122 | make_token_iterator(Iterator begin, Iterator end,const TokenizerFunc& fun)</pre> | 
|---|
| 123 |  | 
|---|
| 124 | <table border="1"> | 
|---|
| 125 |     <tr> | 
|---|
| 126 |         <td><p align="center"><strong>Parameter</strong></p> | 
|---|
| 127 |         </td> | 
|---|
| 128 |         <td><p align="center"><strong>Description</strong></p> | 
|---|
| 129 |         </td> | 
|---|
| 130 |     </tr> | 
|---|
| 131 |     <tr> | 
|---|
| 132 |         <td>begin</td> | 
|---|
| 133 |         <td>The beginning of the sequence to be parsed.</td> | 
|---|
| 134 |     </tr> | 
|---|
| 135 |     <tr> | 
|---|
| 136 |         <td>end</td> | 
|---|
| 137 |         <td>Past the end of the sequence to be parsed.</td> | 
|---|
| 138 |     </tr> | 
|---|
| 139 |     <tr> | 
|---|
| 140 |         <td>fun</td> | 
|---|
| 141 |         <td>A functor that is a model of TokenizerFunction</td> | 
|---|
| 142 |     </tr> | 
|---|
| 143 | </table> | 
|---|
| 144 |  | 
|---|
| 145 | <p> </p> | 
|---|
| 146 |  | 
|---|
| 147 | <hr> | 
|---|
| 148 |  | 
|---|
| 149 | <p>© Copyright John R. Bandela 2001. Permission to copy, use, | 
|---|
| 150 | modify, sell and distribute this document is granted provided | 
|---|
| 151 | this copyright notice appears in all copies. This document is | 
|---|
| 152 | provided "as is" without express or implied warranty, | 
|---|
| 153 | and with no claim as to its suitability for any purpose.</p> | 
|---|
| 154 | </body> | 
|---|
| 155 | </html> | 
|---|