00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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 };
00117
00118
#endif
00119