Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 68d373e54fb21da3730c08bede406633 > files > 820

libCommonC++1.9_3-devel-1.9.4-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>pointer.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.10 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
<hr><h1>pointer.h</h1><a href="pointer_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// Copyright (C) 2001 Open Source Telecom Corporation.</font>
00002 <font class="comment">//  </font>
00003 <font class="comment">// This program is free software; you can redistribute it and/or modify</font>
00004 <font class="comment">// it under the terms of the GNU General Public License as published by</font>
00005 <font class="comment">// the Free Software Foundation; either version 2 of the License, or</font>
00006 <font class="comment">// (at your option) any later version.</font>
00007 <font class="comment">// </font>
00008 <font class="comment">// This program is distributed in the hope that it will be useful,</font>
00009 <font class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00010 <font class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</font>
00011 <font class="comment">// GNU General Public License for more details.</font>
00012 <font class="comment">// </font>
00013 <font class="comment">// You should have received a copy of the GNU General Public License</font>
00014 <font class="comment">// along with this program; if not, write to the Free Software </font>
00015 <font class="comment">// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</font>
00016 <font class="comment">// </font>
00017 <font class="comment">// As a special exception to the GNU General Public License, permission is </font>
00018 <font class="comment">// granted for additional uses of the text contained in its release </font>
00019 <font class="comment">// of Common C++.</font>
00020 <font class="comment">// </font>
00021 <font class="comment">// The exception is that, if you link the Common C++ library with other</font>
00022 <font class="comment">// files to produce an executable, this does not by itself cause the</font>
00023 <font class="comment">// resulting executable to be covered by the GNU General Public License.</font>
00024 <font class="comment">// Your use of that executable is in no way restricted on account of</font>
00025 <font class="comment">// linking the Common C++ library code into it.</font>
00026 <font class="comment">// </font>
00027 <font class="comment">// This exception does not however invalidate any other reasons why</font>
00028 <font class="comment">// the executable file might be covered by the GNU General Public License.</font>
00029 <font class="comment">// </font>
00030 <font class="comment">// This exception applies only to the code released under the </font>
00031 <font class="comment">// name Common C++.  If you copy code from other releases into a copy of</font>
00032 <font class="comment">// Common C++, as the General Public License permits, the exception does</font>
00033 <font class="comment">// not apply to the code that you add in this way.  To avoid misleading</font>
00034 <font class="comment">// anyone as to the status of such modified files, you must delete</font>
00035 <font class="comment">// this exception notice from them.</font>
00036 <font class="comment">// </font>
00037 <font class="comment">// If you write modifications of your own for Common C++, it is your choice</font>
00038 <font class="comment">// whether to permit this exception to apply to your modifications.</font>
00039 <font class="comment">// If you do not wish that, delete this exception notice.  </font>
00040 
00041 <font class="keyword">namespace </font>ost {
00042 
00043 template &lt;class T&gt;
<a name="l00044"></a><a class="code" href="classost_1_1_pointer.html">00044</a> <font class="keyword">class </font>Pointer
00045 {
00046 <font class="keyword">protected</font>:
<a name="l00047"></a><a class="code" href="classost_1_1_pointer.html#n0">00047</a>         <font class="keywordtype">unsigned</font> *ptrCount;
<a name="l00048"></a><a class="code" href="classost_1_1_pointer.html#n1">00048</a>         T *ptrObject;
00049 
<a name="l00050"></a><a class="code" href="classost_1_1_pointer.html#b0">00050</a>         <font class="keywordtype">void</font> <a class="code" href="classost_1_1_pointer.html#b0">ptrDetach</a>(<font class="keywordtype">void</font>)<font class="keyword"></font>
00051 <font class="keyword">        </font>{
00052                 <font class="keywordflow">if</font>(ptrCount &amp;&amp; --(*ptrCount)==0)
00053                 {
00054                         <font class="keyword">delete</font> ptrObject;
00055                         <font class="keyword">delete</font> ptrCount;
00056                 }
00057                 ptrObject = NULL;
00058                 ptrCount = NULL;                
00059         }
00060 
00061 <font class="keyword">public</font>:
<a name="l00062"></a><a class="code" href="classost_1_1_pointer.html#a0">00062</a>         <font class="keyword">explicit</font> <a class="code" href="classost_1_1_pointer.html#a0">Pointer</a>(T* ptr = NULL) : ptrObject(ptr)
00063         {
00064                 ptrCount = <font class="keyword">new</font> <font class="keywordtype">unsigned</font>;
00065         }
00066         
<a name="l00067"></a><a class="code" href="classost_1_1_pointer.html#a1">00067</a>         <a class="code" href="classost_1_1_pointer.html#a0">Pointer</a>(<font class="keyword">const</font> Pointer&lt;T&gt; &amp;ref)<font class="keyword"></font>
00068 <font class="keyword">        </font>{
00069                 ptrObject = ref.ptrObject;
00070                 ptrCount = ref.ptrCount;
00071                 ++(*ptrCount);  
00072         }
00073 
<a name="l00074"></a><a class="code" href="classost_1_1_pointer.html#a2">00074</a>         <font class="keyword">inline</font> <font class="keyword">virtual</font> <a class="code" href="classost_1_1_pointer.html#a2">~Pointer</a>()<font class="keyword"></font>
00075 <font class="keyword">        </font>{
00076                 <a class="code" href="classost_1_1_pointer.html#b0">ptrDetach</a>();
00077         }
00078 
00079 
<a name="l00080"></a><a class="code" href="classost_1_1_pointer.html#a3">00080</a>         Pointer&amp; <a class="code" href="classost_1_1_pointer.html#a3">operator=</a>(<font class="keyword">const</font> Pointer&lt;T&gt; &amp;ref)<font class="keyword"></font>
00081 <font class="keyword">        </font>{
00082                 <font class="keywordflow">if</font>(<font class="keyword">this</font> != &amp;ref)
00083                 {
00084                         <a class="code" href="classost_1_1_pointer.html#b0">ptrDetach</a>();
00085                         ptrObject = ref.ptrObject;
00086                         ptrCount = ref.ptrCount;
00087                         ++(*ptrCount);
00088                 }
00089                 <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00090         }
00091 
<a name="l00092"></a><a class="code" href="classost_1_1_pointer.html#a4">00092</a>         <font class="keyword">inline</font> T&amp; <a class="code" href="classost_1_1_pointer.html#a4">operator*</a>()<font class="keyword"> const</font>
00093 <font class="keyword">                </font>{<font class="keywordflow">return</font> *ptrObject;};
00094 
<a name="l00095"></a><a class="code" href="classost_1_1_pointer.html#a5">00095</a>         <font class="keyword">inline</font> T* <a class="code" href="classost_1_1_pointer.html#a5">getObject</a>()<font class="keyword"> const</font>
00096 <font class="keyword">                </font>{<font class="keywordflow">return</font> ptrObject;};
00097 
<a name="l00098"></a><a class="code" href="classost_1_1_pointer.html#a6">00098</a>         <font class="keyword">inline</font> T* <a class="code" href="classost_1_1_pointer.html#a6">operator-&gt;</a>()<font class="keyword"> const</font>
00099 <font class="keyword">                </font>{<font class="keywordflow">return</font> ptrObject;};
00100 
<a name="l00101"></a><a class="code" href="classost_1_1_pointer.html#a7">00101</a>         <font class="keyword">inline</font> <font class="keywordtype">bool</font> <a class="code" href="classost_1_1_pointer.html#a7">operator!</a>()<font class="keyword"> const</font>
00102 <font class="keyword">                </font>{<font class="keywordflow">return</font> (*ptrCount == 1);}; 
00103 
<a name="l00104"></a><a class="code" href="classost_1_1_pointer.html#a8">00104</a>         <font class="keyword">inline</font> <font class="keywordtype">int</font> <a class="code" href="classost_1_1_pointer.html#a8">operator++</a>()<font class="keyword"> const</font>
00105 <font class="keyword">                </font>{<font class="keywordflow">return</font> ++(*ptrCount);};
00106 
<a name="l00107"></a><a class="code" href="classost_1_1_pointer.html#a9">00107</a>         <font class="keywordtype">int</font> <a class="code" href="classost_1_1_pointer.html#a9">operator--</a>()<font class="keyword"> const</font>
00108 <font class="keyword">        </font>{
00109                 <font class="keywordflow">if</font>(*ptrCount == 1) 
00110                 {
00111                         <font class="keyword">delete</font> <font class="keyword">this</font>;
00112                         <font class="keywordflow">return</font> 0;
00113                 }
00114                 <font class="keywordflow">return</font> --(*ptrCount);
00115         }
00116 };      
00117 
00118 };
</pre></div><hr><address><small>Generated at Fri Jan 4 18:51:45 2002 for CommonC++ by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.gif" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.10 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2001</small></address>
</body>
</html>