XQuilla/docs/simple-api/ReferenceCounted_8hpp-source.html
2020-02-17 22:05:20 +01:00

156 lines
17 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>XQilla Simple API: ReferenceCounted.hpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.6 -->
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="classes.html"><span>Classes</span></a></li>
<li id="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>
<li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
</ul></div>
<h1>ReferenceCounted.hpp</h1><a href="ReferenceCounted_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2001-2006</span>
<a name="l00003"></a>00003 <span class="comment"> * DecisionSoft Limited. All rights reserved.</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (c) 2004-2006</span>
<a name="l00005"></a>00005 <span class="comment"> * Progress Software Corporation. All rights reserved.</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright (c) 2004-2006</span>
<a name="l00007"></a>00007 <span class="comment"> * Oracle. All rights reserved.</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
<a name="l00009"></a>00009 <span class="comment"> * See the file LICENSE for redistribution information.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * $Id: ReferenceCounted.hpp,v 1.7 2006/11/01 16:37:12 jpcs Exp $</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013
<a name="l00014"></a>00014 <span class="preprocessor">#ifndef _REFERENCECOUNTED_HPP</span>
<a name="l00015"></a>00015 <span class="preprocessor"></span><span class="preprocessor">#define _REFERENCECOUNTED_HPP</span>
<a name="l00016"></a>00016 <span class="preprocessor"></span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;xqilla/framework/XQillaExport.hpp&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;<a class="code" href="MemoryManager_8hpp.html">xercesc/framework/MemoryManager.hpp</a>&gt;</span>
<a name="l00019"></a>00019
<a name="l00020"></a>00020 <span class="comment">// for null RefCountPointer instances</span>
<a name="l00021"></a><a class="code" href="ReferenceCounted_8hpp.html#0b9d38d36c9739bb9e286ea387daea2b">00021</a> <span class="preprocessor">#define NULLRCP ((void *)0)</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span>
<a name="l00024"></a><a class="code" href="classReferenceCounted.html">00024</a> <span class="keyword">class </span>XQILLA_API <a class="code" href="classReferenceCounted.html">ReferenceCounted</a>
<a name="l00025"></a>00025 {
<a name="l00026"></a>00026 <span class="keyword">public</span>:
<a name="l00027"></a><a class="code" href="classReferenceCounted.html#5dc30ae895897b5008dc71ea26f175a1">00027</a> <a class="code" href="classReferenceCounted.html">ReferenceCounted</a>()
<a name="l00028"></a>00028 : _ref_count(0) {}
<a name="l00029"></a><a class="code" href="classReferenceCounted.html#039b1f45b252a226c55598f31e3993cc">00029</a> <span class="keyword">virtual</span> ~<a class="code" href="classReferenceCounted.html">ReferenceCounted</a>() {}
<a name="l00030"></a>00030
<a name="l00032"></a><a class="code" href="classReferenceCounted.html#386d6aab0473c14a32ce81226b939cb3">00032</a> <span class="keywordtype">void</span> incrementRefCount()<span class="keyword"> const</span>
<a name="l00033"></a>00033 <span class="keyword"> </span>{
<a name="l00034"></a>00034 ++const_cast&lt;unsigned int&amp;&gt;(_ref_count);
<a name="l00035"></a>00035 }
<a name="l00036"></a>00036
<a name="l00038"></a><a class="code" href="classReferenceCounted.html#426ce234c4797e7150f44a9bb50537b5">00038</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> decrementRefCount()<span class="keyword"> const</span>
<a name="l00039"></a>00039 <span class="keyword"> </span>{
<a name="l00040"></a>00040 <span class="keywordflow">if</span>(--const_cast&lt;unsigned int&amp;&gt;(_ref_count) == 0) {
<a name="l00041"></a>00041 <span class="keyword">delete</span> <span class="keyword">this</span>;
<a name="l00042"></a>00042 }
<a name="l00043"></a>00043 }
<a name="l00044"></a>00044
<a name="l00045"></a>00045 <span class="keyword">protected</span>:
<a name="l00046"></a><a class="code" href="classReferenceCounted.html#09e5d033e5224cd8b94cdc061cb56fe0">00046</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> _ref_count; <span class="comment">// mutable</span>
<a name="l00047"></a>00047 };
<a name="l00048"></a>00048
<a name="l00050"></a><a class="code" href="classRefCountPointer.html">00050</a> <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt; <span class="keyword">class </span><a class="code" href="classRefCountPointer.html">RefCountPointer</a>
<a name="l00051"></a>00051 {
<a name="l00052"></a>00052 <span class="keyword">public</span>:
<a name="l00053"></a><a class="code" href="classRefCountPointer.html#19e599ede99710afeca89ba65cdcb2a1">00053</a> <a class="code" href="classRefCountPointer.html#19e599ede99710afeca89ba65cdcb2a1">RefCountPointer</a>(T *p = 0) : <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>(p)
<a name="l00054"></a>00054 {
<a name="l00055"></a>00055 <span class="keywordflow">if</span>(<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a> != 0) <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>-&gt;incrementRefCount();
<a name="l00056"></a>00056 }
<a name="l00057"></a>00057
<a name="l00058"></a><a class="code" href="classRefCountPointer.html#541717a9c467461b75ab8118ae6f9ed9">00058</a> <span class="keyword">template</span>&lt;<span class="keyword">class</span> T2&gt; <a class="code" href="classRefCountPointer.html#19e599ede99710afeca89ba65cdcb2a1">RefCountPointer</a>(<span class="keyword">const</span> <a class="code" href="classRefCountPointer.html">RefCountPointer&lt;T2&gt;</a> &amp;o) : <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>((T*)(T2*)o)
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060 <span class="keywordflow">if</span>(<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a> != 0) <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>-&gt;incrementRefCount();
<a name="l00061"></a>00061 }
<a name="l00062"></a>00062
<a name="l00063"></a><a class="code" href="classRefCountPointer.html#deb7f9624e9181b2b04950c38d4a8fce">00063</a> <a class="code" href="classRefCountPointer.html#19e599ede99710afeca89ba65cdcb2a1">RefCountPointer</a>(<span class="keyword">const</span> <a class="code" href="classRefCountPointer.html">RefCountPointer&lt;T&gt;</a> &amp;o) : <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>(o.<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>)
<a name="l00064"></a>00064 {
<a name="l00065"></a>00065 <span class="keywordflow">if</span>(<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a> != 0) <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>-&gt;incrementRefCount();
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067
<a name="l00068"></a><a class="code" href="classRefCountPointer.html#aed4cb34420ba9a5190e142cdb3c786d">00068</a> <a class="code" href="classRefCountPointer.html">RefCountPointer</a> &amp;<a class="code" href="classRefCountPointer.html#aed4cb34420ba9a5190e142cdb3c786d">operator=</a>(<span class="keyword">const</span> <a class="code" href="classRefCountPointer.html">RefCountPointer&lt;T&gt;</a> &amp;o)
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070 <span class="keywordflow">if</span>(<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a> != o.<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>) {
<a name="l00071"></a>00071 <span class="keywordflow">if</span>(<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a> != 0) <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>-&gt;decrementRefCount();
<a name="l00072"></a>00072 <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a> = o.<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>;
<a name="l00073"></a>00073 <span class="keywordflow">if</span>(<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a> != 0) <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>-&gt;incrementRefCount();
<a name="l00074"></a>00074 }
<a name="l00075"></a>00075 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00076"></a>00076 }
<a name="l00077"></a>00077
<a name="l00078"></a><a class="code" href="classRefCountPointer.html#15aac5f85305a123c357bbddf5030ef3">00078</a> <a class="code" href="classRefCountPointer.html#15aac5f85305a123c357bbddf5030ef3">~RefCountPointer</a>()
<a name="l00079"></a>00079 {
<a name="l00080"></a>00080 <span class="keywordflow">if</span>(<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a> != 0) <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>-&gt;decrementRefCount();
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082
<a name="l00083"></a><a class="code" href="classRefCountPointer.html#19c9fb1b8719f5b010c0943e3594296a">00083</a> T *<a class="code" href="classRefCountPointer.html#19c9fb1b8719f5b010c0943e3594296a">operator-&gt;</a>()<span class="keyword"> const</span>
<a name="l00084"></a>00084 <span class="keyword"> </span>{
<a name="l00085"></a>00085 <span class="keywordflow">return</span> <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>;
<a name="l00086"></a>00086 }
<a name="l00087"></a>00087
<a name="l00088"></a><a class="code" href="classRefCountPointer.html#6522f582ede5cc4a36fc990bf5165f7d">00088</a> <a class="code" href="classRefCountPointer.html#6522f582ede5cc4a36fc990bf5165f7d">operator T*</a>()<span class="keyword"> const</span>
<a name="l00089"></a>00089 <span class="keyword"> </span>{
<a name="l00090"></a>00090 <span class="keywordflow">return</span> <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>;
<a name="l00091"></a>00091 }
<a name="l00092"></a>00092
<a name="l00093"></a><a class="code" href="classRefCountPointer.html#ad04c84082534aa246546bd0c3355848">00093</a> T *<a class="code" href="classRefCountPointer.html#ad04c84082534aa246546bd0c3355848">get</a>()<span class="keyword"> const</span>
<a name="l00094"></a>00094 <span class="keyword"> </span>{
<a name="l00095"></a>00095 <span class="keywordflow">return</span> <a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>;
<a name="l00096"></a>00096 }
<a name="l00097"></a>00097
<a name="l00098"></a><a class="code" href="classRefCountPointer.html#62f15012bafcbe02f0dcdbd2c0a749ee">00098</a> <span class="keywordtype">bool</span> <a class="code" href="classRefCountPointer.html#62f15012bafcbe02f0dcdbd2c0a749ee">isNull</a>()<span class="keyword"> const</span>
<a name="l00099"></a>00099 <span class="keyword"> </span>{
<a name="l00100"></a>00100 <span class="keywordflow">return</span> (<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a> == 0);
<a name="l00101"></a>00101 }
<a name="l00102"></a>00102
<a name="l00103"></a><a class="code" href="classRefCountPointer.html#1de8e3bd6a0af6661047049983243e1c">00103</a> <span class="keywordtype">bool</span> <a class="code" href="classRefCountPointer.html#1de8e3bd6a0af6661047049983243e1c">notNull</a>()<span class="keyword"> const</span>
<a name="l00104"></a>00104 <span class="keyword"> </span>{
<a name="l00105"></a>00105 <span class="keywordflow">return</span> (<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a> != 0);
<a name="l00106"></a>00106 }
<a name="l00107"></a>00107
<a name="l00108"></a>00108 <span class="keyword">protected</span>:
<a name="l00109"></a><a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">00109</a> T *<a class="code" href="classRefCountPointer.html#bdad2242b59d285fe75208c5fed5a90a">_p</a>;
<a name="l00110"></a>00110 };
<a name="l00111"></a>00111
<a name="l00112"></a>00112 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T1, <span class="keyword">class</span> T2&gt;
<a name="l00113"></a><a class="code" href="ReferenceCounted_8hpp.html#579cc4195b4828fa122c6ba6871fbe43">00113</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="ReferenceCounted_8hpp.html#579cc4195b4828fa122c6ba6871fbe43">operator==</a>(<span class="keyword">const</span> <a class="code" href="classRefCountPointer.html">RefCountPointer&lt;T1&gt;</a> &amp;a, <span class="keyword">const</span> <a class="code" href="classRefCountPointer.html">RefCountPointer&lt;T2&gt;</a> &amp;b)
<a name="l00114"></a>00114 {
<a name="l00115"></a>00115 <span class="keywordflow">return</span> (<span class="keywordtype">void</span>*)(T1*)a == (<span class="keywordtype">void</span>*)(T2*)b;
<a name="l00116"></a>00116 }
<a name="l00117"></a>00117
<a name="l00118"></a>00118 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T1, <span class="keyword">class</span> T2&gt;
<a name="l00119"></a><a class="code" href="ReferenceCounted_8hpp.html#a9b8cf293c3af2483f499e2c1b2eb2f2">00119</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="ReferenceCounted_8hpp.html#a9b8cf293c3af2483f499e2c1b2eb2f2">operator!=</a>(<span class="keyword">const</span> <a class="code" href="classRefCountPointer.html">RefCountPointer&lt;T1&gt;</a> &amp;a, <span class="keyword">const</span> <a class="code" href="classRefCountPointer.html">RefCountPointer&lt;T2&gt;</a> &amp;b)
<a name="l00120"></a>00120 {
<a name="l00121"></a>00121 <span class="keywordflow">return</span> (<span class="keywordtype">void</span>*)(T1*)a != (<span class="keywordtype">void</span>*)(T2*)b;
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123
<a name="l00124"></a>00124 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00125"></a><a class="code" href="ReferenceCounted_8hpp.html#88d1774a3c96b055a9321c8f40e11a66">00125</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="ReferenceCounted_8hpp.html#579cc4195b4828fa122c6ba6871fbe43">operator==</a>(<span class="keyword">const</span> <a class="code" href="classRefCountPointer.html">RefCountPointer&lt;T&gt;</a> &amp;a, <span class="keywordtype">void</span> *b)
<a name="l00126"></a>00126 {
<a name="l00127"></a>00127 <span class="keywordflow">return</span> (T*)a == (T*)b;
<a name="l00128"></a>00128 }
<a name="l00129"></a>00129
<a name="l00130"></a>00130 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00131"></a><a class="code" href="ReferenceCounted_8hpp.html#1982d9cc460432086a45091e2e8324c9">00131</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="ReferenceCounted_8hpp.html#a9b8cf293c3af2483f499e2c1b2eb2f2">operator!=</a>(<span class="keyword">const</span> <a class="code" href="classRefCountPointer.html">RefCountPointer&lt;T&gt;</a> &amp;a, <span class="keywordtype">void</span> *b)
<a name="l00132"></a>00132 {
<a name="l00133"></a>00133 <span class="keywordflow">return</span> (T*)a != (T*)b;
<a name="l00134"></a>00134 }
<a name="l00135"></a>00135
<a name="l00136"></a>00136 <span class="preprocessor">#endif</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Dec 12 00:18:56 2006 for XQilla Simple API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>
</body>
</html>