Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

SHRPtr.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 00025 #ifndef SH_REPORT_RPTR_H 00026 #define SH_REPORT_RPTR_H 00027 00028 #include <stdio.h> 00029 #include <assert.h> 00030 00031 #include "MNValid.h" 00032 00033 namespace SH 00034 { 00035 00049 template <class T> 00050 class RPtr 00051 { 00052 public: 00053 RPtr( ) 00054 : _pointee( NULL ) 00055 { 00056 } 00057 00068 explicit RPtr( T* pointee ) 00069 : _pointee( pointee ) 00070 { 00071 if( pointee != NULL ) 00072 { 00073 pointee->ref(); 00074 } 00075 } 00076 00077 RPtr( const RPtr& other ) 00078 : _pointee( other._pointee ) 00079 { 00080 if( _pointee ) _pointee->ref(); 00081 } 00082 00083 RPtr& operator=( const RPtr& other ) 00084 { 00085 if( _pointee ) _pointee->unref(); 00086 _pointee = other._pointee; 00087 if( _pointee ) _pointee->ref(); 00088 return *this; 00089 } 00090 00091 RPtr& operator=( T* pointee ) 00092 { 00093 if( _pointee ) _pointee->unref(); 00094 _pointee = pointee; 00095 if( _pointee ) _pointee->ref(); 00096 return *this; 00097 } 00098 00099 ~RPtr( ) 00100 { 00101 if( _pointee ) _pointee->unref(); 00102 } 00103 00104 T& operator*( ) const 00105 { 00106 return *_pointee; 00107 } 00108 00109 T* operator->( ) const 00110 { 00111 return _pointee; 00112 } 00113 00114 T* pointer() const 00115 { 00116 return _pointee; 00117 } 00118 00119 inline bool isNull( ) const { 00120 return ( _pointee == NULL ); 00121 } 00122 00123 private: 00124 bool operator==( T* pointee ) 00125 { 00126 return ( _pointee == pointee ); 00127 } 00128 00129 bool operator!=( T* pointee ) 00130 { 00131 return ( _pointee != pointee ); 00132 } 00133 00134 bool operator==( const RPtr& other ) 00135 { 00136 return ( _pointee == other._pointee ); 00137 } 00138 00139 bool operator!=( const RPtr& other ) 00140 { 00141 return ( _pointee != other._pointee ); 00142 } 00143 00144 private: 00145 T* _pointee; 00146 }; 00147 00148 }; // namespace SH 00149 00150 #endif /* SH_REPORT_RPTR_H */ 00151

Generated on Sun Mar 6 13:35:50 2005 for Komssys by doxygen 1.3.8