00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 };
00149
00150
#endif
00151