blob: fdc9f5a83c991510ba0ed9c660f7806e025cdd35 [file] [log] [blame]
<!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>SGL: SkRefCnt.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.0 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">include</a>&nbsp;/&nbsp;<a class="el" href="dir_000001.html">skia</a></div>
<h1>SkRefCnt.h</h1><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifndef SkRefCnt_DEFINED</span>
00002 <span class="preprocessor"></span><span class="preprocessor">#define SkRefCnt_DEFINED</span>
00003 <span class="preprocessor"></span>
00004 <span class="preprocessor">#include "SkTypes.h"</span>
00005
<a name="l00015"></a><a class="code" href="classSkRefCnt.html">00015</a> <span class="keyword">class </span><a class="code" href="classSkRefCnt.html">SkRefCnt</a> {
00016 <span class="keyword">public</span>:
<a name="l00019"></a><a class="code" href="classSkRefCnt.html#a0">00019</a> <a class="code" href="classSkRefCnt.html#a0">SkRefCnt</a>() : fRefCnt(1) {}
<a name="l00022"></a><a class="code" href="classSkRefCnt.html#a1">00022</a> <span class="keyword">virtual</span> <a class="code" href="classSkRefCnt.html#a1">~SkRefCnt</a>() { SkASSERT(fRefCnt == 1); }
00023
<a name="l00026"></a><a class="code" href="classSkRefCnt.html#a2">00026</a> <span class="keywordtype">int</span> <a class="code" href="classSkRefCnt.html#a2">getRefCnt</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fRefCnt; }
<a name="l00029"></a><a class="code" href="classSkRefCnt.html#a3">00029</a> <span class="keywordtype">void</span> <a class="code" href="classSkRefCnt.html#a3">ref</a>()<span class="keyword"> const </span>{ SkASSERT(fRefCnt &gt; 0); ++fRefCnt; }
<a name="l00034"></a><a class="code" href="classSkRefCnt.html#a4">00034</a> <span class="keywordtype">void</span> <a class="code" href="classSkRefCnt.html#a4">unref</a>()<span class="keyword"> const</span>
00035 <span class="keyword"> </span>{
00036 SkASSERT(fRefCnt &gt; 0);
00037 <span class="keywordflow">if</span> (fRefCnt == 1)
00038 <span class="keyword">delete</span> <span class="keyword">this</span>;
00039 <span class="keywordflow">else</span>
00040 --fRefCnt;
00041 }
00042
<a name="l00046"></a><a class="code" href="classSkRefCnt.html#a5">00046</a> <span class="keywordtype">void</span> <a class="code" href="classSkRefCnt.html#a5">safeRef</a>()<span class="keyword"> const </span>{ <span class="keywordflow">if</span> (<span class="keyword">this</span>) this-&gt;<a class="code" href="classSkRefCnt.html#a3">ref</a>(); }
<a name="l00050"></a><a class="code" href="classSkRefCnt.html#a6">00050</a> <span class="keywordtype">void</span> <a class="code" href="classSkRefCnt.html#a6">safeUnref</a>()<span class="keyword"> const </span>{ <span class="keywordflow">if</span> (<span class="keyword">this</span>) this-&gt;<a class="code" href="classSkRefCnt.html#a4">unref</a>(); }
00051
00052 <span class="keyword">private</span>:
00053 <span class="keyword">mutable</span> <span class="keywordtype">int</span> fRefCnt;
00054 };
00055
<a name="l00061"></a><a class="code" href="classSkAutoUnref.html">00061</a> <span class="keyword">class </span><a class="code" href="classSkAutoUnref.html">SkAutoUnref</a> {
00062 <span class="keyword">public</span>:
00063 <a class="code" href="classSkAutoUnref.html">SkAutoUnref</a>(<a class="code" href="classSkRefCnt.html">SkRefCnt</a>* obj) : fObj(obj) {}
00064 ~<a class="code" href="classSkAutoUnref.html">SkAutoUnref</a>();
00065
00066 <a class="code" href="classSkRefCnt.html">SkRefCnt</a>* get()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> fObj; }
00067 <span class="keywordtype">bool</span> ref();
00068 <span class="keywordtype">bool</span> unref();
00069 <a class="code" href="classSkRefCnt.html">SkRefCnt</a>* detach();
00070
00071 <span class="keyword">private</span>:
00072 <a class="code" href="classSkRefCnt.html">SkRefCnt</a>* fObj;
00073 };
00074
00079 <span class="preprocessor">#define SkRefCnt_SafeAssign(dst, src) \</span>
00080 <span class="preprocessor"> do { \</span>
00081 <span class="preprocessor"> if (src) src-&gt;ref(); \</span>
00082 <span class="preprocessor"> if (dst) dst-&gt;unref(); \</span>
00083 <span class="preprocessor"> dst = src; \</span>
00084 <span class="preprocessor"> } while (0)</span>
00085 <span class="preprocessor"></span>
00086 <span class="preprocessor">#endif</span>
00087 <span class="preprocessor"></span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue May 9 14:35:23 2006 for SGL by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.0 </small></address>
</body>
</html>