Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 247b28499c443e092731ffba814075f2 > files > 1292

mpqc-html-2.3.1-9mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>MPQC: ref.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    </ul>
  </div>
<h1>ref.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//</span>
<a name="l00002"></a>00002 <span class="comment">// ref.h --- definitions of the reference counting classes</span>
<a name="l00003"></a>00003 <span class="comment">//</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (C) 1996 Limit Point Systems, Inc.</span>
<a name="l00005"></a>00005 <span class="comment">//</span>
<a name="l00006"></a>00006 <span class="comment">// Author: Curtis Janssen &lt;cljanss@limitpt.com&gt;</span>
<a name="l00007"></a>00007 <span class="comment">// Maintainer: LPS</span>
<a name="l00008"></a>00008 <span class="comment">//</span>
<a name="l00009"></a>00009 <span class="comment">// This file is part of the SC Toolkit.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// The SC Toolkit is free software; you can redistribute it and/or modify</span>
<a name="l00012"></a>00012 <span class="comment">// it under the terms of the GNU Library General Public License as published by</span>
<a name="l00013"></a>00013 <span class="comment">// the Free Software Foundation; either version 2, or (at your option)</span>
<a name="l00014"></a>00014 <span class="comment">// any later version.</span>
<a name="l00015"></a>00015 <span class="comment">//</span>
<a name="l00016"></a>00016 <span class="comment">// The SC Toolkit is distributed in the hope that it will be useful,</span>
<a name="l00017"></a>00017 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00018"></a>00018 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00019"></a>00019 <span class="comment">// GNU Library General Public License for more details.</span>
<a name="l00020"></a>00020 <span class="comment">//</span>
<a name="l00021"></a>00021 <span class="comment">// You should have received a copy of the GNU Library General Public License</span>
<a name="l00022"></a>00022 <span class="comment">// along with the SC Toolkit; see the file COPYING.LIB.  If not, write to</span>
<a name="l00023"></a>00023 <span class="comment">// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.</span>
<a name="l00024"></a>00024 <span class="comment">//</span>
<a name="l00025"></a>00025 <span class="comment">// The U.S. Government is granted a limited license as per AL 91-7.</span>
<a name="l00026"></a>00026 <span class="comment">//</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="comment">//   This is the main include file for the reference counting classes.</span>
<a name="l00029"></a>00029 <span class="comment">// This includes two other files: reftmpl.h and refmacr.h.  The</span>
<a name="l00030"></a>00030 <span class="comment">// former is a template declaration for the reference counted classes</span>
<a name="l00031"></a>00031 <span class="comment">// and the latter is generated from the former by a perl script and</span>
<a name="l00032"></a>00032 <span class="comment">// provides CPP macros that declare reference counting classes.</span>
<a name="l00033"></a>00033 <span class="comment">//</span>
<a name="l00034"></a>00034 <span class="comment">//   The behaviour of the package can be modified with the following five</span>
<a name="l00035"></a>00035 <span class="comment">// macros, each of which should be undefined, 0, or 1:</span>
<a name="l00036"></a>00036 <span class="comment">//</span>
<a name="l00037"></a>00037 <span class="comment">// REF_CHECK_STACK:  If this is 1 referenced objects are checked to see if they</span>
<a name="l00038"></a>00038 <span class="comment">// reside on the stack, in which case storage for the object is not managed,</span>
<a name="l00039"></a>00039 <span class="comment">// if management is enabled.  This feature can be confused by multiple threads</span>
<a name="l00040"></a>00040 <span class="comment">// and memory checking libraries.</span>
<a name="l00041"></a>00041 <span class="comment">//</span>
<a name="l00042"></a>00042 <span class="comment">// REF_MANAGE:  If this is 1 the manage and unmanage members are enabled.</span>
<a name="l00043"></a>00043 <span class="comment">//</span>
<a name="l00044"></a>00044 <span class="comment">// REF_CHECK_MAX_NREF:  If this is 1 the reference count is checked before</span>
<a name="l00045"></a>00045 <span class="comment">// it is incremented to make sure it isn't too big.</span>
<a name="l00046"></a>00046 <span class="comment">//</span>
<a name="l00047"></a>00047 <span class="comment">// REF_CHECK_MIN_NREF:  If this is 1 the reference count is checked before</span>
<a name="l00048"></a>00048 <span class="comment">// it is decremented to make sure it isn't already zero.</span>
<a name="l00049"></a>00049 <span class="comment">//</span>
<a name="l00050"></a>00050 <span class="comment">// REF_USE_LOCKS:  If this is 1 then critical regions are locked before they</span>
<a name="l00051"></a>00051 <span class="comment">// are entered.  This prevents erroneous behavior when multiple threads</span>
<a name="l00052"></a>00052 <span class="comment">// share reference counted objects.  This will slow down certain operations,</span>
<a name="l00053"></a>00053 <span class="comment">// so it should be set to 0 if your application does not need to be thread</span>
<a name="l00054"></a>00054 <span class="comment">// safe.</span>
<a name="l00055"></a>00055 <span class="comment">//</span>
<a name="l00056"></a>00056 <span class="comment">// If a macro is undefined, then the behaviour is architecture</span>
<a name="l00057"></a>00057 <span class="comment">// dependent--usually, the macro will be set to 1 in this case.</span>
<a name="l00058"></a>00058 <span class="comment">// For maximum efficiency and for normal operation after the program is</span>
<a name="l00059"></a>00059 <span class="comment">// debugged, compile with all of the above macros defined to zero.</span>
<a name="l00060"></a>00060 <span class="comment">// This can also be done with -DREF_OPTIMIZE.</span>
<a name="l00061"></a>00061 <span class="comment">//</span>
<a name="l00062"></a>00062 <span class="comment">//   An include file can be used to set these options as well.  This has</span>
<a name="l00063"></a>00063 <span class="comment">// the advantage that dependency checking will force an automatic</span>
<a name="l00064"></a>00064 <span class="comment">// recompile of all affected files if the options change.  The file</span>
<a name="l00065"></a>00065 <span class="comment">// &lt;scconfig.h&gt; will be include if -DHAVE_CONFIG_H is specified.</span>
<a name="l00066"></a>00066 <span class="comment">//</span>
<a name="l00067"></a>00067 <span class="comment">//   Note that all source code that uses references must be compiled with</span>
<a name="l00068"></a>00068 <span class="comment">// the same value REF_MANAGE.  Changing this can change the storage layout</span>
<a name="l00069"></a>00069 <span class="comment">// and the interpretation of the reference count data.</span>
<a name="l00070"></a>00070 
<a name="l00071"></a>00071 
<a name="l00072"></a>00072 <span class="preprocessor">#ifdef __GNUC__</span>
<a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">#pragma interface</span>
<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00075"></a>00075 <span class="preprocessor"></span>
<a name="l00076"></a>00076 <span class="preprocessor">#ifndef _util_ref_ref_h</span>
<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#define _util_ref_ref_h</span>
<a name="l00078"></a>00078 <span class="preprocessor"></span>
<a name="l00079"></a>00079 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00080"></a>00080 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00081"></a>00081 <span class="preprocessor">#include &lt;limits.h&gt;</span>
<a name="l00082"></a>00082 
<a name="l00083"></a>00083 <span class="preprocessor">#include &lt;util/ref/identity.h&gt;</span>
<a name="l00084"></a>00084 
<a name="l00085"></a>00085 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<a name="l00086"></a>00086 <span class="preprocessor"></span><span class="preprocessor">#include &lt;scconfig.h&gt;</span>
<a name="l00087"></a>00087 <span class="preprocessor">#endif</span>
<a name="l00088"></a>00088 <span class="preprocessor"></span>
<a name="l00089"></a>00089 <span class="preprocessor">#ifdef REF_OPTIMIZE</span>
<a name="l00090"></a>00090 <span class="preprocessor"></span><span class="preprocessor">#ifndef REF_CHECK_STACK</span>
<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor"># define REF_CHECK_STACK   0</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00093"></a>00093 <span class="preprocessor"></span><span class="preprocessor">#ifndef REF_MANAGE</span>
<a name="l00094"></a>00094 <span class="preprocessor"></span><span class="preprocessor"># define REF_MANAGE        0</span>
<a name="l00095"></a>00095 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00096"></a>00096 <span class="preprocessor"></span><span class="preprocessor">#ifndef REF_CHECK_MAX_NREF</span>
<a name="l00097"></a>00097 <span class="preprocessor"></span><span class="preprocessor"># define REF_CHECK_MAX_NREF 0</span>
<a name="l00098"></a>00098 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor">#ifndef REF_CHECK_MIN_NREF</span>
<a name="l00100"></a>00100 <span class="preprocessor"></span><span class="preprocessor"># define REF_CHECK_MIN_NREF 0</span>
<a name="l00101"></a>00101 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00102"></a>00102 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00103"></a>00103 <span class="preprocessor"></span>
<a name="l00104"></a>00104 <span class="preprocessor">#ifdef SUNMOS</span>
<a name="l00105"></a>00105 <span class="preprocessor"></span><span class="preprocessor">#ifndef REF_CHECK_STACK</span>
<a name="l00106"></a>00106 <span class="preprocessor"></span><span class="preprocessor">#define REF_CHECK_STACK 0</span>
<a name="l00107"></a>00107 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00108"></a>00108 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00109"></a>00109 <span class="preprocessor"></span><span class="preprocessor">#ifndef REF_CHECK_STACK</span>
<a name="l00110"></a>00110 <span class="preprocessor"></span><span class="preprocessor">#define REF_CHECK_STACK 0</span>
<a name="l00111"></a>00111 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00112"></a>00112 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00113"></a>00113 <span class="preprocessor"></span>
<a name="l00114"></a>00114 <span class="preprocessor">#ifndef REF_MANAGE</span>
<a name="l00115"></a>00115 <span class="preprocessor"></span><span class="preprocessor">#define REF_MANAGE 1</span>
<a name="l00116"></a>00116 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00117"></a>00117 <span class="preprocessor"></span>
<a name="l00118"></a>00118 <span class="preprocessor">#ifndef REF_CHECK_MAX_NREF</span>
<a name="l00119"></a>00119 <span class="preprocessor"></span><span class="preprocessor">#define REF_CHECK_MAX_NREF 1</span>
<a name="l00120"></a>00120 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00121"></a>00121 <span class="preprocessor"></span>
<a name="l00122"></a>00122 <span class="preprocessor">#ifndef REF_CHECK_MIN_NREF</span>
<a name="l00123"></a>00123 <span class="preprocessor"></span><span class="preprocessor">#define REF_CHECK_MIN_NREF 1</span>
<a name="l00124"></a>00124 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00125"></a>00125 <span class="preprocessor"></span>
<a name="l00126"></a>00126 <span class="preprocessor">#ifndef REF_USE_LOCKS</span>
<a name="l00127"></a>00127 <span class="preprocessor"></span><span class="preprocessor">#  if HAVE_STHREAD || HAVE_CREATETHREAD || HAVE_PTHREAD</span>
<a name="l00128"></a>00128 <span class="preprocessor"></span><span class="preprocessor">#    define REF_USE_LOCKS 1</span>
<a name="l00129"></a>00129 <span class="preprocessor"></span><span class="preprocessor">#  endif</span>
<a name="l00130"></a>00130 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00131"></a>00131 <span class="preprocessor"></span>
<a name="l00132"></a>00132 <span class="preprocessor">#ifndef REF_ALWAYS_USE_LOCKS</span>
<a name="l00133"></a>00133 <span class="preprocessor"></span><span class="preprocessor">#  define REF_ALWAYS_USE_LOCKS 1</span>
<a name="l00134"></a>00134 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00135"></a>00135 <span class="preprocessor"></span>
<a name="l00136"></a>00136 <span class="preprocessor">#if REF_CHECK_STACK</span>
<a name="l00137"></a>00137 <span class="preprocessor"></span><span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00138"></a>00138 <span class="preprocessor">#ifndef HAVE_SBRK_DEC</span>
<a name="l00139"></a>00139 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">"C"</span> <span class="keywordtype">void</span> * sbrk(ssize_t);
<a name="l00140"></a>00140 <span class="preprocessor">#endif</span>
<a name="l00141"></a>00141 <span class="preprocessor"></span><span class="preprocessor">#define DO_REF_CHECK_STACK(p) (((void*) (p) &gt; sbrk(0)) &amp;&amp; (p)-&gt;managed())</span>
<a name="l00142"></a>00142 <span class="preprocessor"></span><span class="preprocessor">#else // REF_CHECK_STACK</span>
<a name="l00143"></a>00143 <span class="preprocessor"></span><span class="preprocessor">#define DO_REF_CHECK_STACK(p) (0)</span>
<a name="l00144"></a>00144 <span class="preprocessor"></span><span class="preprocessor">#endif // REF_CHECK_STACK</span>
<a name="l00145"></a>00145 <span class="preprocessor"></span>
<a name="l00146"></a>00146 <span class="preprocessor">#if REF_MANAGE</span>
<a name="l00147"></a>00147 <span class="preprocessor"></span><span class="preprocessor">#define DO_REF_UNMANAGE(p) ((p)-&gt;unmanage())</span>
<a name="l00148"></a>00148 <span class="preprocessor"></span><span class="preprocessor">#else // REF_MANAGE</span>
<a name="l00149"></a>00149 <span class="preprocessor"></span><span class="preprocessor">#define DO_REF_UNMANAGE(p)</span>
<a name="l00150"></a>00150 <span class="preprocessor"></span><span class="preprocessor">#endif // REF_MANAGE</span>
<a name="l00151"></a>00151 <span class="preprocessor"></span>
<a name="l00152"></a>00152 <span class="preprocessor">#if REF_USE_LOCKS</span>
<a name="l00153"></a>00153 <span class="preprocessor"></span><span class="preprocessor">#define __REF_LOCK__(p) p-&gt;lock_ptr()</span>
<a name="l00154"></a>00154 <span class="preprocessor"></span><span class="preprocessor">#define __REF_UNLOCK__(p) p-&gt;unlock_ptr()</span>
<a name="l00155"></a>00155 <span class="preprocessor"></span><span class="preprocessor">#if REF_ALWAYS_USE_LOCKS</span>
<a name="l00156"></a>00156 <span class="preprocessor"></span><span class="preprocessor">#define __REF_INITLOCK__() use_locks(true)</span>
<a name="l00157"></a>00157 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00158"></a>00158 <span class="preprocessor"></span><span class="preprocessor">#define __REF_INITLOCK__() ref_lock_ = 0xff</span>
<a name="l00159"></a>00159 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00160"></a>00160 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00161"></a>00161 <span class="preprocessor"></span><span class="preprocessor">#define __REF_LOCK__(p)</span>
<a name="l00162"></a>00162 <span class="preprocessor"></span><span class="preprocessor">#define __REF_UNLOCK__(p)</span>
<a name="l00163"></a>00163 <span class="preprocessor"></span><span class="preprocessor">#define __REF_INITLOCK__()</span>
<a name="l00164"></a>00164 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00165"></a>00165 <span class="preprocessor"></span>
<a name="l00166"></a>00166 <span class="keyword">namespace </span>sc {
<a name="l00167"></a>00167 
<a name="l00168"></a>00168 <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> refcount_t;
<a name="l00169"></a>00169 
<a name="l00194"></a><a class="code" href="classsc_1_1RefCount.html">00194</a> <span class="keyword">class </span><a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a>: <span class="keyword">public</span> <a class="code" href="classsc_1_1Identity.html" title="Identity gives objects a unique identity and ordering relationship relative to all...">Identity</a> {
<a name="l00195"></a>00195   <span class="keyword">private</span>:
<a name="l00196"></a>00196 <span class="preprocessor">#if REF_MANAGE</span>
<a name="l00197"></a>00197 <span class="preprocessor"></span><span class="preprocessor">#  define REF_MAX_NREF (UINT_MAX - 1)</span>
<a name="l00198"></a>00198 <span class="preprocessor"></span><span class="preprocessor">#  define REF_MANAGED_CODE UINT_MAX</span>
<a name="l00199"></a>00199 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00200"></a>00200 <span class="preprocessor"></span><span class="preprocessor">#  define REF_MAX_NREF UINT_MAX</span>
<a name="l00201"></a>00201 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00202"></a>00202 <span class="preprocessor"></span>    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> _reference_count_;
<a name="l00203"></a>00203 <span class="preprocessor">#if REF_USE_LOCKS</span>
<a name="l00204"></a>00204 <span class="preprocessor"></span>    <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ref_lock_;
<a name="l00205"></a>00205 <span class="preprocessor">#endif</span>
<a name="l00206"></a>00206 <span class="preprocessor"></span>
<a name="l00207"></a>00207     <span class="keywordtype">void</span> error(<span class="keyword">const</span> <span class="keywordtype">char</span>*) <span class="keyword">const</span>;
<a name="l00208"></a>00208     <span class="keywordtype">void</span> too_many_refs() <span class="keyword">const</span>;
<a name="l00209"></a>00209     <span class="keywordtype">void</span> not_enough_refs() <span class="keyword">const</span>;
<a name="l00210"></a>00210   <span class="keyword">protected</span>:
<a name="l00211"></a>00211     <a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a>(): _reference_count_(0) {
<a name="l00212"></a>00212         __REF_INITLOCK__();
<a name="l00213"></a>00213         <span class="comment">//std::cout &lt;&lt; "ref_lock_ = " &lt;&lt; (int) ref_lock_ &lt;&lt; std::endl;</span>
<a name="l00214"></a>00214       }
<a name="l00215"></a>00215     <a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a>&amp;): _reference_count_(0) {
<a name="l00216"></a>00216         __REF_INITLOCK__();
<a name="l00217"></a>00217         <span class="comment">//std::cout &lt;&lt; "ref_lock_ = " &lt;&lt; (int) ref_lock_ &lt;&lt; std::endl;</span>
<a name="l00218"></a>00218       }
<a name="l00219"></a>00219 
<a name="l00220"></a>00220     <span class="comment">// Assigment should not overwrite the reference count.</span>
<a name="l00221"></a>00221     <a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a>&amp; operator=(<span class="keyword">const</span> <a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a>&amp;) { <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
<a name="l00222"></a>00222   <span class="keyword">public</span>:
<a name="l00223"></a>00223     <span class="keyword">virtual</span> ~<a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a>();
<a name="l00224"></a>00224 
<a name="l00226"></a>00226     <span class="keywordtype">int</span> <a class="code" href="classsc_1_1RefCount.html#1c8e9c58bf57dc265d9e842823494cb7" title="Lock this object.">lock_ptr</a>() <span class="keyword">const</span>;
<a name="l00228"></a>00228     <span class="keywordtype">int</span> <a class="code" href="classsc_1_1RefCount.html#65b50a51d8cb99d806323ffc934fa2c4" title="Unlock this object.">unlock_ptr</a>() <span class="keyword">const</span>;
<a name="l00229"></a>00229 
<a name="l00231"></a>00231     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1RefCount.html#f05189b4c9aff106cef46f1b4c00211a" title="start and stop using locks on this object">use_locks</a>(<span class="keywordtype">bool</span> inVal);
<a name="l00232"></a>00232 
<a name="l00234"></a><a class="code" href="classsc_1_1RefCount.html#e94a2d6c0083fc7ffd4c3e6e107ce839">00234</a>     refcount_t <a class="code" href="classsc_1_1RefCount.html#e94a2d6c0083fc7ffd4c3e6e107ce839" title="Return the reference count.">nreference</a>()<span class="keyword"> const </span>{
<a name="l00235"></a>00235 <span class="preprocessor">#       if REF_MANAGE</span>
<a name="l00236"></a>00236 <span class="preprocessor"></span>        <span class="keywordflow">if</span> (!managed()) <span class="keywordflow">return</span> 1;
<a name="l00237"></a>00237 <span class="preprocessor">#       endif</span>
<a name="l00238"></a>00238 <span class="preprocessor"></span>        <span class="keywordflow">return</span> _reference_count_;
<a name="l00239"></a>00239       }
<a name="l00240"></a>00240 
<a name="l00242"></a><a class="code" href="classsc_1_1RefCount.html#10326b12fc26912be4a78f1e709d16da">00242</a>     refcount_t <a class="code" href="classsc_1_1RefCount.html#10326b12fc26912be4a78f1e709d16da" title="Increment the reference count and return the new count.">reference</a>() {
<a name="l00243"></a>00243 <span class="preprocessor">#       if REF_MANAGE</span>
<a name="l00244"></a>00244 <span class="preprocessor"></span>        <span class="keywordflow">if</span> (!managed()) <span class="keywordflow">return</span> 1;
<a name="l00245"></a>00245 <span class="preprocessor">#       endif</span>
<a name="l00246"></a>00246 <span class="preprocessor"></span>        __REF_LOCK__(<span class="keyword">this</span>);
<a name="l00247"></a>00247 <span class="preprocessor">#       if REF_CHECK_MAX_NREF</span>
<a name="l00248"></a>00248 <span class="preprocessor"></span>        <span class="keywordflow">if</span> (_reference_count_ &gt;= REF_MAX_NREF) too_many_refs();
<a name="l00249"></a>00249 <span class="preprocessor">#       endif</span>
<a name="l00250"></a>00250 <span class="preprocessor"></span>        _reference_count_++;
<a name="l00251"></a>00251         refcount_t r = _reference_count_;
<a name="l00252"></a>00252         __REF_UNLOCK__(<span class="keyword">this</span>);
<a name="l00253"></a>00253         <span class="keywordflow">return</span> r;
<a name="l00254"></a>00254       }
<a name="l00255"></a>00255 
<a name="l00257"></a><a class="code" href="classsc_1_1RefCount.html#e391eb4734abf89fde3475bc9b013243">00257</a>     refcount_t <a class="code" href="classsc_1_1RefCount.html#e391eb4734abf89fde3475bc9b013243" title="Decrement the reference count and return the new count.">dereference</a>() {
<a name="l00258"></a>00258 <span class="preprocessor">#       if REF_MANAGE</span>
<a name="l00259"></a>00259 <span class="preprocessor"></span>        <span class="keywordflow">if</span> (!managed()) <span class="keywordflow">return</span> 1;
<a name="l00260"></a>00260 <span class="preprocessor">#       endif</span>
<a name="l00261"></a>00261 <span class="preprocessor"></span>        __REF_LOCK__(<span class="keyword">this</span>);
<a name="l00262"></a>00262 <span class="preprocessor">#       if REF_CHECK_MIN_NREF</span>
<a name="l00263"></a>00263 <span class="preprocessor"></span>        <span class="keywordflow">if</span> (_reference_count_ == 0) not_enough_refs();
<a name="l00264"></a>00264 <span class="preprocessor">#       endif</span>
<a name="l00265"></a>00265 <span class="preprocessor"></span>        _reference_count_--;
<a name="l00266"></a>00266         refcount_t r = _reference_count_;
<a name="l00267"></a>00267         __REF_UNLOCK__(<span class="keyword">this</span>);
<a name="l00268"></a>00268         <span class="keywordflow">return</span> r;
<a name="l00269"></a>00269       }
<a name="l00270"></a>00270 
<a name="l00271"></a>00271 <span class="preprocessor">#if REF_MANAGE</span>
<a name="l00272"></a>00272 <span class="preprocessor"></span>    <span class="keywordtype">int</span> managed()<span class="keyword"> const </span>{
<a name="l00273"></a>00273         <span class="keywordflow">return</span> _reference_count_ != REF_MANAGED_CODE;
<a name="l00274"></a>00274       }
<a name="l00280"></a><a class="code" href="classsc_1_1RefCount.html#e1ae4f1d5308822563eeafd0bdec0713">00280</a>     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1RefCount.html#e1ae4f1d5308822563eeafd0bdec0713" title="Turn off the reference counting mechanism for this object.">unmanage</a>() {
<a name="l00281"></a>00281         _reference_count_ = REF_MANAGED_CODE;
<a name="l00282"></a>00282       }
<a name="l00283"></a>00283 <span class="preprocessor">#else // REF_MANAGE</span>
<a name="l00285"></a><a class="code" href="classsc_1_1RefCount.html#25faf9649131022f7f67052aef3d3361">00285</a> <span class="preprocessor">    int managed() const { return 1; }</span>
<a name="l00286"></a>00286 <span class="preprocessor"></span><span class="preprocessor">#endif // REF_MANAGE</span>
<a name="l00287"></a>00287 <span class="preprocessor"></span>};
<a name="l00288"></a>00288 
<a name="l00292"></a><a class="code" href="classsc_1_1RefBase.html">00292</a> <span class="keyword">class </span><a class="code" href="classsc_1_1RefBase.html" title="Provides a few utility routines common to all Ref template instantiations.">RefBase</a> {
<a name="l00293"></a>00293   <span class="keyword">protected</span>:
<a name="l00295"></a>00295     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1RefBase.html#6f3713d1009ecb115ff1e0188100ef08" title="Print a warning message.">warn</a> ( <span class="keyword">const</span> <span class="keywordtype">char</span> * msg) <span class="keyword">const</span>;
<a name="l00297"></a>00297     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1RefBase.html#c1d072dc9626ac640cb278291a804f2b" title="Called when stack data is referenced.">warn_ref_to_stack</a>() <span class="keyword">const</span>;
<a name="l00299"></a>00299     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1RefBase.html#47977f711ffaee1ddc3e7e06fa3d80e5" title="Called when the deletion of stack data is skipped.">warn_skip_stack_delete</a>() <span class="keyword">const</span>;
<a name="l00301"></a>00301     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1RefBase.html#fbf2a4871cee20b5af5cb21a25ebeb67" title="Called when the reference count is corrupted.">warn_bad_ref_count</a>() <span class="keyword">const</span>;
<a name="l00303"></a>00303     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1RefBase.html#7be608c96a861a724e6a9596727ccbf7" title="Print information about the reference.">ref_info</a>(<a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a>*p,std::ostream&amp; os) <span class="keyword">const</span>;
<a name="l00304"></a>00304     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1RefBase.html#7be608c96a861a724e6a9596727ccbf7" title="Print information about the reference.">ref_info</a>(std::ostream&amp; os) <span class="keyword">const</span>;
<a name="l00305"></a>00305     <span class="keywordtype">void</span> check_pointer() <span class="keyword">const</span>;
<a name="l00306"></a>00306     <span class="keywordtype">void</span> reference(<a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a> *);
<a name="l00307"></a>00307     <span class="keywordtype">int</span> dereference(<a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a> *);
<a name="l00308"></a>00308   <span class="keyword">public</span>:
<a name="l00309"></a>00309     <a class="code" href="classsc_1_1RefBase.html" title="Provides a few utility routines common to all Ref template instantiations.">RefBase</a>() {};
<a name="l00310"></a>00310     <span class="keyword">virtual</span> ~<a class="code" href="classsc_1_1RefBase.html" title="Provides a few utility routines common to all Ref template instantiations.">RefBase</a>();
<a name="l00312"></a>00312     <span class="keyword">virtual</span> <a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a>* <a class="code" href="classsc_1_1RefBase.html#8c7856c35d7593330711aebf76cc46ad" title="Returns the DescribedClass pointer for the contained object.">parentpointer</a>() <span class="keyword">const</span> = 0;
<a name="l00315"></a>00315     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1RefBase.html#4cb3ca60ed22e390185b769e0de65553" title="Requires that a nonnull reference is held.">require_nonnull</a>() <span class="keyword">const</span>;
<a name="l00316"></a>00316 };
<a name="l00317"></a>00317 
<a name="l00331"></a>00331 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00332"></a><a class="code" href="classsc_1_1Ref.html">00332</a> <span class="keyword">class  </span><a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref</a>  : <span class="keyword">public</span> <a class="code" href="classsc_1_1RefBase.html" title="Provides a few utility routines common to all Ref template instantiations.">RefBase</a> {
<a name="l00333"></a>00333   <span class="keyword">private</span>:
<a name="l00334"></a>00334     T* p;
<a name="l00335"></a>00335   <span class="keyword">public</span>:
<a name="l00337"></a><a class="code" href="classsc_1_1Ref.html#1828f4b9976b995d5c4c7aaf014f4328">00337</a>     <a class="code" href="classsc_1_1Ref.html#1828f4b9976b995d5c4c7aaf014f4328" title="Create a reference to a null object.">Ref</a>(): p(0) {}
<a name="l00339"></a><a class="code" href="classsc_1_1Ref.html#71cadabc8f9cdf09cf65c52200b2befa">00339</a>     <a class="code" href="classsc_1_1Ref.html#1828f4b9976b995d5c4c7aaf014f4328" title="Create a reference to a null object.">Ref</a>(T*a) : p(0)
<a name="l00340"></a>00340     {
<a name="l00341"></a>00341       <span class="keywordflow">if</span> (a) {
<a name="l00342"></a>00342           p = a;
<a name="l00343"></a>00343           reference(p);
<a name="l00344"></a>00344         }
<a name="l00345"></a>00345     }
<a name="l00347"></a><a class="code" href="classsc_1_1Ref.html#6fbb70d4053408850b9d98c055c93131">00347</a>     <a class="code" href="classsc_1_1Ref.html#1828f4b9976b995d5c4c7aaf014f4328" title="Create a reference to a null object.">Ref</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;T&gt;</a> &amp;a) : p(0)
<a name="l00348"></a>00348     {
<a name="l00349"></a>00349       <span class="keywordflow">if</span> (a.<a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a" title="Returns a pointer the reference counted object.">pointer</a>()) {
<a name="l00350"></a>00350           p = a.<a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a" title="Returns a pointer the reference counted object.">pointer</a>();
<a name="l00351"></a>00351           reference(p);
<a name="l00352"></a>00352         }
<a name="l00353"></a>00353     }
<a name="l00355"></a><a class="code" href="classsc_1_1Ref.html#f58abbc8993af51de6d977b2d6c16986">00355</a>     <span class="keyword">template</span> &lt;<span class="keyword">class</span> A&gt; <a class="code" href="classsc_1_1Ref.html#1828f4b9976b995d5c4c7aaf014f4328" title="Create a reference to a null object.">Ref</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;A&gt;</a> &amp;a): p(0)
<a name="l00356"></a>00356     {
<a name="l00357"></a>00357       <span class="keywordflow">if</span> (a.<a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a" title="Returns a pointer the reference counted object.">pointer</a>()) {
<a name="l00358"></a>00358           p = a.<a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a" title="Returns a pointer the reference counted object.">pointer</a>();
<a name="l00359"></a>00359           reference(p);
<a name="l00360"></a>00360         }
<a name="l00361"></a>00361     }
<a name="l00362"></a>00362 <span class="comment">//      /** Create a reference to the object a.  Do a</span>
<a name="l00363"></a>00363 <span class="comment">//          dynamic_cast to convert a to the appropiate type. */</span>
<a name="l00364"></a>00364 <span class="comment">//      Ref(const RefBase&amp;a) {</span>
<a name="l00365"></a>00365 <span class="comment">//          p = dynamic_cast&lt;T*&gt;(a.parentpointer());</span>
<a name="l00366"></a>00366 <span class="comment">//          reference(p);</span>
<a name="l00367"></a>00367 <span class="comment">//        }</span>
<a name="l00368"></a>00368 <span class="comment">//      /** Create a reference to the object a.  Do a</span>
<a name="l00369"></a>00369 <span class="comment">//          dynamic_cast to convert a to the appropiate type. */</span>
<a name="l00370"></a>00370 <span class="comment">//      Ref(RefCount*a): p(0) {</span>
<a name="l00371"></a>00371 <span class="comment">//        operator&lt;&lt;(a);</span>
<a name="l00372"></a>00372 <span class="comment">//        }</span>
<a name="l00375"></a><a class="code" href="classsc_1_1Ref.html#c9954e0540adfb9db1a981f10920a3d9">00375</a> <span class="comment"></span>    <a class="code" href="classsc_1_1Ref.html#c9954e0540adfb9db1a981f10920a3d9" title="Create a reference to the object a.">~Ref</a>()
<a name="l00376"></a>00376     {
<a name="l00377"></a>00377       <a class="code" href="classsc_1_1Ref.html#8f1905a797969203f9c6df42dde6e841" title="Refer to the null object.">clear</a>();
<a name="l00378"></a>00378     }
<a name="l00381"></a><a class="code" href="classsc_1_1Ref.html#ac90e0f3897f362d56a120df60b04e6c">00381</a>     T* <a class="code" href="classsc_1_1Ref.html#ac90e0f3897f362d56a120df60b04e6c" title="Returns the reference counted object.">operator-&gt;</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> p; }
<a name="l00383"></a><a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a">00383</a>     T* <a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a" title="Returns a pointer the reference counted object.">pointer</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> p; }
<a name="l00385"></a><a class="code" href="classsc_1_1Ref.html#a6f7841ef026f05f542c35da7d1daa07">00385</a>     <a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a> *<a class="code" href="classsc_1_1Ref.html#a6f7841ef026f05f542c35da7d1daa07" title="Implements the parentpointer pure virtual in the base class.">parentpointer</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> p; }
<a name="l00386"></a>00386 
<a name="l00387"></a>00387     operator T*()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> p; }
<a name="l00390"></a><a class="code" href="classsc_1_1Ref.html#525a11b03e7d697a53196e4e519c9880">00390</a>     T&amp; <a class="code" href="classsc_1_1Ref.html#525a11b03e7d697a53196e4e519c9880" title="Returns a C++ reference to the reference counted object.">operator *</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> *p; };
<a name="l00393"></a><a class="code" href="classsc_1_1Ref.html#f6d0fe28271ddfeef27b2fcba5488131">00393</a>     <span class="keywordtype">int</span> <a class="code" href="classsc_1_1Ref.html#f6d0fe28271ddfeef27b2fcba5488131" title="Return 1 if this is a reference to a null object.">null</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> p == 0; }
<a name="l00395"></a><a class="code" href="classsc_1_1Ref.html#d3e4fe174435299fb1444b8294513783">00395</a>     <span class="keywordtype">int</span> <a class="code" href="classsc_1_1Ref.html#d3e4fe174435299fb1444b8294513783" title="Return !null().">nonnull</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> p != 0; }
<a name="l00398"></a><a class="code" href="classsc_1_1Ref.html#abbb5e1be215f042352eb14192d264b2">00398</a>     <span class="keyword">template</span> &lt;<span class="keyword">class</span> A&gt; <span class="keywordtype">int</span> <a class="code" href="classsc_1_1Ref.html#abbb5e1be215f042352eb14192d264b2" title="A variety of ordering and equivalence operators are provided using the Identity class...">operator==</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;A&gt;</a>&amp;a)<span class="keyword"> const</span>
<a name="l00399"></a>00399 <span class="keyword">        </span>{ <span class="keywordflow">return</span> eq(p,a.<a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a" title="Returns a pointer the reference counted object.">pointer</a>()); }
<a name="l00400"></a>00400     <span class="keyword">template</span> &lt;<span class="keyword">class</span> A&gt; <span class="keywordtype">int</span> operator&gt;=(<span class="keyword">const</span> <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;A&gt;</a>&amp;a)<span class="keyword"> const</span>
<a name="l00401"></a>00401 <span class="keyword">        </span>{ <span class="keywordflow">return</span> ge(p,a.<a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a" title="Returns a pointer the reference counted object.">pointer</a>()); }
<a name="l00402"></a>00402     <span class="keyword">template</span> &lt;<span class="keyword">class</span> A&gt; <span class="keywordtype">int</span> operator&lt;=(const Ref&lt;A&gt;&amp;a) <span class="keyword">const</span>
<a name="l00403"></a>00403         { <span class="keywordflow">return</span> le(p,a.<a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a" title="Returns a pointer the reference counted object.">pointer</a>()); }
<a name="l00404"></a>00404     <span class="keyword">template</span> &lt;<span class="keyword">class</span> A&gt; <span class="keywordtype">int</span> operator&gt;(<span class="keyword">const</span> Ref&lt;A&gt;&amp;a)<span class="keyword"> const</span>
<a name="l00405"></a>00405 <span class="keyword">        </span>{ <span class="keywordflow">return</span> gt(p,a.pointer()); }
<a name="l00406"></a>00406     <span class="keyword">template</span> &lt;<span class="keyword">class</span> A&gt; <span class="keywordtype">int</span> operator&lt;(const Ref&lt;A&gt;&amp;a) <span class="keyword">const</span>
<a name="l00407"></a>00407         { <span class="keywordflow">return</span> lt(p,a.pointer()); }
<a name="l00408"></a>00408     <span class="keyword">template</span> &lt;<span class="keyword">class</span> A&gt; <span class="keywordtype">int</span> operator!=(<span class="keyword">const</span> Ref&lt;A&gt;&amp;a)<span class="keyword"> const</span>
<a name="l00409"></a>00409 <span class="keyword">        </span>{ <span class="keywordflow">return</span> ne(p,a.pointer()); }
<a name="l00412"></a><a class="code" href="classsc_1_1Ref.html#44e2a7a6b45c2683a21ee644e8e1c65a">00412</a>     <span class="keywordtype">int</span> <a class="code" href="classsc_1_1Ref.html#44e2a7a6b45c2683a21ee644e8e1c65a" title="Compare two objects returning -1, 0, or 1.">compare</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;T&gt;</a> &amp;a)<span class="keyword"> const </span>{
<a name="l00413"></a>00413       <span class="keywordflow">return</span> eq(p,a.p)?0:((lt(p,a.p)?-1:1));
<a name="l00414"></a>00414     }
<a name="l00416"></a><a class="code" href="classsc_1_1Ref.html#8f1905a797969203f9c6df42dde6e841">00416</a>     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1Ref.html#8f1905a797969203f9c6df42dde6e841" title="Refer to the null object.">clear</a>()
<a name="l00417"></a>00417     {
<a name="l00418"></a>00418       <span class="keywordflow">if</span> (p) {
<a name="l00419"></a>00419           <span class="keywordtype">int</span> ref = dereference(p);
<a name="l00420"></a>00420           <span class="keywordflow">if</span> (ref == 0)
<a name="l00421"></a>00421               <span class="keyword">delete</span> p;
<a name="l00422"></a>00422           p = 0;
<a name="l00423"></a>00423         }
<a name="l00424"></a>00424     }
<a name="l00426"></a><a class="code" href="classsc_1_1Ref.html#6dabfa060f52834ac0cb32917bac77e7">00426</a>     <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;T&gt;</a>&amp; <a class="code" href="classsc_1_1Ref.html#6dabfa060f52834ac0cb32917bac77e7" title="Assignment to c.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;T&gt;</a> &amp; c)
<a name="l00427"></a>00427     {
<a name="l00428"></a>00428       T *cp = c.<a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a" title="Returns a pointer the reference counted object.">pointer</a>();
<a name="l00429"></a>00429       <span class="keywordflow">if</span> (cp) {
<a name="l00430"></a>00430           cp-&gt;reference();
<a name="l00431"></a>00431           <a class="code" href="classsc_1_1Ref.html#8f1905a797969203f9c6df42dde6e841" title="Refer to the null object.">clear</a>();
<a name="l00432"></a>00432           p=cp;
<a name="l00433"></a>00433         }
<a name="l00434"></a>00434       <span class="keywordflow">else</span> {
<a name="l00435"></a>00435           <a class="code" href="classsc_1_1Ref.html#8f1905a797969203f9c6df42dde6e841" title="Refer to the null object.">clear</a>();
<a name="l00436"></a>00436         }
<a name="l00437"></a>00437       <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00438"></a>00438     }
<a name="l00440"></a><a class="code" href="classsc_1_1Ref.html#1344c7311cfe5b0dadd230fc7e386e9a">00440</a>     <span class="keyword">template</span> &lt;<span class="keyword">class</span> A&gt; <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;T&gt;</a>&amp; <a class="code" href="classsc_1_1Ref.html#6dabfa060f52834ac0cb32917bac77e7" title="Assignment to c.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;A&gt;</a> &amp; c)
<a name="l00441"></a>00441     {
<a name="l00442"></a>00442       A *cp = c.<a class="code" href="classsc_1_1Ref.html#3124e47ef37912b60d0c8b18f811c16a" title="Returns a pointer the reference counted object.">pointer</a>();
<a name="l00443"></a>00443       <span class="keywordflow">if</span> (cp) {
<a name="l00444"></a>00444           cp-&gt;reference();
<a name="l00445"></a>00445           <a class="code" href="classsc_1_1Ref.html#8f1905a797969203f9c6df42dde6e841" title="Refer to the null object.">clear</a>();
<a name="l00446"></a>00446           p=cp;
<a name="l00447"></a>00447         }
<a name="l00448"></a>00448       <span class="keywordflow">else</span> {
<a name="l00449"></a>00449           <a class="code" href="classsc_1_1Ref.html#8f1905a797969203f9c6df42dde6e841" title="Refer to the null object.">clear</a>();
<a name="l00450"></a>00450         }
<a name="l00451"></a>00451       <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00452"></a>00452     }
<a name="l00454"></a><a class="code" href="classsc_1_1Ref.html#ccaa563e6d7f84aa6c73970dfff50562">00454</a>     <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;T&gt;</a>&amp; <a class="code" href="classsc_1_1Ref.html#ccaa563e6d7f84aa6c73970dfff50562" title="Assignment to the object that a references using dynamic_cast.">operator&lt;&lt;</a>(<span class="keyword">const</span> <a class="code" href="classsc_1_1RefBase.html" title="Provides a few utility routines common to all Ref template instantiations.">RefBase</a>&amp;a) {
<a name="l00455"></a>00455         T* cr = <span class="keyword">dynamic_cast&lt;</span>T*<span class="keyword">&gt;</span>(a.<a class="code" href="classsc_1_1RefBase.html#8c7856c35d7593330711aebf76cc46ad" title="Returns the DescribedClass pointer for the contained object.">parentpointer</a>());
<a name="l00456"></a>00456         <span class="keywordflow">if</span> (cr) {
<a name="l00457"></a>00457             reference(cr);
<a name="l00458"></a>00458             <a class="code" href="classsc_1_1Ref.html#8f1905a797969203f9c6df42dde6e841" title="Refer to the null object.">clear</a>();
<a name="l00459"></a>00459           }
<a name="l00460"></a>00460         p = cr;
<a name="l00461"></a>00461         <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00462"></a>00462       }
<a name="l00466"></a><a class="code" href="classsc_1_1Ref.html#56d05df1a6e0f369b075ca3103c2abdf">00466</a>     <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;T&gt;</a>&amp; <a class="code" href="classsc_1_1Ref.html#56d05df1a6e0f369b075ca3103c2abdf" title="Assigns to the given base class pointer using dynamic_cast.">operator&lt;&lt;</a>(<a class="code" href="classsc_1_1RefCount.html" title="The base class for all reference counted objects.">RefCount</a> *a) {
<a name="l00467"></a>00467         T* cr = <span class="keyword">dynamic_cast&lt;</span>T*<span class="keyword">&gt;</span>(a);
<a name="l00468"></a>00468         <span class="keywordflow">if</span> (cr) <a class="code" href="classsc_1_1Ref.html#1de448176a708e014cd3f920f823d3cc" title="Assignment to cr.">assign_pointer</a>(cr);
<a name="l00469"></a>00469         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (a &amp;&amp; a-&gt;<a class="code" href="classsc_1_1RefCount.html#e94a2d6c0083fc7ffd4c3e6e107ce839" title="Return the reference count.">nreference</a>() &lt;= 0) <span class="keyword">delete</span> a;
<a name="l00470"></a>00470         <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00471"></a>00471       }
<a name="l00473"></a><a class="code" href="classsc_1_1Ref.html#e2464c3e4df7b366e93f1680b46d39ae">00473</a>     <a class="code" href="classsc_1_1Ref.html" title="A template class that maintains references counts.">Ref&lt;T&gt;</a>&amp; <a class="code" href="classsc_1_1Ref.html#6dabfa060f52834ac0cb32917bac77e7" title="Assignment to c.">operator=</a>(T* cr)
<a name="l00474"></a>00474     {
<a name="l00475"></a>00475       <a class="code" href="classsc_1_1Ref.html#1de448176a708e014cd3f920f823d3cc" title="Assignment to cr.">assign_pointer</a>(cr);
<a name="l00476"></a>00476       <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00477"></a>00477     }
<a name="l00479"></a><a class="code" href="classsc_1_1Ref.html#1de448176a708e014cd3f920f823d3cc">00479</a>     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1Ref.html#1de448176a708e014cd3f920f823d3cc" title="Assignment to cr.">assign_pointer</a>(T* cr)
<a name="l00480"></a>00480     {
<a name="l00481"></a>00481       <span class="keywordflow">if</span> (cr) {
<a name="l00482"></a>00482           <span class="keywordflow">if</span> (DO_REF_CHECK_STACK(cr)) {
<a name="l00483"></a>00483               DO_REF_UNMANAGE(cr);
<a name="l00484"></a>00484               <a class="code" href="classsc_1_1RefBase.html#c1d072dc9626ac640cb278291a804f2b" title="Called when stack data is referenced.">warn_ref_to_stack</a>();
<a name="l00485"></a>00485             }
<a name="l00486"></a>00486           cr-&gt;reference();
<a name="l00487"></a>00487         }
<a name="l00488"></a>00488       <a class="code" href="classsc_1_1Ref.html#8f1905a797969203f9c6df42dde6e841" title="Refer to the null object.">clear</a>();
<a name="l00489"></a>00489       p = cr;
<a name="l00490"></a>00490     }
<a name="l00492"></a><a class="code" href="classsc_1_1Ref.html#6bc17e0d67e20e242b72925a997ca53c">00492</a>     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1Ref.html#6bc17e0d67e20e242b72925a997ca53c" title="Check the validity of the pointer.">check_pointer</a>()<span class="keyword"> const</span>
<a name="l00493"></a>00493 <span class="keyword">    </span>{
<a name="l00494"></a>00494       <span class="keywordflow">if</span> (p &amp;&amp; p-&gt;nreference() &lt;= 0) {
<a name="l00495"></a>00495           <a class="code" href="classsc_1_1RefBase.html#fbf2a4871cee20b5af5cb21a25ebeb67" title="Called when the reference count is corrupted.">warn_bad_ref_count</a>();
<a name="l00496"></a>00496         }
<a name="l00497"></a>00497     }
<a name="l00499"></a><a class="code" href="classsc_1_1Ref.html#bfdbdc85b08acb445b3aaaf0275a99dd">00499</a>     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1Ref.html#bfdbdc85b08acb445b3aaaf0275a99dd" title="Print information about the reference to os.">ref_info</a>(std::ostream&amp; os)<span class="keyword"> const</span>
<a name="l00500"></a>00500 <span class="keyword">    </span>{
<a name="l00501"></a>00501       <a class="code" href="classsc_1_1Ref.html#bfdbdc85b08acb445b3aaaf0275a99dd" title="Print information about the reference to os.">RefBase::ref_info</a>(p,os);
<a name="l00502"></a>00502     }
<a name="l00504"></a><a class="code" href="classsc_1_1Ref.html#d25c0df45fc0682c2724dcc3c08f465e">00504</a>     <span class="keywordtype">void</span> <a class="code" href="classsc_1_1Ref.html#d25c0df45fc0682c2724dcc3c08f465e" title="Print a warning concerning the reference.">warn</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>*s)<span class="keyword"> const </span>{ <a class="code" href="classsc_1_1Ref.html#d25c0df45fc0682c2724dcc3c08f465e" title="Print a warning concerning the reference.">RefBase::warn</a>(s); }
<a name="l00505"></a>00505 };
<a name="l00506"></a>00506 
<a name="l00507"></a>00507 }
<a name="l00508"></a>00508 
<a name="l00509"></a>00509 <span class="preprocessor">#endif</span>
<a name="l00510"></a>00510 <span class="preprocessor"></span>
<a name="l00511"></a>00511 <span class="comment">// ///////////////////////////////////////////////////////////////////////////</span>
<a name="l00512"></a>00512 
<a name="l00513"></a>00513 <span class="comment">// Local Variables:</span>
<a name="l00514"></a>00514 <span class="comment">// mode: c++</span>
<a name="l00515"></a>00515 <span class="comment">// c-file-style: "CLJ"</span>
<a name="l00516"></a>00516 <span class="comment">// End:</span>
</pre></div></div>
<hr>
<address>
<small>

Generated at Wed Oct 14 14:12:11 2009 for <a
href="http://www.mpqc.org">MPQC</a>
2.3.1 using the documentation package <a
href="http://www.doxygen.org">Doxygen</a>
1.5.9.

</small>
</address>
</body>
</html>