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