00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00049 #ifndef LUMIERA_P_H
00050 #define LUMIERA_P_H
00051
00052
00053 #include <tr1/memory>
00054
00055
00056 namespace lumiera
00057 {
00058 using std::tr1::shared_ptr;
00059 using std::tr1::weak_ptr;
00060
00073 template<class TAR, class BASE =shared_ptr<TAR> >
00074 class P
00075 : public BASE
00076 {
00077 public:
00078 P ( ) : BASE() {}
00079 template<class Y> explicit P (Y* p) : BASE(p) {}
00080 template<class Y, class D> P (Y* p, D d) : BASE(p,d){}
00081
00082 P (P const& r) : BASE(r) {}
00083 template<class Y> P (shared_ptr<Y> const& r) : BASE(r) {}
00084 template<class Y> explicit P (weak_ptr<Y> const& wr) : BASE(wr) {}
00085 template<class Y> explicit P (std::auto_ptr<Y> & ar) : BASE(ar) {}
00086
00087
00088 P& operator= (P const& r) { BASE::operator= (r); return *this; }
00089 template<class Y> P& operator=(shared_ptr<Y> const& sr) { BASE::operator= (sr); return *this; }
00090 template<class Y> P& operator=(std::auto_ptr<Y> & ar) { BASE::operator= (ar); return *this; }
00091
00092 TAR* get() const { return dynamic_cast<TAR*> (BASE::get()); }
00093 TAR& operator*() const { return *get(); }
00094 TAR* operator->() const { return get(); }
00095
00096 void swap(P& b) { BASE::swap (b);}
00097
00098
00099 private:
00100 template<typename _O_>
00101 friend inline bool
00102 operator== (P const& p, P<_O_> const& q) { return (p && q)? (*p == *q) : (!p && !q); }
00103
00104 template<typename _O_>
00105 friend inline bool
00106 operator!= (P const& p, P<_O_> const& q) { return (p && q)? (*p != *q) : !(!p && !q); }
00107
00108 template<typename _O_>
00109 friend inline bool
00110 operator< (P const& p, P<_O_> const& q) { return (p && q) && (*p < *q); }
00111
00112 template<typename _O_>
00113 friend inline bool
00114 operator> (P const& p, P<_O_> const& q) { return (p && q) && (*q < *p); }
00115
00116 template<typename _O_>
00117 friend inline bool
00118 operator<= (P const& p, P<_O_> const& q) { return (p && q)? (*p <= *q) : (!p && !q); }
00119
00120 template<typename _O_>
00121 friend inline bool
00122 operator>= (P const& p, P<_O_> const& q) { return (p && q)? (*p >= *q) : (!p && !q); }
00123
00124 };
00125
00126
00127 }
00128 #endif