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
00028 #ifndef _GPTR_H_
00029 #define _GPTR_H_
00030 #include <coconut_config.h>
00031
00033
00039 template <class _Tp>
00040 class gptr
00041 {
00042 private:
00044 typedef _Tp& reference;
00046 typedef _Tp* pointer;
00048 typedef const _Tp& const_reference;
00050 typedef const _Tp* const_pointer;
00051 public:
00053 virtual ~gptr() {}
00054
00056 virtual reference operator*() PURE_VIRTUAL
00058 virtual const_reference operator*() const PURE_VIRTUAL
00059
00061 virtual pointer operator->() PURE_VIRTUAL
00063 virtual const_pointer operator->() const PURE_VIRTUAL
00064
00067 virtual pointer get_local_copy() PURE_VIRTUAL
00070 virtual const_pointer get_local_copy() const PURE_VIRTUAL
00071 };
00072
00074
00079 template <class _Tp>
00080 class ptr : public gptr<_Tp>
00081 {
00082 private:
00083 typedef ptr<_Tp> _Self;
00084
00086 typedef _Tp& reference;
00088 typedef _Tp* pointer;
00090 typedef const _Tp& const_reference;
00092 typedef const _Tp* const_pointer;
00093
00095 _Tp* _p;
00096 public:
00099 ptr(_Tp& __p) : _p(&__p) {}
00102 ptr(_Tp* __p) : _p(__p) {}
00104 ptr(const _Self& __p) : _p(__p._p) {}
00105
00107 ~ptr() {}
00108
00110 reference operator*() { return *_p; }
00112 const_reference operator*() const { return *_p; }
00113
00115 pointer operator->() { return _p; }
00117 const_pointer operator->() const { return _p; }
00118
00121 pointer get_local_copy() { return _p; }
00124 const_pointer get_local_copy() const { return _p; }
00125
00127 _Self& operator=(const _Self& __p) { _p = __p._p; return *this; }
00129 _Self& operator=(_Tp& __p) { _p = &__p; return *this; }
00130 };
00131
00132 #endif