[651] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
| 2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
[472] | 3 | <title>mixpp: shared_ptr.h Source File</title> |
---|
[651] | 4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
| 5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
| 6 | </head><body> |
---|
| 7 | <!-- Generated by Doxygen 1.5.9 --> |
---|
[472] | 8 | <script type="text/javascript"> |
---|
| 9 | <!-- |
---|
| 10 | function changeDisplayState (e){ |
---|
| 11 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
| 12 | var button=this.firstChild; |
---|
| 13 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
| 14 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
| 15 | sectionDiv.style.display='block'; |
---|
| 16 | button.src='open.gif'; |
---|
| 17 | }else{ |
---|
| 18 | sectionDiv.style.display='none'; |
---|
| 19 | button.src='closed.gif'; |
---|
| 20 | } |
---|
| 21 | } |
---|
| 22 | function initDynSections(){ |
---|
| 23 | var divs=document.getElementsByTagName('div'); |
---|
| 24 | var sectionCounter=1; |
---|
| 25 | for(var i=0;i<divs.length-1;i++){ |
---|
| 26 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
| 27 | var header=divs[i]; |
---|
| 28 | var section=divs[i+1]; |
---|
| 29 | var button=header.firstChild; |
---|
| 30 | if (button!='IMG'){ |
---|
| 31 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
| 32 | button=document.createElement('img'); |
---|
| 33 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
| 34 | } |
---|
| 35 | header.style.cursor='pointer'; |
---|
| 36 | header.onclick=changeDisplayState; |
---|
| 37 | header.id='dynheader'+sectionCounter; |
---|
| 38 | button.src='closed.gif'; |
---|
| 39 | section.id='dynsection'+sectionCounter; |
---|
| 40 | section.style.display='none'; |
---|
| 41 | section.style.marginLeft='14px'; |
---|
| 42 | sectionCounter++; |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | window.onload = initDynSections; |
---|
| 47 | --> |
---|
| 48 | </script> |
---|
| 49 | <div class="navigation" id="top"> |
---|
| 50 | <div class="tabs"> |
---|
| 51 | <ul> |
---|
| 52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
| 53 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
| 54 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
| 55 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
| 56 | </ul> |
---|
| 57 | </div> |
---|
| 58 | <div class="tabs"> |
---|
| 59 | <ul> |
---|
| 60 | <li><a href="files.html"><span>File List</span></a></li> |
---|
| 61 | <li><a href="globals.html"><span>File Members</span></a></li> |
---|
| 62 | </ul> |
---|
| 63 | </div> |
---|
| 64 | <h1>shared_ptr.h</h1><a href="shared__ptr_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
| 65 | <a name="l00013"></a>00013 <span class="preprocessor">#ifndef shared_ptr_h</span> |
---|
| 66 | <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define shared_ptr_h</span> |
---|
| 67 | <a name="l00015"></a>00015 <span class="preprocessor"></span> |
---|
| 68 | <a name="l00016"></a>00016 <span class="preprocessor">#include <limits.h></span> |
---|
| 69 | <a name="l00017"></a>00017 <span class="preprocessor">#include <algorithm></span> |
---|
| 70 | <a name="l00018"></a>00018 <span class="preprocessor">#include <stdexcept></span> |
---|
| 71 | <a name="l00019"></a>00019 <span class="preprocessor">#include <string></span> |
---|
[651] | 72 | <a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="bdmerror_8h.html" title="BDM&#39;s exception-throwing macros.">bdmerror.h</a>"</span> |
---|
[472] | 73 | <a name="l00021"></a>00021 |
---|
| 74 | <a name="l00022"></a>00022 <span class="keyword">namespace </span>bdm { |
---|
| 75 | <a name="l00023"></a>00023 |
---|
[591] | 76 | <a name="l00033"></a>00033 <span class="keyword">template</span> <<span class="keyword">typename</span> T> |
---|
| 77 | <a name="l00034"></a><a class="code" href="classbdm_1_1shared__ptr.html">00034</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr</a> { |
---|
| 78 | <a name="l00035"></a>00035 <span class="keyword">template</span><<span class="keyword">class</span> U> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr</a>; |
---|
| 79 | <a name="l00036"></a>00036 |
---|
| 80 | <a name="l00037"></a>00037 <span class="keyword">private</span>: |
---|
| 81 | <a name="l00038"></a>00038 T *payload; |
---|
| 82 | <a name="l00039"></a>00039 <span class="keywordtype">unsigned</span> *refCnt; |
---|
| 83 | <a name="l00040"></a>00040 |
---|
| 84 | <a name="l00041"></a>00041 <span class="keyword">public</span>: |
---|
[651] | 85 | <a name="l00047"></a><a class="code" href="classbdm_1_1shared__ptr.html#66a4d41031e37618f1a9bb3c81814c11">00047</a> <a class="code" href="classbdm_1_1shared__ptr.html#66a4d41031e37618f1a9bb3c81814c11" title="Default constructor.">shared_ptr</a>() : |
---|
[591] | 86 | <a name="l00048"></a>00048 payload ( 0 ), |
---|
| 87 | <a name="l00049"></a>00049 refCnt ( 0 ) { |
---|
| 88 | <a name="l00050"></a>00050 } |
---|
| 89 | <a name="l00051"></a>00051 |
---|
[651] | 90 | <a name="l00058"></a><a class="code" href="classbdm_1_1shared__ptr.html#c8b7f0a813173581530c80d7ac4fc7c2">00058</a> <a class="code" href="classbdm_1_1shared__ptr.html#66a4d41031e37618f1a9bb3c81814c11" title="Default constructor.">shared_ptr</a> ( T *p ) : |
---|
[591] | 91 | <a name="l00059"></a>00059 payload ( p ), |
---|
| 92 | <a name="l00060"></a>00060 refCnt ( p ? new unsigned ( 1 ) : 0 ) { |
---|
| 93 | <a name="l00061"></a>00061 } |
---|
| 94 | <a name="l00062"></a>00062 |
---|
[651] | 95 | <a name="l00069"></a><a class="code" href="classbdm_1_1shared__ptr.html#357702d12bfd608a08b46e4a194aa4b5">00069</a> <a class="code" href="classbdm_1_1shared__ptr.html#66a4d41031e37618f1a9bb3c81814c11" title="Default constructor.">shared_ptr</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<T></a> &other ) : |
---|
[591] | 96 | <a name="l00070"></a>00070 payload ( other.payload ), |
---|
| 97 | <a name="l00071"></a>00071 refCnt ( other.refCnt ) { |
---|
| 98 | <a name="l00072"></a>00072 add_ref(); |
---|
| 99 | <a name="l00073"></a>00073 } |
---|
| 100 | <a name="l00074"></a>00074 |
---|
| 101 | <a name="l00084"></a>00084 <span class="keyword">template</span><<span class="keyword">typename</span> U> |
---|
[651] | 102 | <a name="l00085"></a><a class="code" href="classbdm_1_1shared__ptr.html#affa5b17385493f4102c52cf75d3b509">00085</a> <a class="code" href="classbdm_1_1shared__ptr.html#66a4d41031e37618f1a9bb3c81814c11" title="Default constructor.">shared_ptr</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr<U></a> &other ) : |
---|
[591] | 103 | <a name="l00086"></a>00086 payload ( other.payload ), |
---|
| 104 | <a name="l00087"></a>00087 refCnt ( other.refCnt ) { |
---|
| 105 | <a name="l00088"></a>00088 add_ref(); |
---|
| 106 | <a name="l00089"></a>00089 } |
---|
| 107 | <a name="l00090"></a>00090 |
---|
[651] | 108 | <a name="l00094"></a><a class="code" href="classbdm_1_1shared__ptr.html#79374842e417d2f64e449e374be4cfc1">00094</a> <a class="code" href="classbdm_1_1shared__ptr.html#79374842e417d2f64e449e374be4cfc1">~shared_ptr</a>() { |
---|
[591] | 109 | <a name="l00095"></a>00095 del_ref(); |
---|
| 110 | <a name="l00096"></a>00096 } |
---|
| 111 | <a name="l00097"></a>00097 |
---|
[651] | 112 | <a name="l00101"></a><a class="code" href="classbdm_1_1shared__ptr.html#55263b1c8efbd3f8fddf703e2c457f6c">00101</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<T></a> &<a class="code" href="classbdm_1_1shared__ptr.html#55263b1c8efbd3f8fddf703e2c457f6c" title="Assignment operator.">operator= </a>( <span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<T></a> &other ) { |
---|
[591] | 113 | <a name="l00102"></a>00102 other.add_ref(); |
---|
| 114 | <a name="l00103"></a>00103 del_ref(); |
---|
| 115 | <a name="l00104"></a>00104 |
---|
| 116 | <a name="l00105"></a>00105 payload = other.payload; |
---|
| 117 | <a name="l00106"></a>00106 refCnt = other.refCnt; |
---|
| 118 | <a name="l00107"></a>00107 |
---|
| 119 | <a name="l00108"></a>00108 <span class="keywordflow">return</span> *<span class="keyword">this</span>; |
---|
| 120 | <a name="l00109"></a>00109 } |
---|
| 121 | <a name="l00110"></a>00110 |
---|
[651] | 122 | <a name="l00115"></a><a class="code" href="classbdm_1_1shared__ptr.html#37ebcfb6750dd7b5630f1d2354c07a96">00115</a> T *<span class="keyword">get</span>() { |
---|
[591] | 123 | <a name="l00116"></a>00116 <span class="keywordflow">return</span> payload; |
---|
| 124 | <a name="l00117"></a>00117 } |
---|
| 125 | <a name="l00118"></a>00118 |
---|
[651] | 126 | <a name="l00124"></a><a class="code" href="classbdm_1_1shared__ptr.html#bcaae812868eacbad050beda465d2327">00124</a> T *<a class="code" href="classbdm_1_1shared__ptr.html#bcaae812868eacbad050beda465d2327">operator-></a>() { |
---|
| 127 | <a name="l00125"></a>00125 <span class="keywordflow">if</span> ( !payload) {abort();};<span class="comment">// "dereferencing NULL" );</span> |
---|
[591] | 128 | <a name="l00126"></a>00126 <span class="keywordflow">return</span> payload; |
---|
| 129 | <a name="l00127"></a>00127 } |
---|
| 130 | <a name="l00128"></a>00128 |
---|
[651] | 131 | <a name="l00132"></a><a class="code" href="classbdm_1_1shared__ptr.html#de38de837267becf5eed2839fea42c45">00132</a> T &<a class="code" href="classbdm_1_1shared__ptr.html#de38de837267becf5eed2839fea42c45">operator*</a>() { |
---|
| 132 | <a name="l00133"></a>00133 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> ( payload, <span class="stringliteral">"dereferencing NULL"</span> ); |
---|
[591] | 133 | <a name="l00134"></a>00134 <span class="keywordflow">return</span> *payload; |
---|
| 134 | <a name="l00135"></a>00135 } |
---|
[472] | 135 | <a name="l00136"></a>00136 |
---|
[651] | 136 | <a name="l00141"></a><a class="code" href="classbdm_1_1shared__ptr.html#fff45e4841b2921cd42ce0691f8c1196">00141</a> <span class="keyword">const</span> T* <span class="keyword">get</span>() <span class="keyword">const</span> { |
---|
[591] | 137 | <a name="l00142"></a>00142 <span class="keywordflow">return</span> payload; |
---|
| 138 | <a name="l00143"></a>00143 } |
---|
| 139 | <a name="l00144"></a>00144 |
---|
[651] | 140 | <a name="l00148"></a><a class="code" href="classbdm_1_1shared__ptr.html#d89ec7ceb318241d833c7d278444396d">00148</a> <span class="keyword">const</span> T *<a class="code" href="classbdm_1_1shared__ptr.html#d89ec7ceb318241d833c7d278444396d">operator-></a>()<span class="keyword"> const </span>{ |
---|
| 141 | <a name="l00149"></a>00149 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> ( payload, <span class="stringliteral">"dereferencing NULL"</span> ); |
---|
[591] | 142 | <a name="l00150"></a>00150 <span class="keywordflow">return</span> payload; |
---|
| 143 | <a name="l00151"></a>00151 } |
---|
[472] | 144 | <a name="l00152"></a>00152 |
---|
[651] | 145 | <a name="l00156"></a><a class="code" href="classbdm_1_1shared__ptr.html#de000a72fe73804aa26962432f264800">00156</a> <span class="keyword">const</span> T &<a class="code" href="classbdm_1_1shared__ptr.html#de000a72fe73804aa26962432f264800">operator*</a>()<span class="keyword"> const </span>{ |
---|
| 146 | <a name="l00157"></a>00157 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> ( payload, <span class="stringliteral">"dereferencing NULL"</span> ); |
---|
[591] | 147 | <a name="l00158"></a>00158 <span class="keywordflow">return</span> *payload; |
---|
| 148 | <a name="l00159"></a>00159 } |
---|
| 149 | <a name="l00160"></a>00160 |
---|
[651] | 150 | <a name="l00162"></a><a class="code" href="classbdm_1_1shared__ptr.html#338dbc6aa9fd95175abdc2df3ae2c284">00162</a> <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1shared__ptr.html#338dbc6aa9fd95175abdc2df3ae2c284" title="Returns use_count() == 1.">unique</a>()<span class="keyword"> const </span>{ |
---|
[591] | 151 | <a name="l00163"></a>00163 <span class="keywordflow">return</span> refCnt && ( *refCnt == 1 ); |
---|
| 152 | <a name="l00164"></a>00164 } |
---|
[472] | 153 | <a name="l00165"></a>00165 |
---|
[651] | 154 | <a name="l00171"></a><a class="code" href="classbdm_1_1shared__ptr.html#8e52b8887a4408c52b5263a5717343f2">00171</a> <span class="keywordtype">long</span> <a class="code" href="classbdm_1_1shared__ptr.html#8e52b8887a4408c52b5263a5717343f2">use_count</a>()<span class="keyword"> const </span>{ |
---|
[591] | 155 | <a name="l00172"></a>00172 <span class="keywordflow">return</span> refCnt ? *refCnt : 0; |
---|
[472] | 156 | <a name="l00173"></a>00173 } |
---|
[591] | 157 | <a name="l00174"></a>00174 |
---|
[651] | 158 | <a name="l00180"></a><a class="code" href="classbdm_1_1shared__ptr.html#6cac71bb600f9f7c6fbed9335fd22d37">00180</a> <a class="code" href="classbdm_1_1shared__ptr.html#6cac71bb600f9f7c6fbed9335fd22d37" title="Boolean cast.">operator bool</a>()<span class="keyword"> const </span>{ |
---|
[591] | 159 | <a name="l00181"></a>00181 <span class="keywordflow">return</span> !!payload; |
---|
| 160 | <a name="l00182"></a>00182 } |
---|
| 161 | <a name="l00183"></a>00183 |
---|
| 162 | <a name="l00190"></a>00190 <span class="keyword">template</span><<span class="keyword">typename</span> U> |
---|
[651] | 163 | <a name="l00191"></a><a class="code" href="classbdm_1_1shared__ptr.html#b3cd369b00369ab92456aa0645e8d560">00191</a> <a class="code" href="classbdm_1_1shared__ptr.html#b3cd369b00369ab92456aa0645e8d560" title="const cast">operator shared_ptr<const U></a>()<span class="keyword"> const </span>{ |
---|
[591] | 164 | <a name="l00192"></a>00192 <a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr<const U></a> cptr; |
---|
| 165 | <a name="l00193"></a>00193 cptr.refCnt = refCnt; |
---|
| 166 | <a name="l00194"></a>00194 cptr.payload = payload; |
---|
| 167 | <a name="l00195"></a>00195 add_ref(); |
---|
| 168 | <a name="l00196"></a>00196 <span class="keywordflow">return</span> cptr; |
---|
| 169 | <a name="l00197"></a>00197 } |
---|
| 170 | <a name="l00198"></a>00198 |
---|
[651] | 171 | <a name="l00202"></a><a class="code" href="classbdm_1_1shared__ptr.html#fca7fd588f8de50e7590357305b00984">00202</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1shared__ptr.html#fca7fd588f8de50e7590357305b00984" title="Efficient swap for shared_ptr.">swap</a> ( <a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr</a> &other ) { |
---|
| 172 | <a name="l00203"></a>00203 <a class="code" href="classbdm_1_1shared__ptr.html#fca7fd588f8de50e7590357305b00984" title="Efficient swap for shared_ptr.">std::swap</a> ( payload, other.payload ); |
---|
| 173 | <a name="l00204"></a>00204 <a class="code" href="classbdm_1_1shared__ptr.html#fca7fd588f8de50e7590357305b00984" title="Efficient swap for shared_ptr.">std::swap</a> ( refCnt, other.refCnt ); |
---|
[591] | 174 | <a name="l00205"></a>00205 } |
---|
| 175 | <a name="l00206"></a>00206 |
---|
| 176 | <a name="l00207"></a>00207 <span class="keyword">private</span>: |
---|
| 177 | <a name="l00208"></a>00208 <span class="keywordtype">void</span> add_ref()<span class="keyword"> const </span>{ |
---|
| 178 | <a name="l00209"></a>00209 <span class="keywordflow">if</span> ( refCnt ) { |
---|
| 179 | <a name="l00210"></a>00210 <span class="keywordflow">if</span> ( *refCnt == UINT_MAX ) { |
---|
| 180 | <a name="l00211"></a>00211 <span class="keywordflow">throw</span> std::overflow_error ( |
---|
[651] | 181 | <a name="l00212"></a>00212 std::string ( <span class="stringliteral">"Shared pointer has too many references."</span> ) ); |
---|
[591] | 182 | <a name="l00213"></a>00213 } |
---|
| 183 | <a name="l00214"></a>00214 |
---|
| 184 | <a name="l00215"></a>00215 ++*refCnt; |
---|
| 185 | <a name="l00216"></a>00216 } |
---|
| 186 | <a name="l00217"></a>00217 } |
---|
| 187 | <a name="l00218"></a>00218 |
---|
| 188 | <a name="l00219"></a>00219 <span class="keywordtype">void</span> del_ref() { |
---|
| 189 | <a name="l00220"></a>00220 <span class="keywordflow">if</span> ( refCnt ) { |
---|
| 190 | <a name="l00221"></a>00221 <span class="keywordflow">if</span> ( ! ( --*refCnt ) ) { |
---|
| 191 | <a name="l00222"></a>00222 <span class="keyword">delete</span> payload; |
---|
| 192 | <a name="l00223"></a>00223 <span class="keyword">delete</span> refCnt; |
---|
| 193 | <a name="l00224"></a>00224 } |
---|
| 194 | <a name="l00225"></a>00225 } |
---|
| 195 | <a name="l00226"></a>00226 } |
---|
| 196 | <a name="l00227"></a>00227 }; |
---|
| 197 | <a name="l00228"></a>00228 |
---|
| 198 | <a name="l00230"></a>00230 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U> |
---|
| 199 | <a name="l00231"></a>00231 <span class="keywordtype">bool</span> operator== ( shared_ptr<T> <span class="keyword">const</span> &a, shared_ptr<U> <span class="keyword">const</span> &b ) { |
---|
| 200 | <a name="l00232"></a>00232 <span class="keywordflow">return</span> a.get() == b.get(); |
---|
| 201 | <a name="l00233"></a>00233 } |
---|
| 202 | <a name="l00234"></a>00234 |
---|
| 203 | <a name="l00236"></a>00236 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U> |
---|
| 204 | <a name="l00237"></a>00237 <span class="keywordtype">bool</span> operator!= ( shared_ptr<T> <span class="keyword">const</span> &a, shared_ptr<U> <span class="keyword">const</span> &b ) { |
---|
| 205 | <a name="l00238"></a>00238 <span class="keywordflow">return</span> a.get() != b.get(); |
---|
| 206 | <a name="l00239"></a>00239 } |
---|
| 207 | <a name="l00240"></a>00240 |
---|
| 208 | <a name="l00242"></a>00242 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U> |
---|
| 209 | <a name="l00243"></a>00243 <span class="keywordtype">bool</span> operator< ( shared_ptr<T> <span class="keyword">const</span> &a, shared_ptr<U> <span class="keyword">const</span> &b ) { |
---|
| 210 | <a name="l00244"></a>00244 <span class="keywordflow">return</span> a.get() < b.get(); |
---|
| 211 | <a name="l00245"></a>00245 } |
---|
| 212 | <a name="l00246"></a>00246 |
---|
| 213 | <a name="l00254"></a>00254 <span class="keyword">template</span> <<span class="keyword">typename</span> T> |
---|
| 214 | <a name="l00255"></a><a class="code" href="classbdm_1_1object__ptr.html">00255</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1object__ptr.html" title="A wrapper of shared_ptr which is never empty.">object_ptr</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr</a><T> |
---|
| 215 | <a name="l00256"></a>00256 { |
---|
| 216 | <a name="l00257"></a>00257 <span class="keyword">public</span>: |
---|
[651] | 217 | <a name="l00263"></a><a class="code" href="classbdm_1_1object__ptr.html#9f1016ff2bbfa497d1cc0a4497c1fba4">00263</a> <a class="code" href="classbdm_1_1object__ptr.html#9f1016ff2bbfa497d1cc0a4497c1fba4" title="Default constructor.">object_ptr</a>() : <a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr</a><T> ( new T() ) { } |
---|
[591] | 218 | <a name="l00264"></a>00264 |
---|
[651] | 219 | <a name="l00270"></a><a class="code" href="classbdm_1_1object__ptr.html#dcb20017177c98274c16087b2c0067dc">00270</a> <a class="code" href="classbdm_1_1object__ptr.html#dcb20017177c98274c16087b2c0067dc" title="Upcast from shared_ptr&lt;T&gt; to object_ptr&lt;T&gt;.">object_ptr</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<T></a> &b ) : <a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr</a><T> ( b ) { |
---|
| 220 | <a name="l00271"></a>00271 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> ( this-><span class="keyword">get</span>(), <span class="stringliteral">"object_ptr cannot be empty"</span> ); |
---|
[591] | 221 | <a name="l00272"></a>00272 } |
---|
| 222 | <a name="l00273"></a>00273 |
---|
[651] | 223 | <a name="l00278"></a><a class="code" href="classbdm_1_1object__ptr.html#a9eb00600d8640711eadeed98c7892e9">00278</a> <a class="code" href="classbdm_1_1object__ptr.html#a9eb00600d8640711eadeed98c7892e9">object_ptr</a> ( T *p ) : <a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr</a><T> ( p ) { |
---|
| 224 | <a name="l00279"></a>00279 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> ( p, <span class="stringliteral">"object_ptr cannot be empty"</span> ); |
---|
[591] | 225 | <a name="l00280"></a>00280 } |
---|
| 226 | <a name="l00281"></a>00281 |
---|
[651] | 227 | <a name="l00285"></a><a class="code" href="classbdm_1_1object__ptr.html#9c80da05b7b3dfc59333ca9bf6f62970">00285</a> <a class="code" href="classbdm_1_1object__ptr.html" title="A wrapper of shared_ptr which is never empty.">object_ptr<T></a> &<a class="code" href="classbdm_1_1object__ptr.html#9c80da05b7b3dfc59333ca9bf6f62970" title="Assignment operator.">operator= </a>( <span class="keyword">const</span> <a class="code" href="classbdm_1_1object__ptr.html" title="A wrapper of shared_ptr which is never empty.">object_ptr<T></a> &other ) { |
---|
| 228 | <a name="l00286"></a>00286 <a class="code" href="classbdm_1_1object__ptr.html#9c80da05b7b3dfc59333ca9bf6f62970" title="Assignment operator.">shared_ptr<T>::operator= </a>( other ); |
---|
[591] | 229 | <a name="l00287"></a>00287 <span class="keywordflow">return</span> *<span class="keyword">this</span>; |
---|
| 230 | <a name="l00288"></a>00288 } |
---|
| 231 | <a name="l00289"></a>00289 }; |
---|
| 232 | <a name="l00290"></a>00290 |
---|
| 233 | <a name="l00291"></a>00291 <span class="preprocessor">#define SHAREDPTR(class_name) typedef bdm::object_ptr< class_name > class_name##_ptr</span> |
---|
| 234 | <a name="l00292"></a>00292 <span class="preprocessor"></span> |
---|
| 235 | <a name="l00293"></a>00293 <span class="preprocessor">#define SHAREDPTR2(template_class_name, template_parameter_name) typedef bdm::object_ptr< template_class_name < template_parameter_name > > template_class_name##_##template_parameter_name##_ptr</span> |
---|
| 236 | <a name="l00294"></a>00294 <span class="preprocessor"></span> |
---|
| 237 | <a name="l00295"></a>00295 } |
---|
| 238 | <a name="l00296"></a>00296 |
---|
| 239 | <a name="l00297"></a>00297 <span class="preprocessor">#endif</span> |
---|
[472] | 240 | </pre></div></div> |
---|
[651] | 241 | <hr size="1"><address style="text-align: right;"><small>Generated on Wed Oct 7 17:34:43 2009 for mixpp by |
---|
[472] | 242 | <a href="http://www.doxygen.org/index.html"> |
---|
[651] | 243 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address> |
---|
[472] | 244 | </body> |
---|
| 245 | </html> |
---|