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

SIPtr.h

Go to the documentation of this file.
00001 /* Copyright (C) 2002 Carsten Griwodz 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, this code may be used in unmodified form 00006 * provided that this copyright notice and this permission notice appear 00007 * in supporting documentation. 00008 * 00009 * The code may be made subject to the terms of the GNU General Public 00010 * License, Version 2, and re-distributed under the terms of this license. 00011 * 00012 * Commercial use other than under the terms of the GNU General Public 00013 * License is allowed only after negotiation of conditions with the authors. 00014 */ 00015 #ifndef OS_SI_PTR_H 00016 #define OS_SI_PTR_H 00017 00018 #include <stdio.h> 00019 #include <assert.h> 00020 00021 namespace OS 00022 { 00023 00036 template <class T> 00037 class SIPtr 00038 { 00039 public: 00040 SIPtr( ) 00041 : _pointee( NULL ) 00042 { 00043 } 00044 00045 explicit SIPtr( T* pointee ) 00046 : _pointee( pointee ) 00047 { 00048 if( _pointee != NULL ) _pointee->ref(); 00049 } 00050 00051 SIPtr( const SIPtr& other ) 00052 : _pointee( other._pointee ) 00053 { 00054 if( _pointee != NULL ) _pointee->ref(); 00055 } 00056 00057 SIPtr& operator=( const SIPtr& other ) 00058 { 00059 if( _pointee != NULL ) _pointee->deref(); 00060 _pointee = other._pointee; 00061 if( _pointee != NULL ) _pointee->ref(); 00062 return *this; 00063 } 00064 00065 SIPtr& operator=( T* pointee ) 00066 { 00067 if( _pointee != NULL ) _pointee->deref(); 00068 _pointee = pointee; 00069 if( _pointee != NULL ) _pointee->ref(); 00070 return *this; 00071 } 00072 00073 ~SIPtr( ) 00074 { 00075 if( _pointee != NULL ) _pointee->deref(); 00076 } 00077 00078 T& operator*( ) const 00079 { 00080 return *_pointee; 00081 } 00082 00083 T* operator->( ) const 00084 { 00085 return _pointee; 00086 } 00087 00088 inline bool isNull( ) const { 00089 return ( _pointee == NULL ); 00090 } 00091 00092 bool operator==( T* pointee ) 00093 { 00094 return ( _pointee == pointee ); 00095 } 00096 00097 bool operator!=( T* pointee ) 00098 { 00099 return ( _pointee != pointee ); 00100 } 00101 00102 bool operator==( const SIPtr& other ) 00103 { 00104 return ( _pointee == other._pointee ); 00105 } 00106 00107 bool operator!=( const SIPtr& other ) 00108 { 00109 return ( _pointee != other._pointee ); 00110 } 00111 00112 private: 00113 T* _pointee; 00114 }; 00115 00116 }; // namespace OS 00117 00118 #endif /* OS_SI_PTR_H */ 00119

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