00001 #include "refclass.h"
00002 template <class TRefType,class Arg> class KillableTStar: public TRefType {
00003 bool killed;
00004 public:
00005 bool Killed()const {return killed;}
00006 void Kill() {killed=true;}
00007 KillableTStar(const Arg & a): TRefType(a){killed=false;}
00008 };
00009
00010 template <class T, class Arg, class TStar = TRef<T,Arg> > class RefContainer: public RefClass<T,Arg,KillableTStar<TStar, Arg> > {
00011 protected:
00012 #define SuperType RefClass<T,Arg,KillableTStar<TStar,Arg> >
00013 #define ThisType RefContainer<T,Arg,TStar>
00014 void DestroyObject() {
00015 SuperType::DestroyObject();
00016 SuperType::SetNull();
00017 }
00018 public:
00019 RefContainer (): SuperType (NOTATHANG,NOTATHANG){}
00020 RefContainer (const Arg & a) : SuperType (a) {}
00021 RefContainer (const ThisType & a): SuperType (a) {}
00022 RefContainer<T,Arg,TStar> & operator = (const SuperType & r) {
00023 SuperType ::operator = (r);
00024 return *this;
00025 }
00026 void Kill() {
00027 if (! SuperType ::IsNull()){
00028 (*t).second.killed=true;
00029 DestroyObject();
00030 }
00031 }
00032 void SetNull(){
00033 if (! SuperType ::IsNull()) {
00034 DestroyObject();
00035 }
00036 }
00037 bool nullCheck() {
00038 if ( SuperType ::IsNull())
00039 return true;
00040 else if ((*t).killed()) {
00041 DestroyObject();
00042 return true;
00043 }
00044 return false;
00045 }
00046 bool IsNull()const {
00047 if ( SuperType ::IsNull()) {
00048 return true;
00049 }else {
00050 return (*t).killed;
00051 }
00052 }
00053 const T * Get ()const {
00054 if (IsNull())
00055 return 0;
00056 return SuperType ::Get();
00057 }
00058 T * Get () {
00059 if (SuperType ::IsNull())
00060 return 0;
00061 else if ((*t).killed()) {
00062 DestroyObject();
00063 return 0;
00064 }
00065 return SuperType ::Get();
00066 }
00067 T * operator * () {return Get();}
00068 const T * operator * ()const {return Get();}
00069
00070 bool operator == (const ThisType & o)const {
00071 bool a= IsNull();bool b = o.IsNull();
00072 if (a||b)
00073 return a==b;
00074 return SuperType ::operator == (o);
00075 }
00076 bool operator != (const ThisType & o)const {
00077 return !((*this)==o);
00078 }
00079 bool operator < (const ThisType & o)const {
00080 bool a= IsNull();bool b = o.IsNull();
00081 if (a||b)
00082 return (!a)&&b;
00083 return SuperType ::operator < (o);
00084 }
00085 #undef SuperType
00086 #undef ThisType
00087 };