token_iterator.htm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Language" content="en-us">
  5. <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
  6. <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
  7. <meta name="ProgId" content="FrontPage.Editor.Document">
  8. <title>Boost Token Iterator</title>
  9. </head>
  10. <body bgcolor="#FFFFFF" text="#000000" link="#0000EE" vlink="#551A8B" alink=
  11. "#FF0000">
  12. <p><img src="../../../boost.png" alt="C++ Boost" width="277" height=
  13. "86"><br></p>
  14. <h1 align="center">Token Iterator</h1>
  15. <pre>
  16. template &lt;
  17. class TokenizerFunc = char_delimiters_separator&lt;char&gt;,
  18. class Iterator = std::string::const_iterator,
  19. class Type = std::string
  20. &gt;
  21. class token_iterator_generator
  22. </pre>
  23. <pre>
  24. template&lt;class Type, class Iterator, class TokenizerFunc&gt;
  25. typename token_iterator_generator&lt;TokenizerFunc,Iterator,Type&gt;::type
  26. make_token_iterator(Iterator begin, Iterator end,const TokenizerFunc&amp; fun)
  27. </pre>
  28. <p>The token iterator serves to provide an iterator view of the tokens in a
  29. parsed sequence.</p>
  30. <h2>Example</h2>
  31. <pre>
  32. /// simple_example_5.cpp
  33. #include&lt;iostream&gt;
  34. #include&lt;boost/token_iterator.hpp&gt;
  35. #include&lt;string&gt;
  36. int main(){
  37. using namespace std;
  38. using namespace boost;
  39. string s = "12252001";
  40. int offsets[] = {2,2,4};
  41. offset_separator f(offsets, offsets+3);
  42. typedef token_iterator_generator&lt;offset_separator&gt;::type Iter;
  43. Iter beg = make_token_iterator&lt;string&gt;(s.begin(),s.end(),f);
  44. Iter end = make_token_iterator&lt;string&gt;(s.end(),s.end(),f);
  45. // The above statement could also have been what is below
  46. // Iter end;
  47. for(;beg!=end;++beg){
  48. cout &lt;&lt; *beg &lt;&lt; "\n";
  49. }
  50. }
  51. </pre>
  52. <p>&nbsp;</p>
  53. <h3>Template Parameters</h3>
  54. <table border="1" summary="">
  55. <tr>
  56. <th>Parameter</th>
  57. <th>Description</th>
  58. </tr>
  59. <tr>
  60. <td><tt>TokenizerFunc</tt></td>
  61. <td>The TokenizerFunction used to parse the sequence.</td>
  62. </tr>
  63. <tr>
  64. <td><tt>Iterator</tt></td>
  65. <td>The type of the iterator the specifies the sequence.</td>
  66. </tr>
  67. <tr>
  68. <td><tt>Type</tt></td>
  69. <td>The type of the token, typically string.</td>
  70. </tr>
  71. </table>
  72. <h2>Model of</h2>
  73. <p>The category of Iterator, up to and including Forward Iterator. Anything
  74. higher will get scaled down to Forward Iterator.</p>
  75. <h2>Related Types</h2>
  76. <table border="1" summary="">
  77. <tr>
  78. <td>
  79. <p align="center"><strong>Type</strong></p>
  80. </td>
  81. <td>
  82. <p align="center"><strong>Remarks</strong></p>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td>token_iterator_generator::type</td>
  87. <td>The type of the token iterator.</td>
  88. </tr>
  89. </table>
  90. <h2>Creation</h2>
  91. <pre>
  92. template&lt;class Type, class Iterator, class TokenizerFunc&gt;
  93. typename token_iterator_generator&lt;TokenizerFunc,Iterator,Type&gt;::type
  94. make_token_iterator(Iterator begin, Iterator end,const TokenizerFunc&amp; fun)
  95. </pre>
  96. <table border="1" summary="">
  97. <tr>
  98. <td>
  99. <p align="center"><strong>Parameter</strong></p>
  100. </td>
  101. <td>
  102. <p align="center"><strong>Description</strong></p>
  103. </td>
  104. </tr>
  105. <tr>
  106. <td>begin</td>
  107. <td>The beginning of the sequence to be parsed.</td>
  108. </tr>
  109. <tr>
  110. <td>end</td>
  111. <td>Past the end of the sequence to be parsed.</td>
  112. </tr>
  113. <tr>
  114. <td>fun</td>
  115. <td>A functor that is a model of TokenizerFunction</td>
  116. </tr>
  117. </table>
  118. <p>&nbsp;</p>
  119. <hr>
  120. <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
  121. "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
  122. height="31" width="88"></a></p>
  123. <p>Revised
  124. <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->25
  125. December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38518" --></p>
  126. <p><i>Copyright &copy; 2001 John R. Bandela</i></p>
  127. <p><i>Distributed under the Boost Software License, Version 1.0. (See
  128. accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  129. copy at <a href=
  130. "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
  131. </body>
  132. </html>