blob: e82a89fe8954bc1cfa1e063e4d85171dc53ac0cc [file] [log] [blame]
<!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>oscl_mem_auto_ptr.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.18 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; </center>
<hr><h1>oscl_mem_auto_ptr.h</h1><a href="oscl__mem__auto__ptr_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/* -*- c++ -*- */</span>
00002 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
00003
00004 <span class="comment">// O S C L _ M E M _ A U T O _ P T R</span>
00005
00006 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
00007
00022 <span class="preprocessor">#ifndef OSCL_MEM_AUTO_PTR_H</span>
00023 <span class="preprocessor"></span><span class="preprocessor">#define OSCL_MEM_AUTO_PTR_H</span>
00024 <span class="preprocessor"></span>
00025 <span class="preprocessor">#ifndef OSCLCONFIG_MEMORY_H_INCLUDED</span>
00026 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="osclconfig__memory_8h.html">osclconfig_memory.h</a>"</span>
00027 <span class="preprocessor">#endif</span>
00028 <span class="preprocessor"></span>
00029 <span class="preprocessor">#ifndef OSCL_MEM_H_INCLUDED</span>
00030 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="oscl__mem_8h.html">oscl_mem.h</a>"</span>
00031 <span class="preprocessor">#endif</span>
00032 <span class="preprocessor"></span>
<a name="l00033"></a><a class="code" href="oscl__mem__auto__ptr_8h.html#a0">00033</a> <span class="preprocessor">#define OSCL_DISABLE_WARNING_TRUNCATE_DEBUG_MESSAGE</span>
<a name="l00034"></a><a class="code" href="group__osclmemory.html#a84">00034</a> <span class="preprocessor"></span><span class="preprocessor">#define OSCL_DISABLE_WARNING_RETURN_TYPE_NOT_UDT</span>
00035 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="osclconfig__compiler__warnings_8h.html">osclconfig_compiler_warnings.h</a>"</span>
<a name="l00053"></a><a class="code" href="classOSCLMemAutoPtr.html">00053</a> <span class="keyword">template</span> &lt; <span class="keyword">class</span> T, <span class="keyword">class</span> _Allocator = Oscl_TAlloc&lt;T, OsclMemAllocator&gt; &gt; <span class="keyword">class </span><a class="code" href="classOSCLMemAutoPtr.html">OSCLMemAutoPtr</a>
00054 {
00055 <span class="keyword">private</span>:
00056 T* _Ptr;
00057
00058
00059 <span class="keyword">public</span>:
<a name="l00060"></a><a class="code" href="classOSCLMemAutoPtr.html#m0">00060</a> <span class="keywordtype">bool</span> <a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a>;
00061
00062
<a name="l00067"></a><a class="code" href="classOSCLMemAutoPtr.html#a0">00067</a> <span class="keyword">explicit</span> <a class="code" href="classOSCLMemAutoPtr.html#a0">OSCLMemAutoPtr</a>(T* inPtr = 0) : _Ptr(inPtr), <a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a>(inPtr != 0) {};
00068
<a name="l00076"></a><a class="code" href="classOSCLMemAutoPtr.html#a1">00076</a> <a class="code" href="classOSCLMemAutoPtr.html#a0">OSCLMemAutoPtr</a>(<span class="keyword">const</span> <a class="code" href="classOSCLMemAutoPtr.html">OSCLMemAutoPtr&lt;T&gt;</a>&amp; _Y): <a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a>(_Y.<a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a>),
00077 _Ptr(_Y.<a class="code" href="classOSCLMemAutoPtr.html#a10">release</a>()) {};
00078
00079
<a name="l00093"></a><a class="code" href="classOSCLMemAutoPtr.html#a2">00093</a> <a class="code" href="classOSCLMemAutoPtr.html">OSCLMemAutoPtr&lt;T, _Allocator&gt;</a>&amp; <a class="code" href="classOSCLMemAutoPtr.html#a2">operator=</a>(<span class="keyword">const</span> <a class="code" href="classOSCLMemAutoPtr.html">OSCLMemAutoPtr&lt;T, _Allocator&gt;</a>&amp; _Y)
00094 {
00095 <span class="keywordflow">if</span> (<span class="keyword">this</span> != &amp;_Y)
00096 {
00097 <span class="keywordflow">if</span> (_Ptr != _Y.<a class="code" href="classOSCLMemAutoPtr.html#a9">get</a>())
00098 {
00099 <span class="keywordflow">if</span> (_Ownership)
00100 {
00101 _Allocator alloc;
00102 alloc.destroy(_Ptr);
00103 alloc.deallocate(_Ptr, 1);
00104 }
00105 <a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a> = _Y.<a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a>;
00106 }
00107 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (_Y.<a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a>)
00108 {
00109 <a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a> = <span class="keyword">true</span>;
00110 }
00111 _Ptr = _Y.<a class="code" href="classOSCLMemAutoPtr.html#a10">release</a>();
00112 }
00113 <span class="keywordflow">return</span> (*this);
00114 }
00115
<a name="l00121"></a><a class="code" href="classOSCLMemAutoPtr.html#a3">00121</a> <a class="code" href="classOSCLMemAutoPtr.html#a3">~OSCLMemAutoPtr</a>()
00122 {
00123 <span class="keywordflow">if</span> (_Ownership)
00124 {
00125 _Allocator alloc;
00126 alloc.destroy(_Ptr);
00127 alloc.deallocate(_Ptr, 1);
00128 }
00129 }
00130
<a name="l00138"></a><a class="code" href="classOSCLMemAutoPtr.html#a4">00138</a> T&amp; <a class="code" href="classOSCLMemAutoPtr.html#a4">operator*</a>()<span class="keyword"> const</span>
00139 <span class="keyword"> </span>{
00140 <span class="keywordflow">return</span> (*<a class="code" href="classOSCLMemAutoPtr.html#a9">get</a>());
00141 }
00142
<a name="l00150"></a><a class="code" href="classOSCLMemAutoPtr.html#a5">00150</a> T *<a class="code" href="classOSCLMemAutoPtr.html#a5">operator-&gt;</a>()<span class="keyword"> const</span>
00151 <span class="keyword"> </span>{
00152 <span class="keywordflow">return</span> (<a class="code" href="classOSCLMemAutoPtr.html#a9">get</a>());
00153 }
00154
00155
<a name="l00161"></a><a class="code" href="classOSCLMemAutoPtr.html#a6">00161</a> <span class="keywordtype">void</span> <a class="code" href="classOSCLMemAutoPtr.html#a6">takeOwnership</a>(T* ptr)
00162 {
00163 <span class="keywordflow">if</span> (_Ptr != ptr)
00164 {
00165 <span class="keywordflow">if</span> (_Ownership)
00166 {
00167 _Allocator alloc;
00168 alloc.destroy(_Ptr);
00169 alloc.deallocate(_Ptr, 1);
00170 }
00171 _Ptr = ptr;
00172 }
00173
00174 <span class="keywordflow">if</span> (_Ptr)
00175 {
00176 <a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a> = <span class="keyword">true</span>;
00177 }
00178 }
00179
<a name="l00180"></a><a class="code" href="classOSCLMemAutoPtr.html#d0">00180</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classOSCLMemAutoPtr.html#d0">deallocate</a>(T* ptr)
00181 {
00182 _Allocator alloc;
00183 alloc.destroy(ptr);
00184 alloc.deallocate(ptr, 1);
00185 }
00186
<a name="l00187"></a><a class="code" href="classOSCLMemAutoPtr.html#a7">00187</a> <span class="keywordtype">void</span> <a class="code" href="classOSCLMemAutoPtr.html#a7">allocate</a>(<a class="code" href="osclconfig__ansi__memory_8h.html#a1">oscl_memsize_t</a> size)
00188 {
00189 _Allocator alloc;
00190 <span class="keywordflow">if</span> (_Ptr &amp;&amp; <a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a>)
00191 {
00192 alloc.destroy(_Ptr);
00193 alloc.deallocate(_Ptr, 1);
00194 }
00195 _Ptr = alloc.ALLOCATE(size);
00196 <a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a> = <span class="keyword">true</span>;
00197 }
00198
<a name="l00204"></a><a class="code" href="classOSCLMemAutoPtr.html#a8">00204</a> <span class="keywordtype">void</span> <a class="code" href="classOSCLMemAutoPtr.html#a8">setWithoutOwnership</a>(T* ptr)
00205 {
00206 <span class="keywordflow">if</span> (_Ptr != ptr)
00207 {
00208 <span class="keywordflow">if</span> (_Ownership)
00209 {
00210 _Allocator alloc;
00211 alloc.destroy(_Ptr);
00212 alloc.deallocate(_Ptr, 1);
00213 }
00214 _Ptr = ptr;
00215 }
00216
00217 <a class="code" href="classOSCLMemAutoPtr.html#m0">_Ownership</a> = <span class="keyword">false</span>;
00218 }
00219
<a name="l00224"></a><a class="code" href="classOSCLMemAutoPtr.html#a9">00224</a> T *<a class="code" href="classOSCLMemAutoPtr.html#a9">get</a>()<span class="keyword"> const</span>
00225 <span class="keyword"> </span>{
00226 <span class="keywordflow">return</span> (_Ptr);
00227 }
00228
<a name="l00234"></a><a class="code" href="classOSCLMemAutoPtr.html#a10">00234</a> T *<a class="code" href="classOSCLMemAutoPtr.html#a10">release</a>()<span class="keyword"> const</span>
00235 <span class="keyword"> </span>{
00236 ((<a class="code" href="classOSCLMemAutoPtr.html">OSCLMemAutoPtr&lt;T&gt;</a> *)<span class="keyword">this</span>)-&gt;_Ownership = <span class="keyword">false</span>;
00237 <span class="keywordflow">return</span> (_Ptr);
00238 }
00239
00240 };
00241
00242 <span class="preprocessor">#endif //OSCL_MEM_AUTO_PTR_H</span>
00243 <span class="preprocessor"></span>
</pre></div><hr size="1"><img src="pvlogo_small.jpg"><address style="align: right;"><small>OSCL API</small>
<address style="align: left;"><small>Posting Version: OPENCORE_20090310 </small>
</small></address>
</body>
</html>