Sophie

Sophie

distrib > Mageia > 1 > i586 > by-pkgid > 64656f00434e190abe8506174ca339ed > files > 5

ucommon-doc-4.3.1-1.mga1.i586.rpm

<!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"/>
<title>ucommon: linked.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.3 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">ucommon</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00003.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<h1>linked.cpp</h1>  </div>
</div>
<div class="contents">
<p>An example of the linked object classes and their use.</p>
<div class="fragment"><pre class="fragment"><span class="comment">// Copyright (C) 2006-2010 David Sugar, Tycho Softworks.</span>
<span class="comment">//</span>
<span class="comment">// This file is part of GNU uCommon C++.</span>
<span class="comment">//</span>
<span class="comment">// GNU uCommon C++ is free software: you can redistribute it and/or modify</span>
<span class="comment">// it under the terms of the GNU Lesser General Public License as published</span>
<span class="comment">// by the Free Software Foundation, either version 3 of the License, or</span>
<span class="comment">// (at your option) any later version.</span>
<span class="comment">//</span>
<span class="comment">// GNU uCommon C++ is distributed in the hope that it will be useful,</span>
<span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment">// GNU Lesser General Public License for more details.</span>
<span class="comment">//</span>
<span class="comment">// You should have received a copy of the GNU Lesser General Public License</span>
<span class="comment">// along with GNU uCommon C++.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>

<span class="preprocessor">#ifndef DEBUG</span>
<span class="preprocessor"></span><span class="preprocessor">#define DEBUG</span>
<span class="preprocessor"></span><span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="preprocessor">#include &lt;<a class="code" href="a00202.html" title="Top level include file for the GNU uCommon C++ core library.">ucommon/ucommon.h</a>&gt;</span>

<span class="preprocessor">#include &lt;stdio.h&gt;</span>

<span class="keyword">using namespace </span>UCOMMON_NAMESPACE;

<span class="keyword">typedef</span> <a name="_a0"></a><a class="code" href="a00062.html" title="Template value class to embed data structure into a linked list.">linked_value&lt;int&gt;</a> ints;

<span class="keyword">static</span> <a name="_a1"></a><a class="code" href="a00098.html" title="An index container for maintaining an ordered list of objects.">OrderedIndex</a> list;

<span class="keyword">class </span>member : <span class="keyword">public</span> <a name="_a2"></a><a class="code" href="a00045.html" title="A double-linked Object, used for certain kinds of lists.">DLinkedObject</a>
{
<span class="keyword">public</span>:
    <span class="keyword">inline</span> member(<span class="keywordtype">unsigned</span> v) : <a class="code" href="a00045.html" title="A double-linked Object, used for certain kinds of lists.">DLinkedObject</a>() {value = v;}

    <span class="keywordtype">unsigned</span> value;
};

<span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> <span class="keywordtype">int</span> main()
{
    <a name="_a3"></a><a class="code" href="a00061.html" title="A smart pointer template for iterating linked lists.">linked_pointer&lt;ints&gt;</a> ptr;
    <span class="keywordtype">unsigned</span> count = 0;
    <span class="comment">// Since value templates pass by reference, we must have referencable</span>
    <span class="comment">// objects or variables.  This avoids passing values by duplicating</span>
    <span class="comment">// objects onto the stack frame, though it causes problems for built-in</span>
    <span class="comment">// types...</span>
    <span class="keywordtype">int</span> xv = 3, xn = 5;
    ints v1(&amp;list, xv);
    ints v2(&amp;list);
    v2 = xn;

    ptr = &amp;list;
    <span class="keywordflow">while</span>(ptr) {
        <span class="keywordflow">switch</span>(++count)
        {
        <span class="keywordflow">case</span> 1:
            assert(ptr-&gt;value == 3);
            <span class="keywordflow">break</span>;
        <span class="keywordflow">case</span> 2:
            assert(ptr-&gt;value == 5);
        }
        ++ptr;
    }
    assert(count == 2);

    member ov1 = 1, ov2 = 2, ov3 = 3;

    assert(ov2.value == 2);

    <a class="code" href="a00187.html#a5de7558458f5f008710122bd706432f9" title="Convenience type for a stack of linked objects.">objstack_t</a> st;
    <a name="a4"></a><a class="code" href="a00180.html#aca6c5f30bf9139ccfa345dd68688bcad" title="Convenience function to push an object onto a stack.">push</a>(st, &amp;ov1);
    <a class="code" href="a00180.html#aca6c5f30bf9139ccfa345dd68688bcad" title="Convenience function to push an object onto a stack.">push</a>(st, &amp;ov2);
    <a class="code" href="a00180.html#aca6c5f30bf9139ccfa345dd68688bcad" title="Convenience function to push an object onto a stack.">push</a>(st, &amp;ov3);

    member *mv = (member *)<a name="a5"></a><a class="code" href="a00187.html#a7cc3128c4401e1eaf84dce788aa8b7be" title="Pop a linked object from a stack of linked objects.">pop</a>(st);
    assert(mv-&gt;value == 3);
    <a class="code" href="a00187.html#a7cc3128c4401e1eaf84dce788aa8b7be" title="Pop a linked object from a stack of linked objects.">pop</a>(st);
    <a class="code" href="a00187.html#a7cc3128c4401e1eaf84dce788aa8b7be" title="Pop a linked object from a stack of linked objects.">pop</a>(st);
    assert(NULL == <a class="code" href="a00187.html#a7cc3128c4401e1eaf84dce788aa8b7be" title="Pop a linked object from a stack of linked objects.">pop</a>(st));

    <a name="_a6"></a><a class="code" href="a00096.html" title="Template for typesafe basic object queue container.">objqueue&lt;member&gt;</a> que;
    que.<a name="a7"></a><a class="code" href="a00096.html#ae2032873c2c026c509c3c3c6bec88c61" title="Add an object to the end of the object queue.">add</a>(&amp;ov1);
    que.<a class="code" href="a00096.html#ae2032873c2c026c509c3c3c6bec88c61" title="Add an object to the end of the object queue.">add</a>(&amp;ov2);
    que.<a class="code" href="a00096.html#ae2032873c2c026c509c3c3c6bec88c61" title="Add an object to the end of the object queue.">add</a>(&amp;ov3);
    mv = que.<a name="a8"></a><a class="code" href="a00096.html#ab800bd4088c650f5d4eb6155c5e6fe13" title="Pop an object from the end of the object queue.">pop</a>();
    assert(mv-&gt;value == 3);
    mv = que.<a name="a9"></a><a class="code" href="a00096.html#a004193ad6673fa9e849c6fac48b5a224" title="Pull an object from the start of the object queue.">pull</a>();
    assert(mv != NULL);
<span class="comment">//  assert(mv-&gt;value == 1);</span>

    <span class="keywordflow">return</span> 0;
}
</pre></div> </div>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="footer">Generated on Wed Apr 13 2011 22:39:47 for ucommon by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li>
    </ul>
  </div>

</body>
</html>