<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <title>ICU 52.1: bytestream.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">ICU 52.1  <span id="projectnumber">52.1</span> </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.1.2 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="dir_bdd9a5d540de89e9fe90efdfc6973a4f.html">common</a></li><li class="navelem"><a class="el" href="dir_f59c6450ff718ff1b085cfd1c36acbd7.html">unicode</a></li> </ul> </div> </div><!-- top --> <div class="header"> <div class="headertitle"> <div class="title">bytestream.h</div> </div> </div><!--header--> <div class="contents"> <a href="bytestream_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">// Copyright (C) 2009-2012, International Business Machines</span></div> <div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment">// Corporation and others. All Rights Reserved.</span></div> <div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment">//</span></div> <div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">// Copyright 2007 Google Inc. All Rights Reserved.</span></div> <div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment">// Author: sanjay@google.com (Sanjay Ghemawat)</span></div> <div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment">//</span></div> <div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment">// Abstract interface that consumes a sequence of bytes (ByteSink).</span></div> <div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">//</span></div> <div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">// Used so that we can write a single piece of code that can operate</span></div> <div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">// on a variety of output string types.</span></div> <div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">//</span></div> <div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">// Various implementations of this interface are provided:</span></div> <div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment">// ByteSink:</span></div> <div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment">// CheckedArrayByteSink Write to a flat array, with bounds checking</span></div> <div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment">// StringByteSink Write to an STL string</span></div> <div class="line"><a name="l00016"></a><span class="lineno"> 16</span> </div> <div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment">// This code is a contribution of Google code, and the style used here is</span></div> <div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment">// a compromise between the original Google code and the ICU coding guidelines.</span></div> <div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment">// For example, data types are ICU-ified (size_t,int->int32_t),</span></div> <div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="comment">// and API comments doxygen-ified, but function names and behavior are</span></div> <div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment">// as in the original, if possible.</span></div> <div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="comment">// Assertion-style error handling, not available in ICU, was changed to</span></div> <div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="comment">// parameter "pinning" similar to UnicodeString.</span></div> <div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="comment">//</span></div> <div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="comment">// In addition, this is only a partial port of the original Google code,</span></div> <div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="comment">// limited to what was needed so far. The (nearly) complete original code</span></div> <div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="comment">// is in the ICU svn repository at icuhtml/trunk/design/strings/contrib</span></div> <div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="comment">// (see ICU ticket 6765, r25517).</span></div> <div class="line"><a name="l00029"></a><span class="lineno"> 29</span> </div> <div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="preprocessor">#ifndef __BYTESTREAM_H__</span></div> <div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="preprocessor"></span><span class="preprocessor">#define __BYTESTREAM_H__</span></div> <div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="preprocessor"></span></div> <div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="preprocessor">#include "<a class="code" href="utypes_8h.html" title="Basic definitions for ICU, for both C and C++ APIs.">unicode/utypes.h</a>"</span></div> <div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="preprocessor">#include "<a class="code" href="uobject_8h.html" title="C++ API: Common ICU base class UObject.">unicode/uobject.h</a>"</span></div> <div class="line"><a name="l00040"></a><span class="lineno"> 40</span> <span class="preprocessor">#include "<a class="code" href="std__string_8h.html" title="C++ API: Central ICU header for including the C++ standard <string> header and for related definition...">unicode/std_string.h</a>"</span></div> <div class="line"><a name="l00041"></a><span class="lineno"> 41</span> </div> <div class="line"><a name="l00042"></a><span class="lineno"> 42</span> <a class="code" href="uversion_8h.html#a7d9374e037299886d4192b763b4c5e8b" title="This is used to begin a declaration of a public ICU C++ API.">U_NAMESPACE_BEGIN</a></div> <div class="line"><a name="l00043"></a><span class="lineno"> 43</span> </div> <div class="line"><a name="l00048"></a><span class="lineno"><a class="code" href="classicu_1_1ByteSink.html"> 48</a></span> <span class="keyword">class </span><a class="code" href="utypes_8h.html#a559955ec3bc692657c5d8b1c6de8e334" title="Set to export library symbols from inside the common library, and to import them from outside...">U_COMMON_API</a> <a class="code" href="classicu_1_1ByteSink.html" title="A ByteSink can be filled with bytes.">ByteSink</a> : <span class="keyword">public</span> <a class="code" href="classicu_1_1UMemory.html" title="UMemory is the common ICU base class.">UMemory</a> {</div> <div class="line"><a name="l00049"></a><span class="lineno"> 49</span> <span class="keyword">public</span>:</div> <div class="line"><a name="l00054"></a><span class="lineno"><a class="code" href="classicu_1_1ByteSink.html#ac3e9a257c1fd9e981bceb8f6981d9b6e"> 54</a></span>  <a class="code" href="classicu_1_1ByteSink.html#ac3e9a257c1fd9e981bceb8f6981d9b6e" title="Default constructor.">ByteSink</a>() { }</div> <div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  <span class="keyword">virtual</span> ~<a class="code" href="classicu_1_1ByteSink.html" title="A ByteSink can be filled with bytes.">ByteSink</a>();</div> <div class="line"><a name="l00060"></a><span class="lineno"> 60</span> </div> <div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Append(<span class="keyword">const</span> <span class="keywordtype">char</span>* bytes, int32_t n) = 0;</div> <div class="line"><a name="l00068"></a><span class="lineno"> 68</span> </div> <div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  <span class="keyword">virtual</span> <span class="keywordtype">char</span>* GetAppendBuffer(int32_t min_capacity,</div> <div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  int32_t desired_capacity_hint,</div> <div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  <span class="keywordtype">char</span>* scratch, int32_t scratch_capacity,</div> <div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  int32_t* result_capacity);</div> <div class="line"><a name="l00115"></a><span class="lineno"> 115</span> </div> <div class="line"><a name="l00124"></a><span class="lineno"> 124</span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Flush();</div> <div class="line"><a name="l00125"></a><span class="lineno"> 125</span> </div> <div class="line"><a name="l00126"></a><span class="lineno"> 126</span> <span class="keyword">private</span>:</div> <div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  <a class="code" href="classicu_1_1ByteSink.html" title="A ByteSink can be filled with bytes.">ByteSink</a>(<span class="keyword">const</span> <a class="code" href="classicu_1_1ByteSink.html" title="A ByteSink can be filled with bytes.">ByteSink</a> &); <span class="comment">// copy constructor not implemented</span></div> <div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  <a class="code" href="classicu_1_1ByteSink.html" title="A ByteSink can be filled with bytes.">ByteSink</a> &operator=(<span class="keyword">const</span> <a class="code" href="classicu_1_1ByteSink.html" title="A ByteSink can be filled with bytes.">ByteSink</a> &); <span class="comment">// assignment operator not implemented</span></div> <div class="line"><a name="l00129"></a><span class="lineno"> 129</span> };</div> <div class="line"><a name="l00130"></a><span class="lineno"> 130</span> </div> <div class="line"><a name="l00131"></a><span class="lineno"> 131</span> <span class="comment">// -------------------------------------------------------------</span></div> <div class="line"><a name="l00132"></a><span class="lineno"> 132</span> <span class="comment">// Some standard implementations</span></div> <div class="line"><a name="l00133"></a><span class="lineno"> 133</span> </div> <div class="line"><a name="l00143"></a><span class="lineno"><a class="code" href="classicu_1_1CheckedArrayByteSink.html"> 143</a></span> <span class="keyword">class </span><a class="code" href="utypes_8h.html#a559955ec3bc692657c5d8b1c6de8e334" title="Set to export library symbols from inside the common library, and to import them from outside...">U_COMMON_API</a> <a class="code" href="classicu_1_1CheckedArrayByteSink.html" title="Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not...">CheckedArrayByteSink</a> : <span class="keyword">public</span> <a class="code" href="classicu_1_1ByteSink.html" title="A ByteSink can be filled with bytes.">ByteSink</a> {</div> <div class="line"><a name="l00144"></a><span class="lineno"> 144</span> <span class="keyword">public</span>:</div> <div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  <a class="code" href="classicu_1_1CheckedArrayByteSink.html" title="Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not...">CheckedArrayByteSink</a>(<span class="keywordtype">char</span>* outbuf, int32_t capacity);</div> <div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  <span class="keyword">virtual</span> ~<a class="code" href="classicu_1_1CheckedArrayByteSink.html" title="Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not...">CheckedArrayByteSink</a>();</div> <div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  <span class="keyword">virtual</span> <a class="code" href="classicu_1_1CheckedArrayByteSink.html" title="Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not...">CheckedArrayByteSink</a>& Reset();</div> <div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classicu_1_1ByteSink.html#a61fe994281322e8a3e3ed2e50c910e41" title="Append "bytes[0,n-1]" to this.">Append</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* bytes, int32_t n);</div> <div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  <span class="keyword">virtual</span> <span class="keywordtype">char</span>* <a class="code" href="classicu_1_1ByteSink.html#a391838e3698a0132097ff2877565aaee" title="Returns a writable buffer for appending and writes the buffer's capacity to *result_capacity.">GetAppendBuffer</a>(int32_t min_capacity,</div> <div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  int32_t desired_capacity_hint,</div> <div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  <span class="keywordtype">char</span>* scratch, int32_t scratch_capacity,</div> <div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  int32_t* result_capacity);</div> <div class="line"><a name="l00196"></a><span class="lineno"><a class="code" href="classicu_1_1CheckedArrayByteSink.html#a855275c60617b7c4732a12058e490331"> 196</a></span>  int32_t <a class="code" href="classicu_1_1CheckedArrayByteSink.html#a855275c60617b7c4732a12058e490331" title="Returns the number of bytes actually written to the sink.">NumberOfBytesWritten</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> size_; }</div> <div class="line"><a name="l00203"></a><span class="lineno"><a class="code" href="classicu_1_1CheckedArrayByteSink.html#ad14f1783aa30e2cea50ce063d26f37af"> 203</a></span>  <a class="code" href="umachine_8h.html#a349ef00011f20ccd1d3b424445681aa5" title="The ICU boolean type.">UBool</a> <a class="code" href="classicu_1_1CheckedArrayByteSink.html#ad14f1783aa30e2cea50ce063d26f37af" title="Returns true if any bytes were discarded, i.e., if there was an attempt to write more than 'capacity'...">Overflowed</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> overflowed_; }</div> <div class="line"><a name="l00211"></a><span class="lineno"><a class="code" href="classicu_1_1CheckedArrayByteSink.html#a3e70bb360869780ab3252b45ff1ea4d3"> 211</a></span>  int32_t <a class="code" href="classicu_1_1CheckedArrayByteSink.html#a3e70bb360869780ab3252b45ff1ea4d3" title="Returns the number of bytes appended to the sink.">NumberOfBytesAppended</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> appended_; }</div> <div class="line"><a name="l00212"></a><span class="lineno"> 212</span> <span class="keyword">private</span>:</div> <div class="line"><a name="l00213"></a><span class="lineno"> 213</span>  <span class="keywordtype">char</span>* outbuf_;</div> <div class="line"><a name="l00214"></a><span class="lineno"> 214</span>  <span class="keyword">const</span> int32_t capacity_;</div> <div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  int32_t size_;</div> <div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  int32_t appended_;</div> <div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  <a class="code" href="umachine_8h.html#a349ef00011f20ccd1d3b424445681aa5" title="The ICU boolean type.">UBool</a> overflowed_;</div> <div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  <a class="code" href="classicu_1_1CheckedArrayByteSink.html" title="Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not...">CheckedArrayByteSink</a>(); </div> <div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  <a class="code" href="classicu_1_1CheckedArrayByteSink.html" title="Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not...">CheckedArrayByteSink</a>(<span class="keyword">const</span> <a class="code" href="classicu_1_1CheckedArrayByteSink.html" title="Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not...">CheckedArrayByteSink</a> &); </div> <div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  <a class="code" href="classicu_1_1CheckedArrayByteSink.html" title="Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not...">CheckedArrayByteSink</a> &operator=(<span class="keyword">const</span> <a class="code" href="classicu_1_1CheckedArrayByteSink.html" title="Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not...">CheckedArrayByteSink</a> &); </div> <div class="line"><a name="l00221"></a><span class="lineno"> 221</span> };</div> <div class="line"><a name="l00222"></a><span class="lineno"> 222</span> </div> <div class="line"><a name="l00223"></a><span class="lineno"> 223</span> <span class="preprocessor">#if U_HAVE_STD_STRING</span></div> <div class="line"><a name="l00224"></a><span class="lineno"> 224</span> <span class="preprocessor"></span></div> <div class="line"><a name="l00230"></a><span class="lineno"> 230</span> <span class="keyword">template</span><<span class="keyword">typename</span> StringClass></div> <div class="line"><a name="l00231"></a><span class="lineno"><a class="code" href="classicu_1_1StringByteSink.html"> 231</a></span> <span class="keyword">class </span><a class="code" href="classicu_1_1StringByteSink.html" title="Implementation of ByteSink that writes to a "string".">StringByteSink</a> : <span class="keyword">public</span> <a class="code" href="classicu_1_1ByteSink.html" title="A ByteSink can be filled with bytes.">ByteSink</a> {</div> <div class="line"><a name="l00232"></a><span class="lineno"> 232</span>  <span class="keyword">public</span>:</div> <div class="line"><a name="l00238"></a><span class="lineno"><a class="code" href="classicu_1_1StringByteSink.html#acf5001ee1201ba4821defafcc409250d"> 238</a></span>  <a class="code" href="classicu_1_1StringByteSink.html#acf5001ee1201ba4821defafcc409250d" title="Constructs a ByteSink that will append bytes to the dest string.">StringByteSink</a>(StringClass* dest) : dest_(dest) { }</div> <div class="line"><a name="l00245"></a><span class="lineno"><a class="code" href="classicu_1_1StringByteSink.html#a966cbe182b8f5f14682580adbb9f66f9"> 245</a></span>  <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classicu_1_1StringByteSink.html#a966cbe182b8f5f14682580adbb9f66f9" title="Append "bytes[0,n-1]" to this.">Append</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* data, int32_t n) { dest_->append(data, n); }</div> <div class="line"><a name="l00246"></a><span class="lineno"> 246</span>  <span class="keyword">private</span>:</div> <div class="line"><a name="l00247"></a><span class="lineno"> 247</span>  StringClass* dest_;</div> <div class="line"><a name="l00248"></a><span class="lineno"> 248</span>  <a class="code" href="classicu_1_1StringByteSink.html" title="Implementation of ByteSink that writes to a "string".">StringByteSink</a>(); </div> <div class="line"><a name="l00249"></a><span class="lineno"> 249</span>  <a class="code" href="classicu_1_1StringByteSink.html" title="Implementation of ByteSink that writes to a "string".">StringByteSink</a>(<span class="keyword">const</span> <a class="code" href="classicu_1_1StringByteSink.html" title="Implementation of ByteSink that writes to a "string".">StringByteSink</a> &); </div> <div class="line"><a name="l00250"></a><span class="lineno"> 250</span>  <a class="code" href="classicu_1_1StringByteSink.html" title="Implementation of ByteSink that writes to a "string".">StringByteSink</a> &operator=(<span class="keyword">const</span> <a class="code" href="classicu_1_1StringByteSink.html" title="Implementation of ByteSink that writes to a "string".">StringByteSink</a> &); </div> <div class="line"><a name="l00251"></a><span class="lineno"> 251</span> };</div> <div class="line"><a name="l00252"></a><span class="lineno"> 252</span> </div> <div class="line"><a name="l00253"></a><span class="lineno"> 253</span> <span class="preprocessor">#endif</span></div> <div class="line"><a name="l00254"></a><span class="lineno"> 254</span> <span class="preprocessor"></span></div> <div class="line"><a name="l00255"></a><span class="lineno"> 255</span> <a class="code" href="uversion_8h.html#a3da1f00f3b02976ac53c014a3e4c0933" title="This is used to end a declaration of a public ICU C++ API.">U_NAMESPACE_END</a></div> <div class="line"><a name="l00256"></a><span class="lineno"> 256</span> </div> <div class="line"><a name="l00257"></a><span class="lineno"> 257</span> <span class="preprocessor">#endif // __BYTESTREAM_H__</span></div> </div><!-- fragment --></div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated on Fri Oct 4 2013 14:10:21 for ICU 52.1 by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.1.2 </small></address> </body> </html>