quickstart.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Quick Start</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <link href="theme/style.css" rel="stylesheet" type="text/css">
  7. </head>
  8. <body text="#000000" background="theme/bkd.gif">
  9. <table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
  10. <tr>
  11. <td width="21"> <h1></h1></td>
  12. <td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Quick
  13. Start </font></b></font></td>
  14. <td width="96"><a href="http://www.boost.org"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
  15. </tr>
  16. </table>
  17. <br>
  18. <table border="0">
  19. <tr>
  20. <td width="10"></td>
  21. <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
  22. <td width="30"><a href="introduction.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
  23. <td width="30"><a href="class_reference_context.html"><img src="theme/r_arr.gif" border="0"></a></td>
  24. </tr>
  25. </table>
  26. <p>Preprocessing with <tt>Wave</tt> is highly configurable. You must
  27. define a few options to control it. Here are a few of the
  28. options you can define:</p>
  29. <BLOCKQUOTE dir="ltr" style="MARGIN-RIGHT: 0px">
  30. <P><STRONG><IMG id="IMG1" height="13" src="theme/bullet.gif" width="13"></STRONG>&nbsp;include
  31. search paths defining where to search for files to be included with
  32. <tt>#include&nbsp;&lt;...&gt;</tt> and <tt>#include&nbsp;"..."</tt> directives<br>
  33. <STRONG><img src="theme/bullet.gif" width="13" height="13">&nbsp;</STRONG>which
  34. macros to predefine and which of the predefined macros to undefine<br>
  35. <STRONG><img src="theme/bullet.gif" width="13" height="13">&nbsp;</STRONG>whether to enable any of several extensions to the C++
  36. Standard (such as for variadics and placemarkers)
  37. </P>
  38. </BLOCKQUOTE>
  39. <p>You can access all these processing parameters through the <tt>boost::wave::context</tt>
  40. object. So you must instantiate one object instance of this type to use the <tt>Wave</tt>
  41. library. (For more information about the context template class, please refer
  42. to the class reference <a href="class_reference_context.html">here</a>.) To instantiate
  43. the <tt>boost::wave::context</tt> object you have to supply at least two template parameters:
  44. the iterator type of the underlying input stream to use and the type of the lexer iterator to be used as the token source for the preprocessing engine.</p>
  45. <P dir="ltr">Do not instantiate the main preprocessing iterators yourself.
  46. Get them from the <tt>boost::wave::context</tt> object instead.
  47. The following code snippet is taken from the <tt>quick_start</tt> sample, which shows a minimal usage scenario for <tt>Wave</tt>. </P>
  48. <pre><span class="comment"> // The following preprocesses a given input file.
  49. // Open the file and read it into a string variable</span>
  50. <span class="keyword">std::ifstream</span> instream(<span class="string">&quot;input.cpp&quot;</span>);
  51. <span class="keyword">std::string </span>input<span class="keyword">(
  52. std::istreambuf_iterator&lt;char&gt;</span>(instream.rdbuf()),
  53. <span class="keyword">std::istreambuf_iterator&lt;char&gt;</span>());
  54. <span class="comment">// The template boost::wave::cpplexer::lex_token&lt;&gt; is the
  55. // token type to be used by the Wave library.
  56. // This token type is one of the central types throughout
  57. // the library, because it is a template parameter to some
  58. // of the public classes and templates and it is returned
  59. // from the iterators.
  60. // The template boost::wave::cpplexer::lex_iterator&lt;&gt; is
  61. // the lexer iterator to use as the token source for the
  62. // preprocessing engine. In this case this is parametrized
  63. // with the token type.</span>
  64. <span class="keyword">typedef</span> <span class="identifier">boost::wave::cpplexer::lex_iterator</span><span class="special">&lt;</span>
  65. <span class="identifier">boost::wave::cpplexer::lex_token</span><span class="special">&lt;&gt; &gt;</span>
  66. <span class="identifier">lex_iterator_type</span><span class="special">;</span>
  67. <span class="keyword">typedef</span> <span class="identifier">boost::wave::context</span><span class="special">&lt;</span>
  68. std::string::iterator<span class="special">,</span> lex_iterator_type<span class="special">&gt;</span>
  69. <span class="identifier">context_type</span><span class="special">;</span>
  70. context_type ctx(input.begin(), input.end(), <span class="string">&quot;input.cpp&quot;</span>);
  71. <span class="comment">
  72. // At this point you may want to set the parameters of the
  73. // preprocessing as include paths and/or predefined macros.
  74. </span> ctx.add_include_path(<span class="literal">&quot;...&quot;</span>);
  75. ctx.add_macro_definition(...);
  76. <span class="comment">
  77. // Get the preprocessor iterators and use them to generate
  78. // the token sequence.
  79. </span> context_type::iterator_type first = ctx.begin();
  80. context_type::iterator_type last = ctx.end();
  81. <span class="comment"> // The input stream is preprocessed for you during iteration<br> // over [first, last)<br></span> <span class="keyword">while</span> (first != last) {
  82. <span class="keyword">std::cout</span> &lt;&lt; (*first).get_value();
  83. ++first;
  84. }
  85. </pre>
  86. <P dir="ltr">The constructor of the <tt>boost::wave::context</tt> object can
  87. take a pair of arbitrary iterator types (at least <tt>input_iterator</tt> type
  88. iterators) to the input stream, which must supply the data to be processed.
  89. The third parameter supplies a filename, which is reported in the preprocessor output to
  90. indicate the current context.
  91. Note though, that this filename is used
  92. only as long as no <tt>#include</tt> or <tt>#line</tt> directives are encountered,
  93. which in turn will alter the current reported filename.</P>
  94. <P dir="ltr">The iteration over the preprocessed tokens is relatively straightforward. Just get the starting and the ending iterators from the context object
  95. (maybe after initializing some include search paths) and you are done! Dereferencing
  96. the iterator will return the preprocessed tokens generated on
  97. the fly from the input stream. (To get further information about the token type,
  98. you may want to look <a href="class_reference_tokentype.html">here</a>.)</P>
  99. <table border="0">
  100. <tr>
  101. <td width="10"></td>
  102. <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
  103. <td width="30"><a href="introduction.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
  104. <td width="30"><a href="class_reference_context.html"><img src="theme/r_arr.gif" border="0"></a></td>
  105. </tr>
  106. </table>
  107. <hr size="1">
  108. <p class="copyright">Copyright &copy; 2003-2011 Hartmut Kaiser<br>
  109. <br>
  110. <font size="2">Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) </font> </p>
  111. <span class="updated"></span>
  112. <p class="copyright"><span class="updated">Last updated:
  113. <!-- #BeginDate format:fcAm1m -->Tuesday, July 29, 2008 20:34<!-- #EndDate -->
  114. </span></p>
  115. </body>
  116. </html>