<!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"/> <meta name="generator" content="Doxygen 1.8.14"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>tesseract: ccutil/unicity_table.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="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript" src="navtreedata.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ $(document).ready(initResizable); /* @license-end */</script> <link href="search/search.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="search/searchdata.js"></script> <script type="text/javascript" src="search/search.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 id="projectalign" style="padding-left: 0.5em;"> <div id="projectname">tesseract  <span id="projectnumber">3.05.02</span> </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.14 --> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ var searchBox = new SearchBox("searchBox", "search",false,'Search'); /* @license-end */ </script> <script type="text/javascript" src="menudata.js"></script> <script type="text/javascript" src="menu.js"></script> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ $(function() { initMenu('',true,false,'search.php','Search'); $(document).ready(function() { init_search(); }); }); /* @license-end */</script> <div id="main-nav"></div> </div><!-- top --> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> <div id="nav-sync" class="sync"></div> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ $(document).ready(function(){initNavTree('a00629_source.html','');}); /* @license-end */ </script> <div id="doc-content"> <!-- window showing the filter options --> <div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)"> </div> <!-- iframe showing the search results (closed by default) --> <div id="MSearchResultsWindow"> <iframe src="javascript:void(0)" frameborder="0" name="MSearchResults" id="MSearchResults"> </iframe> </div> <div class="header"> <div class="headertitle"> <div class="title">unicity_table.h</div> </div> </div><!--header--> <div class="contents"> <a href="a00629.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">// File: UnicityTable.h</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment">// Description: a class to uniquify objects, manipulating them using integers</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">// ids.</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment">// Author: Samuel Charron</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">// (C) Copyright 2006, Google Inc.</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">// you may not use this file except in compliance with the License.</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">// You may obtain a copy of the License at</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">// http://www.apache.org/licenses/LICENSE-2.0</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">// Unless required by applicable law or agreed to in writing, software</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment">// See the License for the specific language governing permissions and</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment">// limitations under the License.</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment">//</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment"></span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="preprocessor">#ifndef TESSERACT_CCUTIL_UNICITY_TABLE_H_</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="preprocessor">#define TESSERACT_CCUTIL_UNICITY_TABLE_H_</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> </div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#include "<a class="code" href="a00596.html">tesscallback.h</a>"</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#include "<a class="code" href="a00500.html">errcode.h</a>"</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="preprocessor">#include "<a class="code" href="a00509.html">genericvector.h</a>"</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> </div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="comment">// A class to uniquify objects, manipulating them using integers ids.</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="comment">// T requirements:</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="comment">// operator= to add an element</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="comment">// default-constructible: allocating the internal table will call the default</span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="comment">// constructor.</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="keyword">class </span><a class="code" href="a02545.html">UnicityTable</a> {</div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>  <a class="code" href="a02545.html#ad2cf3104bf7e0b115d3709359e57cc72">UnicityTable</a>();</div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  <a class="code" href="a02545.html#a98181de03a916ae28b9443a8821e90a5">~UnicityTable</a>();</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> </div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  <span class="keywordtype">void</span> <a class="code" href="a02545.html#aed48975fff77cc08f4724edd62e52b2e">reserve</a>(<span class="keywordtype">int</span> <a class="code" href="a02545.html#a8d4d5b0dbaeccb8f4be89777615a0a61">size</a>);</div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span> </div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  <span class="keywordtype">int</span> <a class="code" href="a02545.html#a8d4d5b0dbaeccb8f4be89777615a0a61">size</a>() <span class="keyword">const</span>;</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> </div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  <span class="keyword">const</span> T &<span class="keyword">get</span>(<span class="keywordtype">int</span> id) <span class="keyword">const</span>;</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span> </div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  <span class="comment">// Return the pointer to an object with the given id.</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  T *<a class="code" href="a02545.html#a6913a3f4f880861e0eca6c606e47646a">get_mutable</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>);</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span> </div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  <span class="keywordtype">int</span> <a class="code" href="a02545.html#a2bba97bdd1934b28deddcc5a1e87ac16">get_id</a>(T <span class="keywordtype">object</span>) <span class="keyword">const</span>;</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span> </div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  <span class="keywordtype">bool</span> <a class="code" href="a02545.html#ae527db7e6f995f3091ccba8d76658578">contains</a>(T <span class="keywordtype">object</span>) <span class="keyword">const</span>;</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span> </div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  T <a class="code" href="a02545.html#a4693858a68107fa77697d8ba994c9999">contains_id</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) <span class="keyword">const</span>;</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span> </div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  <span class="keywordtype">int</span> <a class="code" href="a02545.html#a659534293ab0e46a46cab4421bebfb8f">push_back</a>(T <span class="keywordtype">object</span>);</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span> </div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <span class="keywordtype">void</span> <a class="code" href="a02545.html#accc4dcfc4923d6ec2cb0f19c9f21ecfb">set_clear_callback</a>(<a class="code" href="a03129.html">TessCallback1<T></a>* cb);</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span> </div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  <span class="keywordtype">void</span> <a class="code" href="a02545.html#a64dcf9cac43cae1545a46c20e58156f9">set_compare_callback</a>(<a class="code" href="a03141.html">TessResultCallback2<bool, T const &, T const &></a>* cb);</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span> </div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="keywordtype">void</span> <a class="code" href="a02545.html#a43dd3813d75e38232c26e5532b9a096f">clear</a>();</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span> </div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  <span class="keywordtype">void</span> <a class="code" href="a02545.html#a18c8fc9ccbd7c0befdae1ab65bafdb12">move</a>(<a class="code" href="a02545.html">UnicityTable<T></a>* from);</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span> </div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  <span class="keywordtype">bool</span> <a class="code" href="a02545.html#a9609758121c324bf31c510cd4cb7514b">write</a>(FILE* f, <a class="code" href="a03141.html">TessResultCallback2<bool, FILE*, T const &></a>* cb) <span class="keyword">const</span>;</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  <span class="keywordtype">bool</span> <a class="code" href="a02545.html#a31e2edb3f92024b211332a850723d237">read</a>(FILE* f, <a class="code" href="a03149.html">TessResultCallback3<bool, FILE*, T*, bool></a>* cb, <span class="keywordtype">bool</span> swap);</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span> </div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <span class="keyword">private</span>:</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  <a class="code" href="a02297.html">GenericVector<T></a> table_;</div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <span class="comment">// Mutable because Run method is not const</span></div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  <span class="keyword">mutable</span> <a class="code" href="a03141.html">TessResultCallback2<bool, T const &, T const &></a>* compare_cb_;</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span> };</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span> </div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00099"></a><span class="lineno"><a class="line" href="a04053.html"> 99</a></span> <span class="keyword">class </span><a class="code" href="a04053.html">UnicityTableEqEq</a> : <span class="keyword">public</span> <a class="code" href="a02545.html">UnicityTable</a><T> {</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <span class="keyword">public</span>:</div><div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="a04053.html#a0defa61aea3b236c9661185aedd558aa"> 101</a></span>  <a class="code" href="a04053.html#a0defa61aea3b236c9661185aedd558aa">UnicityTableEqEq</a>() {</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  <a class="code" href="a02545.html#a64dcf9cac43cae1545a46c20e58156f9">UnicityTable<T>::set_compare_callback</a>(</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <a class="code" href="a00596.html#ad000c6729bae0f97075ca10a0b5bf7d6">NewPermanentTessCallback</a>(tesseract::cmp_eq<T>));</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  }</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span> };</div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span> </div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00108"></a><span class="lineno"><a class="line" href="a02545.html#ad2cf3104bf7e0b115d3709359e57cc72"> 108</a></span> <a class="code" href="a02545.html#ad2cf3104bf7e0b115d3709359e57cc72">UnicityTable<T>::UnicityTable</a>() :</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  compare_cb_(0) {</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span> }</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span> </div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span> </div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00114"></a><span class="lineno"><a class="line" href="a02545.html#a98181de03a916ae28b9443a8821e90a5"> 114</a></span> <a class="code" href="a02545.html#a98181de03a916ae28b9443a8821e90a5">UnicityTable<T>::~UnicityTable</a>() {</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  clear();</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span> }</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span> </div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00119"></a><span class="lineno"><a class="line" href="a02545.html#a8d4d5b0dbaeccb8f4be89777615a0a61"> 119</a></span> <span class="keywordtype">int</span> <a class="code" href="a02545.html#a8d4d5b0dbaeccb8f4be89777615a0a61">UnicityTable<T>::size</a>()<span class="keyword"> const</span>{</div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  <span class="keywordflow">return</span> table_.size();</div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span> }</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span> </div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span> <span class="comment">// Reserve some memory. If there is size or more elements, the table will</span></div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span> <span class="comment">// then allocate size * 2 elements.</span></div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00126"></a><span class="lineno"><a class="line" href="a02545.html#aed48975fff77cc08f4724edd62e52b2e"> 126</a></span> <span class="keywordtype">void</span> <a class="code" href="a02545.html#aed48975fff77cc08f4724edd62e52b2e">UnicityTable<T>::reserve</a>(<span class="keywordtype">int</span> size) {</div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  table_.reserve(size);</div><div class="line"><a name="l00128"></a><span class="lineno"> 128</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> <span class="comment">// Return the object from an id.</span></div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00132"></a><span class="lineno"><a class="line" href="a02545.html#abe542edc2a5eec07dcaf171c6a52455d"> 132</a></span> <span class="keyword">const</span> T &<a class="code" href="a02545.html#abe542edc2a5eec07dcaf171c6a52455d">UnicityTable<T>::get</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>)<span class="keyword"> const </span>{</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  <span class="keywordflow">return</span> table_.get(<span class="keywordtype">id</span>);</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span> }</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span> <span class="comment">// Returns the pointer to the object with the given id.</span></div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00137"></a><span class="lineno"><a class="line" href="a02545.html#a6913a3f4f880861e0eca6c606e47646a"> 137</a></span> T *<a class="code" href="a02545.html#a6913a3f4f880861e0eca6c606e47646a">UnicityTable<T>::get_mutable</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) {</div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  <span class="keywordflow">return</span> &(table_.get(<span class="keywordtype">id</span>));</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span> }</div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span> <span class="comment">// Return true if the id is valid</span></div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00142"></a><span class="lineno"><a class="line" href="a02545.html#a4693858a68107fa77697d8ba994c9999"> 142</a></span> T <a class="code" href="a02545.html#a4693858a68107fa77697d8ba994c9999">UnicityTable<T>::contains_id</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>)<span class="keyword"> const </span>{</div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  <span class="keywordflow">return</span> table_.contains_index(<span class="keywordtype">id</span>);</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span> }</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span> </div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span> <span class="comment">// Return the id of the T object.</span></div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00148"></a><span class="lineno"><a class="line" href="a02545.html#a2bba97bdd1934b28deddcc5a1e87ac16"> 148</a></span> <span class="keywordtype">int</span> <a class="code" href="a02545.html#a2bba97bdd1934b28deddcc5a1e87ac16">UnicityTable<T>::get_id</a>(T <span class="keywordtype">object</span>)<span class="keyword"> const </span>{</div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <span class="keywordflow">return</span> table_.get_index(<span class="keywordtype">object</span>);</div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span> }</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span> </div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span> <span class="comment">// Return true if T is in the table</span></div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00154"></a><span class="lineno"><a class="line" href="a02545.html#ae527db7e6f995f3091ccba8d76658578"> 154</a></span> <span class="keywordtype">bool</span> <a class="code" href="a02545.html#ae527db7e6f995f3091ccba8d76658578">UnicityTable<T>::contains</a>(T <span class="keywordtype">object</span>)<span class="keyword"> const </span>{</div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  <span class="keywordflow">return</span> get_id(<span class="keywordtype">object</span>) != -1;</div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span> }</div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span> </div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span> <span class="comment">// Add an element in the table</span></div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00160"></a><span class="lineno"><a class="line" href="a02545.html#a659534293ab0e46a46cab4421bebfb8f"> 160</a></span> <span class="keywordtype">int</span> <a class="code" href="a02545.html#a659534293ab0e46a46cab4421bebfb8f">UnicityTable<T>::push_back</a>(T <span class="keywordtype">object</span>) {</div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  <span class="keywordtype">int</span> idx = get_id(<span class="keywordtype">object</span>);</div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  <span class="keywordflow">if</span> (idx == -1) {</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  idx = table_.push_back(<span class="keywordtype">object</span>);</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  }</div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  <span class="keywordflow">return</span> idx;</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span> }</div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span> </div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span> <span class="comment">// Add a callback to be called to delete the elements when the table took</span></div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span> <span class="comment">// their ownership.</span></div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00171"></a><span class="lineno"><a class="line" href="a02545.html#accc4dcfc4923d6ec2cb0f19c9f21ecfb"> 171</a></span> <span class="keywordtype">void</span> <a class="code" href="a02545.html#accc4dcfc4923d6ec2cb0f19c9f21ecfb">UnicityTable<T>::set_clear_callback</a>(<a class="code" href="a03129.html">TessCallback1<T></a>* cb) {</div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  table_.set_clear_callback(cb);</div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span> }</div><div class="line"><a name="l00174"></a><span class="lineno"> 174</span> </div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span> <span class="comment">// Add a callback to be called to delete the elements when the table took</span></div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span> <span class="comment">// their ownership.</span></div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00178"></a><span class="lineno"><a class="line" href="a02545.html#a64dcf9cac43cae1545a46c20e58156f9"> 178</a></span> <span class="keywordtype">void</span> <a class="code" href="a02545.html#a64dcf9cac43cae1545a46c20e58156f9">UnicityTable<T>::set_compare_callback</a>(<a class="code" href="a03141.html">TessResultCallback2<bool, T const &, T const &></a>* cb) {</div><div class="line"><a name="l00179"></a><span class="lineno"> 179</span>  table_.set_compare_callback(cb);</div><div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  compare_cb_ = cb;</div><div class="line"><a name="l00181"></a><span class="lineno"> 181</span> }</div><div class="line"><a name="l00182"></a><span class="lineno"> 182</span> </div><div class="line"><a name="l00183"></a><span class="lineno"> 183</span> <span class="comment">// Clear the table, calling the callback function if any.</span></div><div class="line"><a name="l00184"></a><span class="lineno"> 184</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00185"></a><span class="lineno"><a class="line" href="a02545.html#a43dd3813d75e38232c26e5532b9a096f"> 185</a></span> <span class="keywordtype">void</span> <a class="code" href="a02545.html#a43dd3813d75e38232c26e5532b9a096f">UnicityTable<T>::clear</a>() {</div><div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  table_.clear();</div><div class="line"><a name="l00187"></a><span class="lineno"> 187</span> }</div><div class="line"><a name="l00188"></a><span class="lineno"> 188</span> </div><div class="line"><a name="l00189"></a><span class="lineno"> 189</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00190"></a><span class="lineno"><a class="line" href="a02545.html#a9609758121c324bf31c510cd4cb7514b"> 190</a></span> <span class="keywordtype">bool</span> <a class="code" href="a02545.html#a9609758121c324bf31c510cd4cb7514b">UnicityTable<T>::write</a>(</div><div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  FILE* f, <a class="code" href="a03141.html">TessResultCallback2<bool, FILE*, T const &></a>* cb)<span class="keyword"> const </span>{</div><div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  <span class="keywordflow">return</span> table_.write(f, cb);</div><div class="line"><a name="l00193"></a><span class="lineno"> 193</span> }</div><div class="line"><a name="l00194"></a><span class="lineno"> 194</span> </div><div class="line"><a name="l00195"></a><span class="lineno"> 195</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00196"></a><span class="lineno"><a class="line" href="a02545.html#a31e2edb3f92024b211332a850723d237"> 196</a></span> <span class="keywordtype">bool</span> <a class="code" href="a02545.html#a31e2edb3f92024b211332a850723d237">UnicityTable<T>::read</a>(</div><div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  FILE* f, <a class="code" href="a03149.html">TessResultCallback3<bool, FILE*, T*, bool></a>* cb, <span class="keywordtype">bool</span> swap) {</div><div class="line"><a name="l00198"></a><span class="lineno"> 198</span>  <span class="keywordflow">return</span> table_.read(f, cb, swap);</div><div class="line"><a name="l00199"></a><span class="lineno"> 199</span> }</div><div class="line"><a name="l00200"></a><span class="lineno"> 200</span> </div><div class="line"><a name="l00201"></a><span class="lineno"> 201</span> <span class="comment">// This method clear the current object, then, does a shallow copy of</span></div><div class="line"><a name="l00202"></a><span class="lineno"> 202</span> <span class="comment">// its argument, and finally invalidate its argument.</span></div><div class="line"><a name="l00203"></a><span class="lineno"> 203</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00204"></a><span class="lineno"><a class="line" href="a02545.html#a18c8fc9ccbd7c0befdae1ab65bafdb12"> 204</a></span> <span class="keywordtype">void</span> <a class="code" href="a02545.html#a18c8fc9ccbd7c0befdae1ab65bafdb12">UnicityTable<T>::move</a>(<a class="code" href="a02545.html">UnicityTable<T></a>* from) {</div><div class="line"><a name="l00205"></a><span class="lineno"> 205</span>  table_.move(&from->table_);</div><div class="line"><a name="l00206"></a><span class="lineno"> 206</span> }</div><div class="line"><a name="l00207"></a><span class="lineno"> 207</span> </div><div class="line"><a name="l00208"></a><span class="lineno"> 208</span> <span class="preprocessor">#endif // TESSERACT_CCUTIL_UNICITY_TABLE_H_</span></div><div class="ttc" id="a02297_html"><div class="ttname"><a href="a02297.html">GenericVector</a></div><div class="ttdef"><b>Definition:</b> <a href="a00008_source.html#l00041">baseapi.h:41</a></div></div> <div class="ttc" id="a02545_html_accc4dcfc4923d6ec2cb0f19c9f21ecfb"><div class="ttname"><a href="a02545.html#accc4dcfc4923d6ec2cb0f19c9f21ecfb">UnicityTable::set_clear_callback</a></div><div class="ttdeci">void set_clear_callback(TessCallback1< T > *cb)</div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00171">unicity_table.h:171</a></div></div> <div class="ttc" id="a02545_html_ae527db7e6f995f3091ccba8d76658578"><div class="ttname"><a href="a02545.html#ae527db7e6f995f3091ccba8d76658578">UnicityTable::contains</a></div><div class="ttdeci">bool contains(T object) const</div><div class="ttdoc">Return true if T is in the table. </div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00154">unicity_table.h:154</a></div></div> <div class="ttc" id="a00596_html_ad000c6729bae0f97075ca10a0b5bf7d6"><div class="ttname"><a href="a00596.html#ad000c6729bae0f97075ca10a0b5bf7d6">NewPermanentTessCallback</a></div><div class="ttdeci">_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)</div><div class="ttdef"><b>Definition:</b> <a href="a00596_source.html#l00116">tesscallback.h:116</a></div></div> <div class="ttc" id="a02545_html_a43dd3813d75e38232c26e5532b9a096f"><div class="ttname"><a href="a02545.html#a43dd3813d75e38232c26e5532b9a096f">UnicityTable::clear</a></div><div class="ttdeci">void clear()</div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00185">unicity_table.h:185</a></div></div> <div class="ttc" id="a02545_html_a9609758121c324bf31c510cd4cb7514b"><div class="ttname"><a href="a02545.html#a9609758121c324bf31c510cd4cb7514b">UnicityTable::write</a></div><div class="ttdeci">bool write(FILE *f, TessResultCallback2< bool, FILE *, T const &> *cb) const</div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00190">unicity_table.h:190</a></div></div> <div class="ttc" id="a02545_html_a31e2edb3f92024b211332a850723d237"><div class="ttname"><a href="a02545.html#a31e2edb3f92024b211332a850723d237">UnicityTable::read</a></div><div class="ttdeci">bool read(FILE *f, TessResultCallback3< bool, FILE *, T *, bool > *cb, bool swap)</div><div class="ttdoc">swap is used to switch the endianness. </div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00196">unicity_table.h:196</a></div></div> <div class="ttc" id="a02545_html_aed48975fff77cc08f4724edd62e52b2e"><div class="ttname"><a href="a02545.html#aed48975fff77cc08f4724edd62e52b2e">UnicityTable::reserve</a></div><div class="ttdeci">void reserve(int size)</div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00126">unicity_table.h:126</a></div></div> <div class="ttc" id="a00596_html"><div class="ttname"><a href="a00596.html">tesscallback.h</a></div></div> <div class="ttc" id="a02545_html_ad2cf3104bf7e0b115d3709359e57cc72"><div class="ttname"><a href="a02545.html#ad2cf3104bf7e0b115d3709359e57cc72">UnicityTable::UnicityTable</a></div><div class="ttdeci">UnicityTable()</div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00108">unicity_table.h:108</a></div></div> <div class="ttc" id="a02545_html_a64dcf9cac43cae1545a46c20e58156f9"><div class="ttname"><a href="a02545.html#a64dcf9cac43cae1545a46c20e58156f9">UnicityTable::set_compare_callback</a></div><div class="ttdeci">void set_compare_callback(TessResultCallback2< bool, T const &, T const &> *cb)</div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00178">unicity_table.h:178</a></div></div> <div class="ttc" id="a04053_html_a0defa61aea3b236c9661185aedd558aa"><div class="ttname"><a href="a04053.html#a0defa61aea3b236c9661185aedd558aa">UnicityTableEqEq::UnicityTableEqEq</a></div><div class="ttdeci">UnicityTableEqEq()</div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00101">unicity_table.h:101</a></div></div> <div class="ttc" id="a03141_html"><div class="ttname"><a href="a03141.html">TessResultCallback2</a></div><div class="ttdef"><b>Definition:</b> <a href="a00596_source.html#l01688">tesscallback.h:1688</a></div></div> <div class="ttc" id="a00509_html"><div class="ttname"><a href="a00509.html">genericvector.h</a></div></div> <div class="ttc" id="a02545_html_a8d4d5b0dbaeccb8f4be89777615a0a61"><div class="ttname"><a href="a02545.html#a8d4d5b0dbaeccb8f4be89777615a0a61">UnicityTable::size</a></div><div class="ttdeci">int size() const</div><div class="ttdoc">Return the size used. </div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00119">unicity_table.h:119</a></div></div> <div class="ttc" id="a02545_html_a4693858a68107fa77697d8ba994c9999"><div class="ttname"><a href="a02545.html#a4693858a68107fa77697d8ba994c9999">UnicityTable::contains_id</a></div><div class="ttdeci">T contains_id(int id) const</div><div class="ttdoc">Return true if the id is valid. </div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00142">unicity_table.h:142</a></div></div> <div class="ttc" id="a00500_html"><div class="ttname"><a href="a00500.html">errcode.h</a></div></div> <div class="ttc" id="a03129_html"><div class="ttname"><a href="a03129.html">TessCallback1< T ></a></div></div> <div class="ttc" id="a03149_html"><div class="ttname"><a href="a03149.html">TessResultCallback3</a></div><div class="ttdef"><b>Definition:</b> <a href="a00596_source.html#l01702">tesscallback.h:1702</a></div></div> <div class="ttc" id="a02545_html_a6913a3f4f880861e0eca6c606e47646a"><div class="ttname"><a href="a02545.html#a6913a3f4f880861e0eca6c606e47646a">UnicityTable::get_mutable</a></div><div class="ttdeci">T * get_mutable(int id)</div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00137">unicity_table.h:137</a></div></div> <div class="ttc" id="a02545_html_abe542edc2a5eec07dcaf171c6a52455d"><div class="ttname"><a href="a02545.html#abe542edc2a5eec07dcaf171c6a52455d">UnicityTable::get</a></div><div class="ttdeci">const T & get(int id) const</div><div class="ttdoc">Return the object from an id. </div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00132">unicity_table.h:132</a></div></div> <div class="ttc" id="a02545_html_a98181de03a916ae28b9443a8821e90a5"><div class="ttname"><a href="a02545.html#a98181de03a916ae28b9443a8821e90a5">UnicityTable::~UnicityTable</a></div><div class="ttdeci">~UnicityTable()</div><div class="ttdoc">Clear the structures and deallocate internal structures. </div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00114">unicity_table.h:114</a></div></div> <div class="ttc" id="a02545_html_a2bba97bdd1934b28deddcc5a1e87ac16"><div class="ttname"><a href="a02545.html#a2bba97bdd1934b28deddcc5a1e87ac16">UnicityTable::get_id</a></div><div class="ttdeci">int get_id(T object) const</div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00148">unicity_table.h:148</a></div></div> <div class="ttc" id="a02545_html"><div class="ttname"><a href="a02545.html">UnicityTable</a></div><div class="ttdef"><b>Definition:</b> <a href="a00266_source.html#l00030">fontinfo.h:30</a></div></div> <div class="ttc" id="a02545_html_a659534293ab0e46a46cab4421bebfb8f"><div class="ttname"><a href="a02545.html#a659534293ab0e46a46cab4421bebfb8f">UnicityTable::push_back</a></div><div class="ttdeci">int push_back(T object)</div><div class="ttdoc">Add an element in the table. </div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00160">unicity_table.h:160</a></div></div> <div class="ttc" id="a02545_html_a18c8fc9ccbd7c0befdae1ab65bafdb12"><div class="ttname"><a href="a02545.html#a18c8fc9ccbd7c0befdae1ab65bafdb12">UnicityTable::move</a></div><div class="ttdeci">void move(UnicityTable< T > *from)</div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00204">unicity_table.h:204</a></div></div> <div class="ttc" id="a04053_html"><div class="ttname"><a href="a04053.html">UnicityTableEqEq</a></div><div class="ttdef"><b>Definition:</b> <a href="a00629_source.html#l00099">unicity_table.h:99</a></div></div> </div><!-- fragment --></div><!-- contents --> </div><!-- doc-content --> <!-- start footer part --> <div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> <ul> <li class="navelem"><a class="el" href="dir_c912ed9abd7a6639fbb8ce2a4e4e80ae.html">ccutil</a></li><li class="navelem"><a class="el" href="a00629.html">unicity_table.h</a></li> <li class="footer">Generated on Mon Oct 29 2018 11:27:48 for tesseract by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li> </ul> </div> </body> </html>