Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/wave/doc/class_reference_inptpolcy.html @ 69

Last change on this file since 69 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 7.0 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3<head>
4<title>The Input Policy</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>
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">The
14      Input Policy</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="class_reference_context.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
24    <td width="30"><a href="class_reference_ctxpolicy.html"><img src="theme/r_arr.gif" border="0"></a></td>
25  </tr>
26</table>
27
28<blockquote> 
29  <p><a href="class_reference_inptpolcy.html#introduction">Introduction</a><br>
30    <a href="class_reference_inptpolcy.html#header_synopsis">Header 'wave/cpp_iteration_context.hpp'
31    synopsis</a><br>
32    <a href="class_reference_inptpolcy.html#template_parameters">Template parameters</a><br>
33    <a href="class_reference_inptpolcy.html#member_functions">Member functions</a></p>
34</blockquote>
35<h2><b><a name="introduction"></a>Introduction</b></h2>
36<p>The input policy type may be specified as a template parameter to the <tt>wave::context</tt> 
37  object and is used for customizing the way, how an included file is to be represented
38  by a pair of iterators pointing to the beginning and the end of the resulting
39  input sequence. If this template parameter is not given while instantiating
40  the context object, it defaults to the <tt>iteration_context_policies::load_file_to_string</tt> 
41  type. </p>
42<h2><b><a name="header_synopsis"></a>Header <a href="http://cvs.sourceforge.net/viewcvs.py/boost/boost/boost/wave/util/iteration_context.hpp?view=markup">wave/iteration_context.hpp</a> 
43  synopsis</b></h2>
44<p>The following code listing does not show the required interface only, but for
45  brevity reasons the whole implementation of an input policy, which loads the
46  given file into a string variable and exposes the begin() and end() iterators
47  of this string to the <tt>Wave</tt> library.</p>
48<pre><span class="keyword">namespace</span> boost {
49<span class="keyword">namespace</span> wave {
50<span class="keyword">namespace</span> iteration_context_policies {
51
52    <span class="keyword">struct</span> load_file_to_string {
53   
54        <span class="keyword">template</span> &lt;<span class="keyword">typename</span> IterContext&gt;
55        <span class="keyword">class</span> inner {
56       
57        <span class="keyword">public</span>:
58            <span class="comment">// expose the begin and end iterators for the</span>
59            <span class="comment">// included file</span>
60            <span class="keyword">template</span> &lt;typename Position&gt;
61            <span class="keyword">static</span> 
62            <span class="keyword">void</span> <a href="class_reference_inptpolcy.html#init_iterators">init_iterators</a>(IterContext&iter_ctx,
63                Position const &act_pos)
64            {
65                <span class="keyword">typedef typename</span> IterContext::iterator_type iterator_type;
66               
67                <span class="keyword">std::ifstream</span> instream(iter_ctx.filename.c_str());
68                if (!instream.is_open()) {
69                    CPP_THROW(preprocess_exception, bad_include_file,
70                        iter_ctx.filename, act_pos);
71                }
72               
73                iter_ctx.instring = <span class="keyword">std::string</span>(
74                    <span class="keyword">std::istreambuf_iterator</span><char>(instream.rdbuf()),
75                    <span class="keyword">std::istreambuf_iterator</span><char>());
76
77                iter_ctx.first = iterator_type(iter_ctx.instring.begin(),
78                    iter_ctx.instring.end(),
79                    PositionT(iter_ctx.filename));
80                iter_ctx.last = iterator_type();
81            }
82
83        <span class="keyword">private</span>:
84            <span class="keyword">std::string</span> instring;
85        };
86    };
87
88}   <span class="comment">// namespace iteration_context_policies</span>
89}   <span class="comment">// namespace wave </span>
90}   <span class="comment">// namespace boost </span>  </pre>
91<p>As you can see, an <tt>input_policy</tt> for the <tt>wave::context</tt> object
92  should implement one function only, the init_iterators function. The policy
93  shown is implemented with the help of an embedded class to avoid the need for
94  template template parameters, which aren't implemented by all systems today.
95  This embedded class should have the name <tt>inner</tt>.</p>
96<h3><a name="template_parameters"></a>Template Parameters</h3>
97<p>The <tt>inner</tt> class is instantiated with one template parameter, the iteration
98  context type, from which the policy is a part of. The iterator type <tt>iterator_type</tt> 
99  which is used to access the underlying input stream has to be derived through
100  a typedef as shown. The iterator pair to initialize (which is accessible as
101  <tt>iter_ctx.first</tt> and <tt>iter_ctx.last</tt>) has to initialized from
102  an abritrary iterator type, representing the actual input stream.</p>
103<h3><a name="member_functions"></a>Member Functions</h3>
104<p><a name="init_iterators"></a><b>init_iterators</b></p>
105<pre>    <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Position&gt;
106    <span class="keyword">static void</span> init_iterators(
107        IterContext iter_ctx,
108        Position const &act_pos);</pre>
109
110    <p>directive was found in the input token stream. The main rationale for this
111    function is to initialize the pair of iterators <tt>iter_ctx.first</tt> and
112    <tt>iter_ctx.last</tt>, which are to be used to access the input stream corresponding
113  to the include file to be inserted from inside the preprocessing engine.</p>
114</blockquote>
115<table border="0">
116  <tr> 
117    <td width="10"></td>
118    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
119    <td width="30"><a href="class_reference_context.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
120    <td width="30"><a href="class_reference_ctxpolicy.html"><img src="theme/r_arr.gif" border="0"></a></td>
121  </tr>
122</table>
123<hr size="1">
124<p class="copyright">Copyright &copy; 2003-2007 Hartmut Kaiser<br>
125  <br>
126  <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>
127<span class="updated"></span>
128<p class="copyright"><span class="updated">Last updated:
129  <!-- #BeginDate format:fcAm1m -->Sunday, May 15, 2005  12:23<!-- #EndDate -->
130  </span></p>
131</body>
132</html>
Note: See TracBrowser for help on using the repository browser.