a00099.html 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
  5. <title>GTL - Graph Template Library: symlist.h Source File</title>
  6. <link href="doxygen.css" rel="stylesheet" type="text/css">
  7. </head>
  8. <body>
  9. <p class="links">
  10. <a href="../index.html">Home</a> |
  11. Documentation |
  12. <a href="../register.html">Download</a> |
  13. <a href="../platforms.html">Platforms</a> |
  14. <a href="../refer.html">Projects</a> |
  15. <a href="../lists.html">Mailing Lists</a> |
  16. <a href="../history.html">Version History</a>
  17. </p>
  18. <!-- Generated by Doxygen 1.5.3 -->
  19. <div class="tabs">
  20. <ul>
  21. <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
  22. <li><a href="classes.html"><span>Classes</span></a></li>
  23. <li class="current"><a href="files.html"><span>Files</span></a></li>
  24. <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  25. </ul>
  26. </div>
  27. <h1>symlist.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//==========================================================================</span>
  28. <a name="l00002"></a>00002 <span class="comment">//</span>
  29. <a name="l00003"></a>00003 <span class="comment">// symlist.h</span>
  30. <a name="l00004"></a>00004 <span class="comment">//</span>
  31. <a name="l00005"></a>00005 <span class="comment">//==========================================================================</span>
  32. <a name="l00006"></a>00006 <span class="comment">// $Id: symlist.h,v 1.17 2002/12/20 08:26:08 chris Exp $</span>
  33. <a name="l00007"></a>00007
  34. <a name="l00008"></a>00008 <span class="preprocessor">#ifndef SYMLIST_H</span>
  35. <a name="l00009"></a>00009 <span class="preprocessor"></span><span class="preprocessor">#define SYMLIST_H</span>
  36. <a name="l00010"></a>00010 <span class="preprocessor"></span>
  37. <a name="l00011"></a>00011 <span class="preprocessor">#include &lt;GTL/GTL.h&gt;</span>
  38. <a name="l00012"></a>00012
  39. <a name="l00013"></a>00013 <span class="preprocessor">#include &lt;cassert&gt;</span>
  40. <a name="l00014"></a>00014
  41. <a name="l00015"></a>00015 __GTL_BEGIN_NAMESPACE
  42. <a name="l00016"></a>00016
  43. <a name="l00020"></a>00020 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  44. <a name="l00021"></a>00021 <span class="keyword">struct </span>symnode
  45. <a name="l00022"></a>00022 {
  46. <a name="l00026"></a>00026 symnode()
  47. <a name="l00027"></a>00027 {
  48. <a name="l00028"></a>00028 }
  49. <a name="l00029"></a>00029
  50. <a name="l00033"></a>00033 symnode(<span class="keyword">const</span> T&amp; n) : data(n)
  51. <a name="l00034"></a>00034 {
  52. <a name="l00035"></a>00035 }
  53. <a name="l00036"></a>00036
  54. <a name="l00040"></a>00040 symnode* adj[2];
  55. <a name="l00041"></a>00041
  56. <a name="l00045"></a>00045 T data;
  57. <a name="l00046"></a>00046 };
  58. <a name="l00047"></a>00047
  59. <a name="l00051"></a>00051 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T, <span class="keyword">class</span> Ref&gt;
  60. <a name="l00052"></a>00052 <span class="keyword">struct </span>symlist_iterator
  61. <a name="l00053"></a>00053 {
  62. <a name="l00057"></a>00057 <span class="keyword">typedef</span> symlist_iterator&lt;T, Ref&gt; <span class="keyword">self</span>;
  63. <a name="l00058"></a>00058
  64. <a name="l00062"></a>00062 <span class="keyword">typedef</span> symnode&lt;T&gt;* linktype;
  65. <a name="l00063"></a>00063
  66. <a name="l00067"></a>00067 symlist_iterator() : act (0)
  67. <a name="l00068"></a>00068 {
  68. <a name="l00069"></a>00069 }
  69. <a name="l00070"></a>00070
  70. <a name="l00074"></a>00074 symlist_iterator(<span class="keyword">const</span> <span class="keyword">self</span>&amp; it) : act(it.act), dir(it.dir)
  71. <a name="l00075"></a>00075 {
  72. <a name="l00076"></a>00076 }
  73. <a name="l00077"></a>00077
  74. <a name="l00081"></a>00081 symlist_iterator(linktype _act, <span class="keywordtype">int</span> _dir) : act(_act), dir(_dir)
  75. <a name="l00082"></a>00082 {
  76. <a name="l00083"></a>00083 }
  77. <a name="l00084"></a>00084
  78. <a name="l00088"></a>00088 symlist_iterator(linktype _act, linktype _prev) :
  79. <a name="l00089"></a>00089 act(_act),
  80. <a name="l00090"></a>00090 dir (where_not (_act, _prev))
  81. <a name="l00091"></a>00091 {
  82. <a name="l00092"></a>00092 }
  83. <a name="l00093"></a>00093
  84. <a name="l00097"></a>00097 <span class="keyword">self</span>&amp; operator=(<span class="keyword">const</span> <span class="keyword">self</span>&amp; it)
  85. <a name="l00098"></a>00098 {
  86. <a name="l00099"></a>00099 act = it.act;
  87. <a name="l00100"></a>00100 dir = it.dir;
  88. <a name="l00101"></a>00101 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
  89. <a name="l00102"></a>00102 }
  90. <a name="l00103"></a>00103
  91. <a name="l00107"></a>00107 <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> <span class="keyword">self</span>&amp; it)<span class="keyword"> const</span>
  92. <a name="l00108"></a>00108 <span class="keyword"> </span>{
  93. <a name="l00109"></a>00109 <span class="keywordflow">return</span> act == it.act;
  94. <a name="l00110"></a>00110 }
  95. <a name="l00111"></a>00111
  96. <a name="l00115"></a>00115 <span class="keywordtype">bool</span> operator!=(<span class="keyword">const</span> <span class="keyword">self</span>&amp; it)<span class="keyword"> const</span>
  97. <a name="l00116"></a>00116 <span class="keyword"> </span>{
  98. <a name="l00117"></a>00117 <span class="keywordflow">return</span> act != it.act;
  99. <a name="l00118"></a>00118 }
  100. <a name="l00119"></a>00119
  101. <a name="l00123"></a>00123 Ref operator*()
  102. <a name="l00124"></a>00124 {
  103. <a name="l00125"></a>00125 <span class="keywordflow">return</span> act-&gt;data;
  104. <a name="l00126"></a>00126 }
  105. <a name="l00127"></a>00127
  106. <a name="l00131"></a>00131 <span class="keyword">self</span>&amp; operator++();
  107. <a name="l00132"></a>00132
  108. <a name="l00136"></a>00136 <span class="keyword">self</span>&amp; operator--();
  109. <a name="l00137"></a>00137
  110. <a name="l00141"></a>00141 <span class="keyword">static</span> <span class="keywordtype">int</span> where(linktype _act, linktype _prev)
  111. <a name="l00142"></a>00142 {
  112. <a name="l00143"></a>00143 <span class="keywordflow">return</span> _prev == _act-&gt;adj[0] ? 0 : 1;
  113. <a name="l00144"></a>00144 }
  114. <a name="l00145"></a>00145
  115. <a name="l00149"></a>00149 <span class="keyword">static</span> <span class="keywordtype">int</span> where_not(linktype _act, linktype _prev)
  116. <a name="l00150"></a>00150 {
  117. <a name="l00151"></a>00151 <span class="keywordflow">return</span> _prev == _act-&gt;adj[1] ? 0 : 1;
  118. <a name="l00152"></a>00152 }
  119. <a name="l00153"></a>00153
  120. <a name="l00157"></a>00157 <span class="keywordtype">void</span> reverse()
  121. <a name="l00158"></a>00158 {
  122. <a name="l00159"></a>00159 dir = 1 - dir;
  123. <a name="l00160"></a>00160 }
  124. <a name="l00161"></a>00161
  125. <a name="l00165"></a>00165 linktype&amp; next()
  126. <a name="l00166"></a>00166 {
  127. <a name="l00167"></a>00167 <span class="keywordflow">return</span> act-&gt;adj[dir];
  128. <a name="l00168"></a>00168 }
  129. <a name="l00169"></a>00169
  130. <a name="l00173"></a>00173 linktype&amp; prev()
  131. <a name="l00174"></a>00174 {
  132. <a name="l00175"></a>00175 <span class="keywordflow">return</span> act-&gt;adj[1 - dir];
  133. <a name="l00176"></a>00176 }
  134. <a name="l00177"></a>00177
  135. <a name="l00181"></a>00181 linktype act;
  136. <a name="l00182"></a>00182
  137. <a name="l00186"></a>00186 <span class="keywordtype">int</span> dir;
  138. <a name="l00187"></a>00187 };
  139. <a name="l00188"></a>00188
  140. <a name="l00207"></a>00207 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  141. <a name="l00208"></a><a class="code" href="a00027.html">00208</a> <span class="keyword">class </span><a class="code" href="a00027.html" title="List which can be reversed in .">symlist</a>
  142. <a name="l00209"></a>00209 {
  143. <a name="l00210"></a>00210 <span class="keyword">public</span>:
  144. <a name="l00214"></a>00214 <span class="keyword">typedef</span> symlist_iterator&lt;T, T&amp;&gt; iterator;
  145. <a name="l00215"></a>00215
  146. <a name="l00219"></a>00219 <span class="keyword">typedef</span> symlist_iterator&lt;T, const T&amp;&gt; const_iterator;
  147. <a name="l00220"></a>00220
  148. <a name="l00224"></a><a class="code" href="a00027.html#678dc0ddb02994195a2359a361ee0ea6">00224</a> <a class="code" href="a00027.html#678dc0ddb02994195a2359a361ee0ea6" title="Creates empty symlist.">symlist</a>()
  149. <a name="l00225"></a>00225 {
  150. <a name="l00226"></a>00226 link = <span class="keyword">new</span> symnode&lt;T&gt;;
  151. <a name="l00227"></a>00227 link-&gt;adj[0] = link-&gt;adj[1] = link;
  152. <a name="l00228"></a>00228 }
  153. <a name="l00229"></a>00229
  154. <a name="l00235"></a>00235 <a class="code" href="a00027.html#678dc0ddb02994195a2359a361ee0ea6" title="Creates empty symlist.">symlist</a>(<span class="keyword">const</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; li);
  155. <a name="l00236"></a>00236
  156. <a name="l00246"></a>00246 <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; <a class="code" href="a00027.html#ab326eda0f6d3a78f193a249342670bc" title="Assignes li to this list.">operator=</a>(<span class="keyword">const</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; li);
  157. <a name="l00247"></a>00247
  158. <a name="l00251"></a>00251 <a class="code" href="a00027.html#45c3a0b7f0e996998037fb876effefd4" title="Destructor.">~symlist</a>();
  159. <a name="l00252"></a>00252
  160. <a name="l00260"></a><a class="code" href="a00027.html#a09d7b1edcb879524dd200cecf7f5f72">00260</a> <span class="keywordtype">bool</span> <a class="code" href="a00027.html#a09d7b1edcb879524dd200cecf7f5f72" title="Checks whether list is empty.">empty</a>()<span class="keyword"> const</span>
  161. <a name="l00261"></a>00261 <span class="keyword"> </span>{
  162. <a name="l00262"></a>00262 <span class="keywordflow">return</span> link-&gt;adj[0] == link &amp;&amp; link-&gt;adj[1] == link;
  163. <a name="l00263"></a>00263 }
  164. <a name="l00264"></a>00264
  165. <a name="l00272"></a><a class="code" href="a00027.html#fd4b55616fc20033d4a47684551866e8">00272</a> T&amp; <a class="code" href="a00027.html#fd4b55616fc20033d4a47684551866e8" title="First element in list.">front</a>()
  166. <a name="l00273"></a>00273 {
  167. <a name="l00274"></a>00274 <span class="keywordflow">return</span> link-&gt;adj[0]-&gt;data;
  168. <a name="l00275"></a>00275 }
  169. <a name="l00276"></a>00276
  170. <a name="l00284"></a><a class="code" href="a00027.html#bc0570ff78ded9210ac26865519d36e3">00284</a> T&amp; <a class="code" href="a00027.html#bc0570ff78ded9210ac26865519d36e3" title="Last element in list.">back</a>()
  171. <a name="l00285"></a>00285 {
  172. <a name="l00286"></a>00286 <span class="keywordflow">return</span> link-&gt;adj[1]-&gt;data;
  173. <a name="l00287"></a>00287 }
  174. <a name="l00288"></a>00288
  175. <a name="l00294"></a><a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0">00294</a> iterator <a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>()
  176. <a name="l00295"></a>00295 {
  177. <a name="l00296"></a>00296 <span class="keywordflow">return</span> ++<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>();
  178. <a name="l00297"></a>00297 }
  179. <a name="l00298"></a>00298
  180. <a name="l00304"></a><a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883">00304</a> iterator <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>()
  181. <a name="l00305"></a>00305 {
  182. <a name="l00306"></a>00306 <span class="keywordflow">return</span> iterator(link, 0);
  183. <a name="l00307"></a>00307 }
  184. <a name="l00308"></a>00308
  185. <a name="l00314"></a><a class="code" href="a00027.html#7c714327f88430cb7caeb1ecd67afd95">00314</a> const_iterator <a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>()<span class="keyword"> const</span>
  186. <a name="l00315"></a>00315 <span class="keyword"> </span>{
  187. <a name="l00316"></a>00316 <span class="keywordflow">return</span> ++<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>();
  188. <a name="l00317"></a>00317 }
  189. <a name="l00318"></a>00318
  190. <a name="l00324"></a><a class="code" href="a00027.html#e7435efb58eeacee68c0268332ed1b0e">00324</a> const_iterator <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a> ()<span class="keyword"> const</span>
  191. <a name="l00325"></a>00325 <span class="keyword"> </span>{
  192. <a name="l00326"></a>00326 <span class="keywordflow">return</span> const_iterator (link, 0);
  193. <a name="l00327"></a>00327 }
  194. <a name="l00328"></a>00328
  195. <a name="l00334"></a><a class="code" href="a00027.html#e5250e0c0c2bedee285f72584ddce29d">00334</a> iterator <a class="code" href="a00027.html#e5250e0c0c2bedee285f72584ddce29d" title="Start iteration through element of list in reverse order.">rbegin</a>()
  196. <a name="l00335"></a>00335 {
  197. <a name="l00336"></a>00336 <span class="keywordflow">return</span> ++<a class="code" href="a00027.html#421fc482e62f257a9081e9e1c29d66a6" title="End of iteration through elements of list in reverse order.">rend</a>();
  198. <a name="l00337"></a>00337 }
  199. <a name="l00338"></a>00338
  200. <a name="l00344"></a><a class="code" href="a00027.html#421fc482e62f257a9081e9e1c29d66a6">00344</a> iterator <a class="code" href="a00027.html#421fc482e62f257a9081e9e1c29d66a6" title="End of iteration through elements of list in reverse order.">rend</a>()
  201. <a name="l00345"></a>00345 {
  202. <a name="l00346"></a>00346 <span class="keywordflow">return</span> iterator (link, 1);
  203. <a name="l00347"></a>00347 }
  204. <a name="l00348"></a>00348
  205. <a name="l00354"></a><a class="code" href="a00027.html#52e8efa766be554f4a5a788758c8b2e9">00354</a> const_iterator <a class="code" href="a00027.html#e5250e0c0c2bedee285f72584ddce29d" title="Start iteration through element of list in reverse order.">rbegin</a>()<span class="keyword"> const</span>
  206. <a name="l00355"></a>00355 <span class="keyword"> </span>{
  207. <a name="l00356"></a>00356 <span class="keywordflow">return</span> ++<a class="code" href="a00027.html#421fc482e62f257a9081e9e1c29d66a6" title="End of iteration through elements of list in reverse order.">rend</a>();
  208. <a name="l00357"></a>00357 }
  209. <a name="l00358"></a>00358
  210. <a name="l00364"></a><a class="code" href="a00027.html#a33168957d1316726012faa6b01fb9d2">00364</a> const_iterator <a class="code" href="a00027.html#421fc482e62f257a9081e9e1c29d66a6" title="End of iteration through elements of list in reverse order.">rend</a>()<span class="keyword"> const</span>
  211. <a name="l00365"></a>00365 <span class="keyword"> </span>{
  212. <a name="l00366"></a>00366 <span class="keywordflow">return</span> const_iterator(link, 1);
  213. <a name="l00367"></a>00367 }
  214. <a name="l00368"></a>00368
  215. <a name="l00377"></a>00377 iterator <a class="code" href="a00027.html#8a54cb9a00643d32c91a3b303140abb9" title="Inserts data before pos in list.">insert</a> (iterator pos, <span class="keyword">const</span> T&amp; data);
  216. <a name="l00378"></a>00378
  217. <a name="l00390"></a>00390 <span class="keywordtype">void</span> <a class="code" href="a00027.html#c2bd4d9db62ea6a3282662c62a97c3b2" title="Inserts the element it points to before pos into this list.">splice</a> (iterator pos, iterator it);
  218. <a name="l00391"></a>00391
  219. <a name="l00404"></a>00404 <span class="keywordtype">void</span> <a class="code" href="a00027.html#c2bd4d9db62ea6a3282662c62a97c3b2" title="Inserts the element it points to before pos into this list.">splice</a> (iterator pos, iterator it, iterator <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>);
  220. <a name="l00405"></a>00405
  221. <a name="l00413"></a>00413 iterator <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">erase</a> (iterator pos);
  222. <a name="l00414"></a>00414
  223. <a name="l00423"></a>00423 iterator <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">erase</a> (iterator it, iterator <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>);
  224. <a name="l00424"></a>00424
  225. <a name="l00428"></a>00428 <span class="keywordtype">void</span> attach_sublist (iterator, iterator);
  226. <a name="l00429"></a>00429
  227. <a name="l00433"></a>00433 <span class="keywordtype">void</span> detach_sublist ();
  228. <a name="l00434"></a>00434
  229. <a name="l00440"></a>00440 <span class="keywordtype">void</span> <a class="code" href="a00027.html#e22b65101604c694e96974cc9579ab78" title="Change the direction of list.">reverse</a> ();
  230. <a name="l00441"></a>00441 <span class="keyword">private</span>:
  231. <a name="l00445"></a>00445 symnode&lt;T&gt;* link;
  232. <a name="l00446"></a>00446
  233. <a name="l00452"></a>00452 iterator _prev;
  234. <a name="l00453"></a>00453
  235. <a name="l00459"></a>00459 iterator _next;
  236. <a name="l00460"></a>00460 };
  237. <a name="l00461"></a>00461
  238. <a name="l00462"></a>00462
  239. <a name="l00463"></a>00463 <span class="comment">// Implementation Begin</span>
  240. <a name="l00464"></a>00464
  241. <a name="l00465"></a>00465 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T, <span class="keyword">class</span> Ref&gt;
  242. <a name="l00466"></a>00466 symlist_iterator&lt;T, Ref&gt;&amp; symlist_iterator&lt;T, Ref&gt;::operator++()
  243. <a name="l00467"></a>00467 {
  244. <a name="l00468"></a>00468 symnode&lt;T&gt;* prev = act;
  245. <a name="l00469"></a>00469 act = act-&gt;adj[dir];
  246. <a name="l00470"></a>00470 dir = where_not(act, prev);
  247. <a name="l00471"></a>00471 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
  248. <a name="l00472"></a>00472 }
  249. <a name="l00473"></a>00473
  250. <a name="l00474"></a>00474
  251. <a name="l00475"></a>00475 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T, <span class="keyword">class</span> Ref&gt;
  252. <a name="l00476"></a>00476 symlist_iterator&lt;T, Ref&gt;&amp; symlist_iterator&lt;T, Ref&gt;::operator--()
  253. <a name="l00477"></a>00477 {
  254. <a name="l00478"></a>00478 symnode&lt;T&gt;* prev = act;
  255. <a name="l00479"></a>00479 act = act-&gt;adj[1 - dir];
  256. <a name="l00480"></a>00480 dir = where(act, prev);
  257. <a name="l00481"></a>00481 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
  258. <a name="l00482"></a>00482 }
  259. <a name="l00483"></a>00483
  260. <a name="l00484"></a>00484
  261. <a name="l00485"></a>00485 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  262. <a name="l00486"></a><a class="code" href="a00027.html#5c17d54592dac03b2c4d940a10153797">00486</a> <a class="code" href="a00027.html#678dc0ddb02994195a2359a361ee0ea6" title="Creates empty symlist.">symlist&lt;T&gt;::symlist</a> (<span class="keyword">const</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; l)
  263. <a name="l00487"></a>00487 {
  264. <a name="l00488"></a>00488 link = <span class="keyword">new</span> symnode&lt;T&gt;;
  265. <a name="l00489"></a>00489 link-&gt;adj[0] = link-&gt;adj[1] = link;
  266. <a name="l00490"></a>00490
  267. <a name="l00491"></a>00491 const_iterator it = l.<a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>();
  268. <a name="l00492"></a>00492 const_iterator e = l.<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>();
  269. <a name="l00493"></a>00493
  270. <a name="l00494"></a>00494 <span class="keywordflow">while</span> (it != e)
  271. <a name="l00495"></a>00495 {
  272. <a name="l00496"></a>00496 <a class="code" href="a00027.html#8a54cb9a00643d32c91a3b303140abb9" title="Inserts data before pos in list.">insert</a>(<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>(), *it);
  273. <a name="l00497"></a>00497 ++it;
  274. <a name="l00498"></a>00498 }
  275. <a name="l00499"></a>00499 }
  276. <a name="l00500"></a>00500
  277. <a name="l00501"></a>00501
  278. <a name="l00502"></a>00502 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  279. <a name="l00503"></a><a class="code" href="a00027.html#45c3a0b7f0e996998037fb876effefd4">00503</a> <a class="code" href="a00027.html#45c3a0b7f0e996998037fb876effefd4" title="Destructor.">symlist&lt;T&gt;::~symlist</a>()
  280. <a name="l00504"></a>00504 {
  281. <a name="l00505"></a>00505 <span class="keywordflow">if</span> (_next == iterator())
  282. <a name="l00506"></a>00506 {
  283. <a name="l00507"></a>00507 <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">erase</a> (<a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>(), <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>());
  284. <a name="l00508"></a>00508 }
  285. <a name="l00509"></a>00509 <span class="keywordflow">else</span>
  286. <a name="l00510"></a>00510 {
  287. <a name="l00511"></a>00511 detach_sublist();
  288. <a name="l00512"></a>00512 }
  289. <a name="l00513"></a>00513
  290. <a name="l00514"></a>00514 <span class="keyword">delete</span> link;
  291. <a name="l00515"></a>00515 }
  292. <a name="l00516"></a>00516
  293. <a name="l00517"></a>00517
  294. <a name="l00518"></a>00518 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  295. <a name="l00519"></a><a class="code" href="a00027.html#ab326eda0f6d3a78f193a249342670bc">00519</a> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; <a class="code" href="a00027.html#ab326eda0f6d3a78f193a249342670bc" title="Assignes li to this list.">symlist&lt;T&gt;::operator=</a>(<span class="keyword">const</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;</a>&amp; l)
  296. <a name="l00520"></a>00520 {
  297. <a name="l00521"></a>00521 <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">erase</a>(<a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>(), <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>());
  298. <a name="l00522"></a>00522
  299. <a name="l00523"></a>00523 const_iterator it = l.<a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>();
  300. <a name="l00524"></a>00524 const_iterator e = l.<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>();
  301. <a name="l00525"></a>00525
  302. <a name="l00526"></a>00526 <span class="keywordflow">while</span> (it != e)
  303. <a name="l00527"></a>00527 {
  304. <a name="l00528"></a>00528 <a class="code" href="a00027.html#8a54cb9a00643d32c91a3b303140abb9" title="Inserts data before pos in list.">insert</a>(<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>(), *it);
  305. <a name="l00529"></a>00529 ++it;
  306. <a name="l00530"></a>00530 }
  307. <a name="l00531"></a>00531
  308. <a name="l00532"></a>00532 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
  309. <a name="l00533"></a>00533 }
  310. <a name="l00534"></a>00534
  311. <a name="l00535"></a>00535
  312. <a name="l00536"></a>00536 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  313. <a name="l00537"></a>00537 symlist_iterator&lt;T, T&amp;&gt; <a class="code" href="a00027.html#8a54cb9a00643d32c91a3b303140abb9" title="Inserts data before pos in list.">symlist&lt;T&gt;::insert</a>(
  314. <a name="l00538"></a>00538 symlist_iterator&lt;T,T&amp;&gt; pos,
  315. <a name="l00539"></a>00539 <span class="keyword">const</span> T&amp; ins)
  316. <a name="l00540"></a>00540 {
  317. <a name="l00541"></a>00541 iterator prev = pos;
  318. <a name="l00542"></a>00542 --prev;
  319. <a name="l00543"></a>00543 symnode&lt;T&gt;* n = <span class="keyword">new</span> symnode&lt;T&gt;(ins);
  320. <a name="l00544"></a>00544 n-&gt;adj[0] = pos.act;
  321. <a name="l00545"></a>00545 n-&gt;adj[1] = prev.act;
  322. <a name="l00546"></a>00546
  323. <a name="l00547"></a>00547 <span class="keywordflow">if</span> (pos == prev)
  324. <a name="l00548"></a>00548 {
  325. <a name="l00549"></a>00549 pos = prev;
  326. <a name="l00550"></a>00550 }
  327. <a name="l00551"></a>00551
  328. <a name="l00552"></a>00552 pos.prev() = n;
  329. <a name="l00553"></a>00553 prev.next() = n;
  330. <a name="l00554"></a>00554
  331. <a name="l00555"></a>00555 <span class="keywordflow">return</span> iterator(n, 0);
  332. <a name="l00556"></a>00556 }
  333. <a name="l00557"></a>00557
  334. <a name="l00558"></a>00558
  335. <a name="l00559"></a>00559 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  336. <a name="l00560"></a>00560 <span class="keywordtype">void</span> <a class="code" href="a00027.html#c2bd4d9db62ea6a3282662c62a97c3b2" title="Inserts the element it points to before pos into this list.">symlist&lt;T&gt;::splice</a>(symlist_iterator&lt;T, T&amp;&gt; pos,
  337. <a name="l00561"></a>00561 symlist_iterator&lt;T, T&amp;&gt; beg,
  338. <a name="l00562"></a>00562 symlist_iterator&lt;T, T&amp;&gt; <a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>)
  339. <a name="l00563"></a>00563 {
  340. <a name="l00564"></a>00564 <span class="keywordflow">if</span> (beg != end)
  341. <a name="l00565"></a>00565 {
  342. <a name="l00566"></a>00566 iterator prev = beg;
  343. <a name="l00567"></a>00567 --prev;
  344. <a name="l00568"></a>00568 iterator last = end;
  345. <a name="l00569"></a>00569 --last;
  346. <a name="l00570"></a>00570
  347. <a name="l00571"></a>00571 <span class="comment">//</span>
  348. <a name="l00572"></a>00572 <span class="comment">// The following seems to be rather senseless, but it is required</span>
  349. <a name="l00573"></a>00573 <span class="comment">// since two iterator are equal, iff the point to the same element.</span>
  350. <a name="l00574"></a>00574 <span class="comment">// This implies that they might have different directions. Suppose</span>
  351. <a name="l00575"></a>00575 <span class="comment">// that prev == end is true and they have different directions,</span>
  352. <a name="l00576"></a>00576 <span class="comment">// than prev.next() and end.prev() return the same element !! Thus</span>
  353. <a name="l00577"></a>00577 <span class="comment">// the assignment prev = end corrects this, since the direction</span>
  354. <a name="l00578"></a>00578 <span class="comment">// gets copied, too.</span>
  355. <a name="l00579"></a>00579 <span class="comment">//</span>
  356. <a name="l00580"></a>00580 <span class="keywordflow">if</span> (prev == end)
  357. <a name="l00581"></a>00581 {
  358. <a name="l00582"></a>00582 prev = end;
  359. <a name="l00583"></a>00583 }
  360. <a name="l00584"></a>00584
  361. <a name="l00585"></a>00585 prev.next() = end.act;
  362. <a name="l00586"></a>00586 end.prev() = prev.act;
  363. <a name="l00587"></a>00587
  364. <a name="l00588"></a>00588 prev = pos;
  365. <a name="l00589"></a>00589 --prev;
  366. <a name="l00590"></a>00590
  367. <a name="l00591"></a>00591 <span class="keywordflow">if</span> (pos == prev)
  368. <a name="l00592"></a>00592 {
  369. <a name="l00593"></a>00593 pos = prev;
  370. <a name="l00594"></a>00594 }
  371. <a name="l00595"></a>00595
  372. <a name="l00596"></a>00596 <span class="keywordflow">if</span> (last == beg)
  373. <a name="l00597"></a>00597 {
  374. <a name="l00598"></a>00598 last = beg;
  375. <a name="l00599"></a>00599 }
  376. <a name="l00600"></a>00600
  377. <a name="l00601"></a>00601 prev.next() = beg.act;
  378. <a name="l00602"></a>00602 beg.prev() = prev.act;
  379. <a name="l00603"></a>00603 pos.prev() = last.act;
  380. <a name="l00604"></a>00604 last.next() = pos.act;
  381. <a name="l00605"></a>00605 }
  382. <a name="l00606"></a>00606 }
  383. <a name="l00607"></a>00607
  384. <a name="l00608"></a>00608
  385. <a name="l00609"></a>00609 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  386. <a name="l00610"></a>00610 <span class="keywordtype">void</span> <a class="code" href="a00027.html#c2bd4d9db62ea6a3282662c62a97c3b2" title="Inserts the element it points to before pos into this list.">symlist&lt;T&gt;::splice</a>(symlist_iterator&lt;T,T&amp;&gt; pos,
  387. <a name="l00611"></a>00611 symlist_iterator&lt;T,T&amp;&gt; beg)
  388. <a name="l00612"></a>00612 {
  389. <a name="l00613"></a>00613 iterator tmp = beg;
  390. <a name="l00614"></a>00614 ++tmp;
  391. <a name="l00615"></a>00615 <a class="code" href="a00027.html#c2bd4d9db62ea6a3282662c62a97c3b2" title="Inserts the element it points to before pos into this list.">splice</a>(pos, beg, tmp);
  392. <a name="l00616"></a>00616 }
  393. <a name="l00617"></a>00617
  394. <a name="l00618"></a>00618
  395. <a name="l00619"></a>00619 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  396. <a name="l00620"></a>00620 symlist_iterator&lt;T,T&amp;&gt; <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">symlist&lt;T&gt;::erase</a>(symlist_iterator&lt;T,T&amp;&gt; pos)
  397. <a name="l00621"></a>00621 {
  398. <a name="l00622"></a>00622 assert (pos.act != link);
  399. <a name="l00623"></a>00623 iterator prev = pos;
  400. <a name="l00624"></a>00624 --prev;
  401. <a name="l00625"></a>00625 iterator next = pos;
  402. <a name="l00626"></a>00626 ++next;
  403. <a name="l00627"></a>00627
  404. <a name="l00628"></a>00628 <span class="keywordflow">if</span> (next == prev)
  405. <a name="l00629"></a>00629 {
  406. <a name="l00630"></a>00630 next = prev;
  407. <a name="l00631"></a>00631 }
  408. <a name="l00632"></a>00632
  409. <a name="l00633"></a>00633 next.prev() = prev.act;
  410. <a name="l00634"></a>00634 prev.next() = next.act;
  411. <a name="l00635"></a>00635
  412. <a name="l00636"></a>00636 <span class="keyword">delete</span> (pos.act);
  413. <a name="l00637"></a>00637
  414. <a name="l00638"></a>00638 <span class="keywordflow">return</span> next;
  415. <a name="l00639"></a>00639 }
  416. <a name="l00640"></a>00640
  417. <a name="l00641"></a>00641 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  418. <a name="l00642"></a>00642 symlist_iterator&lt;T,T&amp;&gt; <a class="code" href="a00027.html#75fc1fc7db7b20cc430ddb8577608904" title="Deletes element at position pos from list.">symlist&lt;T&gt;::erase</a>(symlist_iterator&lt;T,T&amp;&gt; beg,
  419. <a name="l00643"></a>00643 symlist_iterator&lt;T,T&amp;&gt; end)
  420. <a name="l00644"></a>00644 {
  421. <a name="l00645"></a>00645 iterator prev = beg;
  422. <a name="l00646"></a>00646 --prev;
  423. <a name="l00647"></a>00647 iterator it = beg;
  424. <a name="l00648"></a>00648 symnode&lt;T&gt;* act;
  425. <a name="l00649"></a>00649
  426. <a name="l00650"></a>00650 <span class="keywordflow">while</span> (it != end)
  427. <a name="l00651"></a>00651 {
  428. <a name="l00652"></a>00652 assert (it.act != link);
  429. <a name="l00653"></a>00653 act = it.act;
  430. <a name="l00654"></a>00654 ++it;
  431. <a name="l00655"></a>00655 <span class="keyword">delete</span> (act);
  432. <a name="l00656"></a>00656 }
  433. <a name="l00657"></a>00657
  434. <a name="l00658"></a>00658 <span class="keywordflow">if</span> (prev == end)
  435. <a name="l00659"></a>00659 {
  436. <a name="l00660"></a>00660 prev = end;
  437. <a name="l00661"></a>00661 }
  438. <a name="l00662"></a>00662
  439. <a name="l00663"></a>00663 end.prev() = prev.act;
  440. <a name="l00664"></a>00664 prev.next() = end.act;
  441. <a name="l00665"></a>00665
  442. <a name="l00666"></a>00666 <span class="keywordflow">return</span> end;
  443. <a name="l00667"></a>00667 }
  444. <a name="l00668"></a>00668
  445. <a name="l00669"></a>00669
  446. <a name="l00670"></a>00670 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  447. <a name="l00671"></a>00671 <span class="keywordtype">void</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;::attach_sublist</a>(symlist_iterator&lt;T,T&amp;&gt; it,
  448. <a name="l00672"></a>00672 symlist_iterator&lt;T,T&amp;&gt; end)
  449. <a name="l00673"></a>00673 {
  450. <a name="l00674"></a>00674 assert (<a class="code" href="a00027.html#a09d7b1edcb879524dd200cecf7f5f72" title="Checks whether list is empty.">empty</a>());
  451. <a name="l00675"></a>00675 iterator last = end;
  452. <a name="l00676"></a>00676 --last;
  453. <a name="l00677"></a>00677 _prev = it;
  454. <a name="l00678"></a>00678 --_prev;
  455. <a name="l00679"></a>00679 _next = end;
  456. <a name="l00680"></a>00680
  457. <a name="l00681"></a>00681 <span class="keywordflow">if</span> (it == last)
  458. <a name="l00682"></a>00682 {
  459. <a name="l00683"></a>00683 it = last;
  460. <a name="l00684"></a>00684 }
  461. <a name="l00685"></a>00685
  462. <a name="l00686"></a>00686 link-&gt;adj[0] = it.act;
  463. <a name="l00687"></a>00687 it.prev() = link;
  464. <a name="l00688"></a>00688 link-&gt;adj[1] = last.act;
  465. <a name="l00689"></a>00689 last.next() = link;
  466. <a name="l00690"></a>00690 }
  467. <a name="l00691"></a>00691
  468. <a name="l00692"></a>00692
  469. <a name="l00693"></a>00693 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  470. <a name="l00694"></a>00694 <span class="keywordtype">void</span> <a class="code" href="a00027.html" title="List which can be reversed in .">symlist&lt;T&gt;::detach_sublist</a>()
  471. <a name="l00695"></a>00695 {
  472. <a name="l00696"></a>00696 <span class="keywordflow">if</span> (_next != iterator())
  473. <a name="l00697"></a>00697 {
  474. <a name="l00698"></a>00698 iterator it(<a class="code" href="a00027.html#525b8d44af5d771fe15916372515cce0" title="Start iteration through elements of list.">begin</a>());
  475. <a name="l00699"></a>00699 iterator e(<a class="code" href="a00027.html#7283589fa01f79d722f8256d7a6a7883" title="End of iteration through elements of list.">end</a>());
  476. <a name="l00700"></a>00700
  477. <a name="l00701"></a>00701 --e;
  478. <a name="l00702"></a>00702
  479. <a name="l00703"></a>00703 <span class="keywordflow">if</span> (e == it)
  480. <a name="l00704"></a>00704 {
  481. <a name="l00705"></a>00705 e = it;
  482. <a name="l00706"></a>00706 }
  483. <a name="l00707"></a>00707
  484. <a name="l00708"></a>00708 _prev.next() = it.act;
  485. <a name="l00709"></a>00709 it.prev() = _prev.act;
  486. <a name="l00710"></a>00710 _next.prev() = e.act;
  487. <a name="l00711"></a>00711 e.next() = _next.act;
  488. <a name="l00712"></a>00712 link-&gt;adj[0] = link-&gt;adj[1] = link;
  489. <a name="l00713"></a>00713
  490. <a name="l00714"></a>00714 _next = iterator();
  491. <a name="l00715"></a>00715 _prev = iterator();
  492. <a name="l00716"></a>00716 }
  493. <a name="l00717"></a>00717 }
  494. <a name="l00718"></a>00718
  495. <a name="l00719"></a>00719
  496. <a name="l00720"></a>00720 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
  497. <a name="l00721"></a><a class="code" href="a00027.html#e22b65101604c694e96974cc9579ab78">00721</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00027.html#e22b65101604c694e96974cc9579ab78" title="Change the direction of list.">symlist&lt;T&gt;::reverse</a>()
  498. <a name="l00722"></a>00722 {
  499. <a name="l00723"></a>00723 symnode&lt;T&gt;* tmp = link-&gt;adj[0];
  500. <a name="l00724"></a>00724 link-&gt;adj[0] = link-&gt;adj[1];
  501. <a name="l00725"></a>00725 link-&gt;adj[1] = tmp;
  502. <a name="l00726"></a>00726 }
  503. <a name="l00727"></a>00727
  504. <a name="l00728"></a>00728 <span class="comment">// Implementation End</span>
  505. <a name="l00729"></a>00729
  506. <a name="l00730"></a>00730 __GTL_END_NAMESPACE
  507. <a name="l00731"></a>00731
  508. <a name="l00732"></a>00732 <span class="preprocessor">#endif // SYMLIST_H</span>
  509. <a name="l00733"></a>00733 <span class="preprocessor"></span>
  510. <a name="l00734"></a>00734 <span class="comment">//--------------------------------------------------------------------------</span>
  511. <a name="l00735"></a>00735 <span class="comment">// end of file</span>
  512. <a name="l00736"></a>00736 <span class="comment">//--------------------------------------------------------------------------</span>
  513. </pre></div> <p class="links">
  514. <a href="http://www.uni-passau.de/">University of Passau</a>
  515. &nbsp;-&nbsp;
  516. <a href="http://www.fmi.uni-passau.de/">FMI</a>
  517. &nbsp;-&nbsp;
  518. <a href="http://www.fmi.uni-passau.de/fmi/lehrstuehle/brandenburg/">Theoretical
  519. Computer Science</a>
  520. </p>
  521. <div class="copyright">
  522. Design &copy; 2002, 2003 <a href="mailto:raitner@fmi.uni-passau.de">Marcus Raitner</a>, University of Passau
  523. </div>
  524. </body>
  525. </html>