jigdo API
Last update by Admin on 2010-05-23
util/autonullptr.hh
Go to the documentation of this file.00001 /* $Id: autonullptr.hh,v 1.5 2005/07/04 10:25:10 atterer Exp $ -*- C++ -*- 00002 __ _ 00003 |_) /| Copyright (C) 2004 | richard@ 00004 | \/¯| Richard Atterer | atterer.net 00005 ¯ '` ¯ 00006 This program is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU General Public License, version 2. See the file 00008 COPYING for details. 00009 00010 */ 00027 #ifndef AUTONULLPTR_HH 00028 #define AUTONULLPTR_HH 00029 00030 #include <ilist.hh> 00031 //______________________________________________________________________ 00032 00033 template<class T> class AutoNullPtrBase; 00034 00036 template<class T> 00037 class AutoNullPtr : public IListBase { 00038 public: 00039 AutoNullPtr() : IListBase(), p(0) { } 00040 AutoNullPtr(T* ptr) : IListBase(), p(ptr) { addSelf(); } 00041 AutoNullPtr(const AutoNullPtr<T>& b) : IListBase(), p(b.get()) { addSelf(); } 00042 ~AutoNullPtr() { iList_remove(); } 00043 00044 AutoNullPtr<T>& operator=(const AutoNullPtr<T>& b) { 00045 iList_remove(); p = b.get(); addSelf(); return *this; 00046 } 00047 AutoNullPtr<T>& operator=(T* ptr) { 00048 iList_remove(); p = ptr; addSelf(); return *this; 00049 } 00050 00051 T* get() const { return p; } 00052 T& operator*() const { return *p; } 00053 T* operator->() const { return p; } 00054 operator bool() const { return p != 0; } 00055 00056 private: 00057 void addSelf() { if (p != 0) p->list.push_back(*this); } 00058 T* p; 00059 }; 00060 //______________________________________________________________________ 00061 00064 template<class T> 00065 class AutoNullPtrBase { 00066 public: 00067 AutoNullPtrBase() { } 00068 ~AutoNullPtrBase() { while (!list.empty()) list.front() = 0; } 00069 private: 00070 friend class AutoNullPtr<T>; 00071 IList<AutoNullPtr<T> > list; 00072 }; 00073 //______________________________________________________________________ 00074 00078 template<class T> 00079 inline bool operator==(const AutoNullPtr<T>& a, const T* b) { 00080 return a.get() == b; 00081 } 00082 template<class T> 00083 inline bool operator==(const T* b, const AutoNullPtr<T>& a) { 00084 return a.get() == b; 00085 } 00086 template<class T> 00087 inline bool operator==(const AutoNullPtr<T>& a, const AutoNullPtr<T>& b) { 00088 return a.get() == b.get(); 00089 } 00090 00091 template<class T> 00092 inline bool operator!=(const AutoNullPtr<T>& a, const T* b) { 00093 return a.get() != b; 00094 } 00095 template<class T> 00096 inline bool operator!=(const T* b, const AutoNullPtr<T>& a) { 00097 return a.get() != b; 00098 } 00099 template<class T> 00100 inline bool operator!=(const AutoNullPtr<T>& a, const AutoNullPtr<T>& b) { 00101 return a.get() != b.get(); 00102 } 00103 00104 template<class T> 00105 inline bool operator<(const AutoNullPtr<T>& a, const T* b) { 00106 return a.get() < b; 00107 } 00108 template<class T> 00109 inline bool operator<(const T* b, const AutoNullPtr<T>& a) { 00110 return a.get() < b; 00111 } 00112 template<class T> 00113 inline bool operator<(const AutoNullPtr<T>& a, const AutoNullPtr<T>& b) { 00114 return a.get() < b.get(); 00115 } 00116 00117 template<class T> 00118 inline bool operator>(const AutoNullPtr<T>& a, const T* b) { 00119 return a.get() > b; 00120 } 00121 template<class T> 00122 inline bool operator>(const T* b, const AutoNullPtr<T>& a) { 00123 return a.get() > b; 00124 } 00125 template<class T> 00126 inline bool operator>(const AutoNullPtr<T>& a, const AutoNullPtr<T>& b) { 00127 return a.get() > b.get(); 00128 } 00129 00130 template<class T> 00131 inline bool operator<=(const AutoNullPtr<T>& a, const T* b) { 00132 return a.get() <= b; 00133 } 00134 template<class T> 00135 inline bool operator<=(const T* b, const AutoNullPtr<T>& a) { 00136 return a.get() <= b; 00137 } 00138 template<class T> 00139 inline bool operator<=(const AutoNullPtr<T>& a, const AutoNullPtr<T>& b) { 00140 return a.get() <= b.get(); 00141 } 00142 00143 template<class T> 00144 inline bool operator>=(const AutoNullPtr<T>& a, const T* b) { 00145 return a.get() >= b; 00146 } 00147 template<class T> 00148 inline bool operator>=(const T* b, const AutoNullPtr<T>& a) { 00149 return a.get() >= b; 00150 } 00151 template<class T> 00152 inline bool operator>=(const AutoNullPtr<T>& a, const AutoNullPtr<T>& b) { 00153 return a.get() >= b.get(); 00154 } 00156 //______________________________________________________________________ 00157 00158 #endif
Generated on Tue Sep 23 14:27:41 2008 for jigdo by
