a00091.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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: node.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>node.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">// node.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: node.h,v 1.20 2003/11/27 13:36:56 raitner Exp $</span>
  33. <a name="l00007"></a>00007
  34. <a name="l00008"></a>00008 <span class="preprocessor">#ifndef GTL_NODE_H</span>
  35. <a name="l00009"></a>00009 <span class="preprocessor"></span><span class="preprocessor">#define GTL_NODE_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 <span class="preprocessor">#include &lt;GTL/edge.h&gt;</span>
  39. <a name="l00013"></a>00013
  40. <a name="l00014"></a>00014 <span class="preprocessor">#include &lt;list&gt;</span>
  41. <a name="l00015"></a>00015
  42. <a name="l00016"></a>00016 __GTL_BEGIN_NAMESPACE
  43. <a name="l00017"></a>00017
  44. <a name="l00018"></a>00018 <span class="comment">//--------------------------------------------------------------------------</span>
  45. <a name="l00019"></a>00019 <span class="comment">// For MSVC 5.0 node.h has to be included before {node,edge}_data.h.</span>
  46. <a name="l00020"></a>00020 <span class="comment">// So we only declare node_data here</span>
  47. <a name="l00021"></a>00021 <span class="comment">//--------------------------------------------------------------------------</span>
  48. <a name="l00022"></a>00022
  49. <a name="l00023"></a>00023 <span class="keyword">class </span>node_data;
  50. <a name="l00024"></a>00024
  51. <a name="l00025"></a>00025 <span class="comment">//--------------------------------------------------------------------------</span>
  52. <a name="l00026"></a>00026 <span class="comment">// The first alternative is correct. The second one is a workaround</span>
  53. <a name="l00027"></a>00027 <span class="comment">// for compilers that don't support namespaces and use the SGI STL</span>
  54. <a name="l00028"></a>00028 <span class="comment">// (i.e. gcc/egcs)</span>
  55. <a name="l00029"></a>00029 <span class="comment">//--------------------------------------------------------------------------</span>
  56. <a name="l00030"></a>00030
  57. <a name="l00031"></a>00031 <span class="preprocessor">#ifdef __GTL_USE_NAMESPACES</span>
  58. <a name="l00032"></a>00032 <span class="preprocessor"></span>
  59. <a name="l00033"></a>00033 <span class="keyword">class </span><a class="code" href="a00020.html" title="A node in a graph.">node</a>;
  60. <a name="l00034"></a>00034 <span class="keyword">typedef</span> std::iterator&lt;std::bidirectional_iterator_tag, edge&gt; bi_iter_edge;
  61. <a name="l00035"></a>00035 <span class="keyword">typedef</span> std::iterator&lt;std::bidirectional_iterator_tag, node&gt; bi_iter_node;
  62. <a name="l00036"></a>00036
  63. <a name="l00037"></a>00037 <span class="preprocessor">#else</span>
  64. <a name="l00038"></a>00038 <span class="preprocessor"></span>
  65. <a name="l00039"></a>00039 <span class="keyword">class </span><a class="code" href="a00020.html" title="A node in a graph.">node</a>;
  66. <a name="l00040"></a>00040 <span class="keyword">typedef</span> bidirectional_iterator&lt;edge,ptrdiff_t&gt; bi_iter_edge;
  67. <a name="l00041"></a>00041 <span class="keyword">typedef</span> bidirectional_iterator&lt;node,ptrdiff_t&gt; bi_iter_node;
  68. <a name="l00042"></a>00042
  69. <a name="l00043"></a>00043 <span class="preprocessor">#endif // __GTL_USE_NAMESPACES</span>
  70. <a name="l00044"></a>00044 <span class="preprocessor"></span>
  71. <a name="l00045"></a>00045 <span class="comment">//--------------------------------------------------------------------------</span>
  72. <a name="l00046"></a>00046 <span class="comment">// nodes</span>
  73. <a name="l00047"></a>00047 <span class="comment">//--------------------------------------------------------------------------</span>
  74. <a name="l00048"></a>00048
  75. <a name="l00052"></a><a class="code" href="a00020.html">00052</a> <span class="keyword">class </span>GTL_EXTERN <a class="code" href="a00020.html" title="A node in a graph.">node</a>
  76. <a name="l00053"></a>00053 {
  77. <a name="l00054"></a>00054 <span class="keyword">public</span>:
  78. <a name="l00068"></a>00068 <a class="code" href="a00020.html" title="A node in a graph.">node</a>();
  79. <a name="l00069"></a>00069
  80. <a name="l00074"></a>00074 <span class="keywordtype">int</span> degree() <span class="keyword">const</span>;
  81. <a name="l00075"></a>00075
  82. <a name="l00079"></a>00079 <span class="keywordtype">int</span> outdeg() <span class="keyword">const</span>;
  83. <a name="l00080"></a>00080
  84. <a name="l00084"></a>00084 <span class="keywordtype">int</span> indeg() <span class="keyword">const</span>;
  85. <a name="l00085"></a>00085
  86. <a name="l00089"></a>00089 <span class="keywordtype">int</span> id() <span class="keyword">const</span>;
  87. <a name="l00090"></a>00090
  88. <a name="l00096"></a>00096 <span class="keyword">const</span> <a class="code" href="a00020.html" title="A node in a graph.">node</a>&amp; opposite(<a class="code" href="a00010.html" title="An edge in a graph.">edge</a> e) <span class="keyword">const</span>;
  89. <a name="l00097"></a>00097
  90. <a name="l00101"></a>00101 list&lt;node&gt; opposites(<a class="code" href="a00010.html" title="An edge in a graph.">edge</a>) <span class="keyword">const</span>;
  91. <a name="l00102"></a>00102
  92. <a name="l00110"></a>00110 <span class="keywordtype">bool</span> is_hidden () <span class="keyword">const</span>;
  93. <a name="l00111"></a>00111
  94. <a name="l00118"></a>00118 <span class="keywordtype">int</span> excentricity() <span class="keyword">const</span>;
  95. <a name="l00119"></a>00119
  96. <a name="l00120"></a>00120 <span class="comment">//================================================== Iterator types</span>
  97. <a name="l00121"></a>00121
  98. <a name="l00125"></a>00125 <span class="keyword">typedef</span> list&lt;edge&gt;::const_iterator in_edges_iterator;
  99. <a name="l00129"></a>00129 <span class="keyword">typedef</span> list&lt;edge&gt;::const_iterator out_edges_iterator;
  100. <a name="l00130"></a>00130
  101. <a name="l00134"></a>00134 <span class="keyword">class </span>inout_edges_iterator;
  102. <a name="l00135"></a>00135
  103. <a name="l00139"></a>00139 <span class="keyword">class </span>adj_nodes_iterator;
  104. <a name="l00140"></a>00140
  105. <a name="l00144"></a>00144 <span class="keyword">class </span>adj_edges_iterator;
  106. <a name="l00145"></a>00145
  107. <a name="l00146"></a>00146 <span class="comment">//================================================== Iterators</span>
  108. <a name="l00147"></a>00147
  109. <a name="l00153"></a>00153 adj_nodes_iterator adj_nodes_begin() <span class="keyword">const</span>;
  110. <a name="l00154"></a>00154
  111. <a name="l00160"></a>00160 adj_nodes_iterator adj_nodes_end() <span class="keyword">const</span>;
  112. <a name="l00161"></a>00161
  113. <a name="l00167"></a>00167 adj_edges_iterator adj_edges_begin() <span class="keyword">const</span>;
  114. <a name="l00168"></a>00168
  115. <a name="l00174"></a>00174 adj_edges_iterator adj_edges_end() <span class="keyword">const</span>;
  116. <a name="l00175"></a>00175
  117. <a name="l00181"></a>00181 in_edges_iterator in_edges_begin() <span class="keyword">const</span>;
  118. <a name="l00182"></a>00182
  119. <a name="l00188"></a>00188 in_edges_iterator in_edges_end() <span class="keyword">const</span>;
  120. <a name="l00189"></a>00189
  121. <a name="l00195"></a>00195 out_edges_iterator out_edges_begin() <span class="keyword">const</span>;
  122. <a name="l00196"></a>00196
  123. <a name="l00202"></a>00202 out_edges_iterator out_edges_end() <span class="keyword">const</span>;
  124. <a name="l00203"></a>00203
  125. <a name="l00209"></a>00209 inout_edges_iterator inout_edges_begin() <span class="keyword">const</span>;
  126. <a name="l00210"></a>00210
  127. <a name="l00216"></a>00216 inout_edges_iterator inout_edges_end() <span class="keyword">const</span>;
  128. <a name="l00217"></a>00217
  129. <a name="l00218"></a>00218 <span class="comment">//================================================== Implementation</span>
  130. <a name="l00219"></a>00219
  131. <a name="l00220"></a>00220 <span class="keyword">private</span>:
  132. <a name="l00221"></a>00221 node_data *data;
  133. <a name="l00222"></a>00222
  134. <a name="l00223"></a>00223 <span class="keywordtype">bool</span> is_directed() <span class="keyword">const</span>;
  135. <a name="l00224"></a>00224 <span class="keywordtype">bool</span> is_undirected() <span class="keyword">const</span>;
  136. <a name="l00225"></a>00225
  137. <a name="l00226"></a>00226 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="a00014.html" title="A directed or undirected graph.">graph</a>;
  138. <a name="l00227"></a>00227 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="a00010.html" title="An edge in a graph.">edge</a>;
  139. <a name="l00228"></a>00228 <span class="keyword">friend</span> <span class="keyword">class </span>adj_edges_iterator;
  140. <a name="l00229"></a>00229
  141. <a name="l00230"></a>00230 GTL_EXTERN <span class="keyword">friend</span> <span class="keywordtype">bool</span> operator==(<a class="code" href="a00020.html" title="A node in a graph.">node</a>, <a class="code" href="a00020.html" title="A node in a graph.">node</a>);
  142. <a name="l00231"></a>00231 GTL_EXTERN <span class="keyword">friend</span> <span class="keywordtype">bool</span> operator!=(<a class="code" href="a00020.html" title="A node in a graph.">node</a>, <a class="code" href="a00020.html" title="A node in a graph.">node</a>);
  143. <a name="l00232"></a>00232 GTL_EXTERN <span class="keyword">friend</span> <span class="keywordtype">bool</span> operator&lt;(<a class="code" href="a00020.html" title="A node in a graph.">node</a>, <a class="code" href="a00020.html" title="A node in a graph.">node</a>);
  144. <a name="l00233"></a>00233 GTL_EXTERN <span class="keyword">friend</span> ostream&amp; operator&lt;&lt; (ostream&amp; os, <span class="keyword">const</span> <a class="code" href="a00020.html" title="A node in a graph.">node</a>&amp; n);
  145. <a name="l00234"></a>00234 };
  146. <a name="l00235"></a>00235
  147. <a name="l00236"></a>00236
  148. <a name="l00240"></a>00240 <span class="keyword">class </span>GTL_EXTERN <a class="code" href="a00020.html" title="A node in a graph.">node</a>::adj_edges_iterator : <span class="keyword">public</span> bi_iter_edge
  149. <a name="l00241"></a>00241 {
  150. <a name="l00242"></a>00242 <span class="keyword">public</span>:
  151. <a name="l00243"></a>00243
  152. <a name="l00244"></a>00244 <span class="comment">// constructor</span>
  153. <a name="l00245"></a>00245 adj_edges_iterator();
  154. <a name="l00246"></a>00246 adj_edges_iterator(<a class="code" href="a00020.html" title="A node in a graph.">node</a>, <span class="keywordtype">bool</span>);
  155. <a name="l00247"></a>00247
  156. <a name="l00248"></a>00248 <span class="comment">// comparibility</span>
  157. <a name="l00249"></a>00249 <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> adj_edges_iterator&amp;) <span class="keyword">const</span>;
  158. <a name="l00250"></a>00250 <span class="keywordtype">bool</span> operator!=(<span class="keyword">const</span> adj_edges_iterator&amp;) <span class="keyword">const</span>;
  159. <a name="l00251"></a>00251
  160. <a name="l00252"></a>00252 <span class="comment">// operators</span>
  161. <a name="l00253"></a>00253 adj_edges_iterator &amp;operator++();
  162. <a name="l00254"></a>00254 adj_edges_iterator operator++(<span class="keywordtype">int</span>);
  163. <a name="l00255"></a>00255 adj_edges_iterator &amp;operator--();
  164. <a name="l00256"></a>00256 adj_edges_iterator operator--(<span class="keywordtype">int</span>);
  165. <a name="l00257"></a>00257
  166. <a name="l00258"></a>00258 <span class="comment">// dereferencing</span>
  167. <a name="l00259"></a>00259 <span class="keyword">const</span> <a class="code" href="a00010.html" title="An edge in a graph.">edge</a>&amp; operator*() <span class="keyword">const</span>;
  168. <a name="l00260"></a>00260 <span class="keyword">const</span> <a class="code" href="a00010.html" title="An edge in a graph.">edge</a>* operator-&gt;() <span class="keyword">const</span>;
  169. <a name="l00261"></a>00261
  170. <a name="l00262"></a>00262 <span class="keyword">private</span>:
  171. <a name="l00263"></a>00263 in_edges_iterator akt_edge[2], last_edge[2], begin_edge[2];
  172. <a name="l00264"></a>00264 <span class="keywordtype">int</span> inout; <span class="comment">// in=0, out=1</span>
  173. <a name="l00265"></a>00265 <span class="keywordtype">bool</span> directed; <span class="comment">// graph directed ??</span>
  174. <a name="l00266"></a>00266 };
  175. <a name="l00267"></a>00267
  176. <a name="l00271"></a>00271 <span class="keyword">class </span>GTL_EXTERN <a class="code" href="a00020.html" title="A node in a graph.">node</a>::inout_edges_iterator : <span class="keyword">public</span> bi_iter_edge
  177. <a name="l00272"></a>00272 {
  178. <a name="l00273"></a>00273 <span class="keyword">public</span>:
  179. <a name="l00274"></a>00274
  180. <a name="l00275"></a>00275 <span class="comment">// constructor</span>
  181. <a name="l00276"></a>00276 inout_edges_iterator();
  182. <a name="l00277"></a>00277 inout_edges_iterator(<a class="code" href="a00020.html" title="A node in a graph.">node</a> n, <span class="keywordtype">bool</span> start);
  183. <a name="l00278"></a>00278
  184. <a name="l00279"></a>00279 <span class="comment">// comparibility</span>
  185. <a name="l00280"></a>00280 <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> inout_edges_iterator&amp;) <span class="keyword">const</span>;
  186. <a name="l00281"></a>00281 <span class="keywordtype">bool</span> operator!=(<span class="keyword">const</span> inout_edges_iterator&amp;) <span class="keyword">const</span>;
  187. <a name="l00282"></a>00282
  188. <a name="l00283"></a>00283 <span class="comment">// operators</span>
  189. <a name="l00284"></a>00284 inout_edges_iterator &amp;operator++();
  190. <a name="l00285"></a>00285 inout_edges_iterator operator++(<span class="keywordtype">int</span>);
  191. <a name="l00286"></a>00286 inout_edges_iterator &amp;operator--();
  192. <a name="l00287"></a>00287 inout_edges_iterator operator--(<span class="keywordtype">int</span>);
  193. <a name="l00288"></a>00288
  194. <a name="l00289"></a>00289 <span class="comment">// dereferencing</span>
  195. <a name="l00290"></a>00290 <span class="keyword">const</span> <a class="code" href="a00010.html" title="An edge in a graph.">edge</a>&amp; operator*() <span class="keyword">const</span>;
  196. <a name="l00291"></a>00291 <span class="keyword">const</span> <a class="code" href="a00010.html" title="An edge in a graph.">edge</a>* operator-&gt;() <span class="keyword">const</span>;
  197. <a name="l00292"></a>00292
  198. <a name="l00293"></a>00293 <span class="keyword">private</span>:
  199. <a name="l00294"></a>00294 in_edges_iterator akt_edge[2], last_edge, begin_edge;
  200. <a name="l00295"></a>00295 <span class="keywordtype">int</span> inout; <span class="comment">// in=0, out=1</span>
  201. <a name="l00296"></a>00296 };
  202. <a name="l00297"></a>00297
  203. <a name="l00301"></a>00301 <span class="keyword">class </span>GTL_EXTERN <a class="code" href="a00020.html" title="A node in a graph.">node</a>::adj_nodes_iterator : <span class="keyword">public</span> bi_iter_node
  204. <a name="l00302"></a>00302 {
  205. <a name="l00303"></a>00303 <span class="keyword">public</span>:
  206. <a name="l00304"></a>00304
  207. <a name="l00305"></a>00305 <span class="comment">// constructor</span>
  208. <a name="l00306"></a>00306 adj_nodes_iterator();
  209. <a name="l00307"></a>00307 adj_nodes_iterator(<span class="keyword">const</span> <a class="code" href="a00020.html" title="A node in a graph.">node</a>&amp;, <span class="keywordtype">bool</span>);
  210. <a name="l00308"></a>00308
  211. <a name="l00309"></a>00309 <span class="comment">// comparibility</span>
  212. <a name="l00310"></a>00310 <span class="keywordtype">bool</span> operator==(<span class="keyword">const</span> adj_nodes_iterator&amp;) <span class="keyword">const</span>;
  213. <a name="l00311"></a>00311 <span class="keywordtype">bool</span> operator!=(<span class="keyword">const</span> adj_nodes_iterator&amp;) <span class="keyword">const</span>;
  214. <a name="l00312"></a>00312
  215. <a name="l00313"></a>00313 <span class="comment">// operators</span>
  216. <a name="l00314"></a>00314 adj_nodes_iterator &amp;operator++();
  217. <a name="l00315"></a>00315 adj_nodes_iterator operator++(<span class="keywordtype">int</span>);
  218. <a name="l00316"></a>00316 adj_nodes_iterator &amp;operator--();
  219. <a name="l00317"></a>00317 adj_nodes_iterator operator--(<span class="keywordtype">int</span>);
  220. <a name="l00318"></a>00318
  221. <a name="l00319"></a>00319 <span class="comment">// dereferencing</span>
  222. <a name="l00320"></a>00320 <span class="keyword">const</span> <a class="code" href="a00020.html" title="A node in a graph.">node</a>&amp; operator*() <span class="keyword">const</span>;
  223. <a name="l00321"></a>00321 <span class="keyword">const</span> <a class="code" href="a00020.html" title="A node in a graph.">node</a>* operator-&gt;() <span class="keyword">const</span>;
  224. <a name="l00322"></a>00322
  225. <a name="l00323"></a>00323 <span class="keyword">private</span>:
  226. <a name="l00324"></a>00324 adj_edges_iterator akt_edge;
  227. <a name="l00325"></a>00325 <a class="code" href="a00020.html" title="A node in a graph.">node</a> int_node;
  228. <a name="l00326"></a>00326 };
  229. <a name="l00327"></a>00327
  230. <a name="l00328"></a>00328
  231. <a name="l00329"></a>00329 __GTL_END_NAMESPACE
  232. <a name="l00330"></a>00330
  233. <a name="l00331"></a>00331 <span class="comment">//--------------------------------------------------------------------------</span>
  234. <a name="l00332"></a>00332 <span class="comment">// Iteration</span>
  235. <a name="l00333"></a>00333 <span class="comment">//--------------------------------------------------------------------------</span>
  236. <a name="l00334"></a>00334
  237. <a name="l00335"></a>00335 <span class="comment">// #define forall_adj_nodes(v,w) GTL_FORALL(v,w,node::adj_nodes_iterator,adj_nodes_)</span>
  238. <a name="l00336"></a>00336 <span class="preprocessor">#define forall_out_edges(e,v) GTL_FORALL(e,v,node::out_edges_iterator,out_edges_)</span>
  239. <a name="l00337"></a>00337 <span class="preprocessor"></span><span class="preprocessor">#define forall_in_edges(e,v) GTL_FORALL(e,v,node::in_edges_iterator,in_edges_)</span>
  240. <a name="l00338"></a>00338 <span class="preprocessor"></span><span class="preprocessor">#define forall_inout_edges(e,v) GTL_FORALL(e,v,node::inout_edges_iterator,inout_edges_)</span>
  241. <a name="l00339"></a>00339 <span class="preprocessor"></span><span class="preprocessor">#define forall_adj_edges(e,v) GTL_FORALL(e,v,node::adj_edges_iterator,adj_edges_)</span>
  242. <a name="l00340"></a>00340 <span class="preprocessor"></span>
  243. <a name="l00341"></a>00341 <span class="preprocessor">#endif // GTL_NODE_H</span>
  244. <a name="l00342"></a>00342 <span class="preprocessor"></span>
  245. <a name="l00343"></a>00343 <span class="comment">//--------------------------------------------------------------------------</span>
  246. <a name="l00344"></a>00344 <span class="comment">// end of file</span>
  247. <a name="l00345"></a>00345 <span class="comment">//--------------------------------------------------------------------------</span>
  248. </pre></div> <p class="links">
  249. <a href="http://www.uni-passau.de/">University of Passau</a>
  250. &nbsp;-&nbsp;
  251. <a href="http://www.fmi.uni-passau.de/">FMI</a>
  252. &nbsp;-&nbsp;
  253. <a href="http://www.fmi.uni-passau.de/fmi/lehrstuehle/brandenburg/">Theoretical
  254. Computer Science</a>
  255. </p>
  256. <div class="copyright">
  257. Design &copy; 2002, 2003 <a href="mailto:raitner@fmi.uni-passau.de">Marcus Raitner</a>, University of Passau
  258. </div>
  259. </body>
  260. </html>