<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>VTK: dox/Common/vtkWeakPointer.h 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.5.6 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <h1>dox/Common/vtkWeakPointer.h</h1><a href="a02168.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"></span> <a name="l00003"></a>00003 <span class="comment"> Program: Visualization Toolkit</span> <a name="l00004"></a>00004 <span class="comment"> Module: $RCSfile: vtkWeakPointer.h,v $</span> <a name="l00005"></a>00005 <span class="comment"></span> <a name="l00006"></a>00006 <span class="comment"> Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen</span> <a name="l00007"></a>00007 <span class="comment"> All rights reserved.</span> <a name="l00008"></a>00008 <span class="comment"> See Copyright.txt or http://www.kitware.com/Copyright.htm for details.</span> <a name="l00009"></a>00009 <span class="comment"></span> <a name="l00010"></a>00010 <span class="comment"> This software is distributed WITHOUT ANY WARRANTY; without even</span> <a name="l00011"></a>00011 <span class="comment"> the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR</span> <a name="l00012"></a>00012 <span class="comment"> PURPOSE. See the above copyright notice for more information.</span> <a name="l00013"></a>00013 <span class="comment"></span> <a name="l00014"></a>00014 <span class="comment">=========================================================================*/</span> <a name="l00024"></a>00024 <span class="preprocessor">#ifndef __vtkWeakPointer_h</span> <a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#define __vtkWeakPointer_h</span> <a name="l00026"></a>00026 <span class="preprocessor"></span> <a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="a02169.html">vtkWeakPointerBase.h</a>"</span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="keyword">template</span> <<span class="keyword">class</span> T> <a name="l00030"></a><a class="code" href="a01869.html">00030</a> <span class="keyword">class </span><a class="code" href="a01869.html" title="a weak reference to a vtkObject.">vtkWeakPointer</a>: <span class="keyword">public</span> <a class="code" href="a01870.html" title="Non-templated superclass for vtkWeakPointer.">vtkWeakPointerBase</a> <a name="l00031"></a>00031 { <a name="l00032"></a>00032 <span class="keyword">public</span>: <a name="l00034"></a><a class="code" href="a01869.html#cc59fdeb63d85a20bdf9ee16a6ed39c3">00034</a> <a class="code" href="a01869.html#cc59fdeb63d85a20bdf9ee16a6ed39c3">vtkWeakPointer</a>() {} <a name="l00035"></a>00035 <a name="l00037"></a><a class="code" href="a01869.html#f1b3f6c9ba9fbb4d37b8ed350094e333">00037</a> <a class="code" href="a01869.html#cc59fdeb63d85a20bdf9ee16a6ed39c3">vtkWeakPointer</a>(T* r): <a class="code" href="a01870.html" title="Non-templated superclass for vtkWeakPointer.">vtkWeakPointerBase</a>(r) {} <a name="l00038"></a>00038 <a name="l00040"></a><a class="code" href="a01869.html#4728a749aae9058f02c8233177a8f3d6">00040</a> <a class="code" href="a01869.html#cc59fdeb63d85a20bdf9ee16a6ed39c3">vtkWeakPointer</a>(<span class="keyword">const</span> <a class="code" href="a01870.html" title="Non-templated superclass for vtkWeakPointer.">vtkWeakPointerBase</a>& r): <a class="code" href="a01870.html" title="Non-templated superclass for vtkWeakPointer.">vtkWeakPointerBase</a>(r) {} <a name="l00041"></a>00041 <a name="l00043"></a>00043 <a name="l00044"></a><a class="code" href="a01869.html#7ed2217bbfa2b7d94e826c819828693f">00044</a> <a class="code" href="a01869.html" title="a weak reference to a vtkObject.">vtkWeakPointer</a>& <a class="code" href="a01869.html#7ed2217bbfa2b7d94e826c819828693f">operator=</a>(T* r) <a name="l00045"></a>00045 { <a name="l00046"></a>00046 this-><a class="code" href="a01870.html#50debb05379664333b315f2630f97d42">vtkWeakPointerBase::operator=</a>(r); <a name="l00047"></a>00047 <span class="keywordflow">return</span> *<span class="keyword">this</span>; <a name="l00048"></a>00048 } <a name="l00050"></a>00050 <a name="l00052"></a>00052 <a name="l00053"></a><a class="code" href="a01869.html#fc0c1f1f34f5eb68a2e1f81385324b52">00053</a> <a class="code" href="a01869.html" title="a weak reference to a vtkObject.">vtkWeakPointer</a>& <a class="code" href="a01869.html#7ed2217bbfa2b7d94e826c819828693f">operator=</a>(<span class="keyword">const</span> <a class="code" href="a01870.html" title="Non-templated superclass for vtkWeakPointer.">vtkWeakPointerBase</a>& r) <a name="l00054"></a>00054 { <a name="l00055"></a>00055 this-><a class="code" href="a01870.html#50debb05379664333b315f2630f97d42">vtkWeakPointerBase::operator=</a>(r); <a name="l00056"></a>00056 <span class="keywordflow">return</span> *<span class="keyword">this</span>; <a name="l00057"></a>00057 } <a name="l00059"></a>00059 <a name="l00061"></a>00061 <a name="l00062"></a><a class="code" href="a01869.html#120c06fe3bc24100982f85bb76f0048e">00062</a> T* <a class="code" href="a01869.html#120c06fe3bc24100982f85bb76f0048e">GetPointer</a>()<span class="keyword"> const</span> <a name="l00063"></a>00063 <span class="keyword"> </span>{ <a name="l00064"></a>00064 <span class="keywordflow">return</span> <span class="keyword">static_cast<</span>T*<span class="keyword">></span>(this-><a class="code" href="a01870.html#1e6a5d13318f1f914720aa344ef88604">Object</a>); <a name="l00065"></a>00065 } <a name="l00067"></a>00067 <a name="l00069"></a>00069 <a name="l00070"></a><a class="code" href="a01869.html#ef7802536807bf812c160bce7c2444a7">00070</a> <a class="code" href="a01869.html#ef7802536807bf812c160bce7c2444a7">operator T* </a>()<span class="keyword"> const</span> <a name="l00071"></a>00071 <span class="keyword"> </span>{ <a name="l00072"></a>00072 <span class="keywordflow">return</span> <span class="keyword">static_cast<</span>T*<span class="keyword">></span>(this-><a class="code" href="a01870.html#1e6a5d13318f1f914720aa344ef88604">Object</a>); <a name="l00073"></a>00073 } <a name="l00075"></a>00075 <a name="l00077"></a>00077 <a name="l00079"></a><a class="code" href="a01869.html#24786c8cc63ff67a9563d9d1a5aa9282">00079</a> T& <a class="code" href="a01869.html#24786c8cc63ff67a9563d9d1a5aa9282">operator*</a>()<span class="keyword"> const</span> <a name="l00080"></a>00080 <span class="keyword"> </span>{ <a name="l00081"></a>00081 <span class="keywordflow">return</span> *<span class="keyword">static_cast<</span>T*<span class="keyword">></span>(this-><a class="code" href="a01870.html#1e6a5d13318f1f914720aa344ef88604">Object</a>); <a name="l00082"></a>00082 } <a name="l00084"></a>00084 <a name="l00086"></a>00086 <a name="l00087"></a><a class="code" href="a01869.html#d6570bfb9a359b23a9f50742c3a82d5e">00087</a> T* <a class="code" href="a01869.html#d6570bfb9a359b23a9f50742c3a82d5e">operator-></a>()<span class="keyword"> const</span> <a name="l00088"></a>00088 <span class="keyword"> </span>{ <a name="l00089"></a>00089 <span class="keywordflow">return</span> <span class="keyword">static_cast<</span>T*<span class="keyword">></span>(this-><a class="code" href="a01870.html#1e6a5d13318f1f914720aa344ef88604">Object</a>); <a name="l00090"></a>00090 } <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="comment">// Work-around for HP and IBM overload resolution bug. Since</span> <a name="l00094"></a>00094 <span class="comment">// NullPointerOnly is a private type the only pointer value that can</span> <a name="l00095"></a>00095 <span class="comment">// be passed by user code is a null pointer. This operator will be</span> <a name="l00096"></a>00096 <span class="comment">// chosen by the compiler when comparing against null explicitly and</span> <a name="l00097"></a>00097 <span class="comment">// avoid the bogus ambiguous overload error.</span> <a name="l00098"></a>00098 <span class="preprocessor">#if defined(__HP_aCC) || defined(__IBMCPP__)</span> <a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor"># define VTK_WEAK_POINTER_DEFINE_OPERATOR_WORKAROUND(op) \</span> <a name="l00100"></a>00100 <span class="preprocessor"> vtkstd_bool operator op (NullPointerOnly*) const \</span> <a name="l00101"></a>00101 <span class="preprocessor"> { \</span> <a name="l00102"></a>00102 <span class="preprocessor"> return ::operator op (*this, 0); \</span> <a name="l00103"></a>00103 <span class="preprocessor"> }</span> <a name="l00104"></a>00104 <span class="preprocessor"></span><span class="keyword">private</span>: <a name="l00105"></a>00105 <span class="keyword">class </span>NullPointerOnly {}; <a name="l00106"></a>00106 <span class="keyword">public</span>: <a name="l00107"></a>00107 VTK_WEAK_POINTER_DEFINE_OPERATOR_WORKAROUND(==) <a name="l00108"></a>00108 VTK_WEAK_POINTER_DEFINE_OPERATOR_WORKAROUND(!=) <a name="l00109"></a>00109 VTK_WEAK_POINTER_DEFINE_OPERATOR_WORKAROUND(<) <a name="l00110"></a>00110 VTK_WEAK_POINTER_DEFINE_OPERATOR_WORKAROUND(<=) <a name="l00111"></a>00111 VTK_WEAK_POINTER_DEFINE_OPERATOR_WORKAROUND(>) <a name="l00112"></a>00112 VTK_WEAK_POINTER_DEFINE_OPERATOR_WORKAROUND(>=) <a name="l00113"></a>00113 <span class="preprocessor"># undef VTK_WEAK_POINTER_DEFINE_OPERATOR_WORKAROUND</span> <a name="l00114"></a>00114 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00115"></a>00115 <span class="preprocessor"></span><span class="keyword">protected</span>: <a name="l00116"></a><a class="code" href="a01869.html#d17cd51b9eacc4e076ce9217ed0f880e">00116</a> <a class="code" href="a01869.html#cc59fdeb63d85a20bdf9ee16a6ed39c3">vtkWeakPointer</a>(T* r, <span class="keyword">const</span> <a class="code" href="a01871.html">NoReference</a>& n): <a class="code" href="a01870.html" title="Non-templated superclass for vtkWeakPointer.">vtkWeakPointerBase</a>(r, n) {} <a name="l00117"></a>00117 <span class="keyword">private</span>: <a name="l00118"></a>00118 <span class="comment">// These are purposely not implemented to prevent callers from</span> <a name="l00119"></a>00119 <span class="comment">// trying to take references from other smart pointers.</span> <a name="l00120"></a>00120 <span class="keywordtype">void</span> TakeReference(<span class="keyword">const</span> <a class="code" href="a01870.html" title="Non-templated superclass for vtkWeakPointer.">vtkWeakPointerBase</a>&); <span class="comment">// Not implemented.</span> <a name="l00121"></a>00121 <span class="keyword">static</span> <span class="keywordtype">void</span> Take(<span class="keyword">const</span> <a class="code" href="a01870.html" title="Non-templated superclass for vtkWeakPointer.">vtkWeakPointerBase</a>&); <span class="comment">// Not implemented.</span> <a name="l00122"></a>00122 }; <a name="l00123"></a>00123 <a name="l00124"></a><a class="code" href="a02168.html#d347c053a366bfe54d3d1def7a087116">00124</a> <span class="preprocessor">#define VTK_WEAK_POINTER_DEFINE_OPERATOR(op) \</span> <a name="l00125"></a>00125 <span class="preprocessor"> template <class T> \</span> <a name="l00126"></a>00126 <span class="preprocessor"> inline vtkstd_bool \</span> <a name="l00127"></a>00127 <span class="preprocessor"> operator op (const vtkWeakPointer<T>& l, const vtkWeakPointer<T>& r) \</span> <a name="l00128"></a>00128 <span class="preprocessor"> { \</span> <a name="l00129"></a>00129 <span class="preprocessor"> return (l.GetPointer() op r.GetPointer()); \</span> <a name="l00130"></a>00130 <span class="preprocessor"> } \</span> <a name="l00131"></a>00131 <span class="preprocessor"> template <class T> \</span> <a name="l00132"></a>00132 <span class="preprocessor"> inline vtkstd_bool operator op (T* l, const vtkWeakPointer<T>& r) \</span> <a name="l00133"></a>00133 <span class="preprocessor"> { \</span> <a name="l00134"></a>00134 <span class="preprocessor"> return (l op r.GetPointer()); \</span> <a name="l00135"></a>00135 <span class="preprocessor"> } \</span> <a name="l00136"></a>00136 <span class="preprocessor"> template <class T> \</span> <a name="l00137"></a>00137 <span class="preprocessor"> inline vtkstd_bool operator op (const vtkWeakPointer<T>& l, T* r) \</span> <a name="l00138"></a>00138 <span class="preprocessor"> { \</span> <a name="l00139"></a>00139 <span class="preprocessor"> return (l.GetPointer() op r); \</span> <a name="l00140"></a>00140 <span class="preprocessor"> }</span> <a name="l00141"></a>00141 <span class="preprocessor"></span> <a name="l00142"></a>00142 <a class="code" href="a02168.html#d347c053a366bfe54d3d1def7a087116">VTK_WEAK_POINTER_DEFINE_OPERATOR</a>(==) <a name="l00143"></a>00143 <a class="code" href="a02168.html#d347c053a366bfe54d3d1def7a087116">VTK_WEAK_POINTER_DEFINE_OPERATOR</a>(!=) <a name="l00144"></a>00144 <a class="code" href="a02168.html#d347c053a366bfe54d3d1def7a087116">VTK_WEAK_POINTER_DEFINE_OPERATOR</a>(<) <a name="l00145"></a>00145 <a class="code" href="a02168.html#d347c053a366bfe54d3d1def7a087116">VTK_WEAK_POINTER_DEFINE_OPERATOR</a>(<=) <a name="l00146"></a>00146 <a class="code" href="a02168.html#d347c053a366bfe54d3d1def7a087116">VTK_WEAK_POINTER_DEFINE_OPERATOR</a>(>) <a name="l00147"></a>00147 <a class="code" href="a02168.html#d347c053a366bfe54d3d1def7a087116">VTK_WEAK_POINTER_DEFINE_OPERATOR</a>(>=) <a name="l00148"></a>00148 <a name="l00149"></a>00149 <span class="preprocessor">#undef VTK_WEAK_POINTER_DEFINE_OPERATOR</span> <a name="l00150"></a>00150 <span class="preprocessor"></span> <a name="l00152"></a>00152 <a name="l00153"></a>00153 <span class="keyword">template</span> <<span class="keyword">class</span> T> <a name="l00154"></a><a class="code" href="a02168.html#1023d9682a4bff01cbe21554ed037308">00154</a> <span class="keyword">inline</span> ostream& operator << (ostream& os, const vtkWeakPointer<T>& p) <a name="l00156"></a>00156 { <a name="l00157"></a>00157 <span class="keywordflow">return</span> os << static_cast<const vtkWeakPointerBase&>(p); <a name="l00158"></a>00158 } <a name="l00159"></a>00159 <a name="l00160"></a>00160 <a name="l00161"></a>00161 <span class="preprocessor">#endif</span> <a name="l00162"></a>00162 <span class="preprocessor"></span> <a name="l00163"></a>00163 </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Wed Jun 3 18:35:13 2009 for VTK by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> </body> </html>